What's the algorithm to copy a file?

What's the algorithm to copy a file?

Attached: g or b.jpg (449x356, 32K)

cp [file] [destination]

cp file.one file.two

Right click file
Click copy
Open destination folder
Right click on the background
Click paste

That didn't work. Either stop fucking replying to my thread or give me actually useful advice you fucking idiots

rn [file]

>not using rsync

Attached: Timmy Raabe 1.jpg (562x340, 35K)

#include

int main(int argc, char **argv) {
FILE *infile = fopen(argv[1], "rb");
FILE *outfile = fopen(argv[2], "wb");

unsigned long count = 0;
int ch;

while (EOF != (ch=getc(infile))) {
++count;
putc(ch, outfile);
}
printf("%lu bytes copied\n", count);
return 0;
}

Attached: 745092302.jpg (640x640, 68K)

Works with every Unix-like OS, so fuck off, you nutter.

cat /path/to/source >/path/to/destination

lol what’s this jibberish?

This is a bit of a stupid question to be honest, but since none of these fags are going to give you a serious response, I might as well

where the file ends up in the filesystem depends on the type of filesystem you're using, but when you're "moving" it on the disk, you first check how long the file is and allocate the appropriate diskspace at the target location, which again, depends on the filesystem, go to the first byte, mark it for deletion, and then write that byte at its respective location, and repeat until the entire source file has been marked for deletion.

It's an algorithm. It copies a file to another file to your naming. It's C code. Compile it with gcc.

nevermind, guess I posted too late ()

Is it an AI?

Y E E T

Attached: dog ahegao tentacles.jpg (672x503, 87K)

not OP but thanks, never knew how it really worked.

This board is literally a /v/ daycare.

Nice buffer size

main :: IO ()
main = do
content

Alt+C, Alt+V

>argv[1]
>argv[2]
>doesn't check argc
reee

Nice penis size

might as well make count an unsigned long long

Copy it blockwise into a buffer, then write that buffer to the other file.

Based rsync

system("copy " + file1 + " " + file2);

>one byte at a time
w
e
w
l
a
d

And without stdio?

>while (EOF != (ch=getc(infile)))
while ((ch=getc(infile)) != EOF) is more intuitive to me, but maybe that's just arguing semantics.

rose is a dead meme
give it up already

who?

Rose

Attached: rose.jpg (785x1000, 181K)

(spit "OP" (slurp "FAG"))

that's the hill you want to die on in that mess?

don't know him

Bash is FOSS, why don't you go look at what the cp command does? Other than alert the FBI, of course.

>no error checking for fopen
>no check for argument count
>one byte at a time
>variable declaration after code
>having a count pointer instead of just using ftell
>++variable;
kill yourself

>not seeing it's rudimentary

I thought OP was asking about a safe low-level sequence to copy a file eg avoiding race conditions. Saddened to read the thread content.

Rose will outlive memes. Rose is life.

>using int instead of off_t for file size

Just buy new ones, it's cheaper.

Attached: bunch of files.jpg (474x355, 27K)

>What is an algorithm
The movie.

Holy fuck

What is this, Haskell?

import file
copy file

The quads of truth has successfully been checked

Attached: 141002140314-11-quads-hallock-horizontal-large-gallery.jpg (980x552, 78K)

dd if=file of=file.copy

You coulda copied cp code from one of the BSDs and stripped it down user. You might even have learned a thing or two in the process. But to be honest, K&R's version is basically yours only shorter.
/* filecopy: copy file ifp to file ofp */
void filecopy(FILE *ifp, FILE *ofp)
{
int c;
while ((c = getc(ifp)) != EOF)
putc(c, ofp);
}

I personally woulda put EOF !=(...), to avoid the case were when one might mistype ==, !=... and accidentally put = instead

>algorithm
Do you want a command or an external memory algorithm? One is Jow Forumsshit and one is math

>tfw her Christmas video coming soon
>tfw year is almost already over

The OS handles that for you. Also the standard library's FILE structure has got its own buffering mechanisms. So unless you know for sure the target standard library/OS has poor or no buffering mechanism (some embedded systems), using the FILE api function calls will get you a good performance any day of the week. Keep in mind the standard C library has been undergoing crazy optimizations since its inception in the late 70s.
There are cases where designing buffering from the ground up makes sense, which is the case in game engines and other big engineering undertakings. But here your work is tied in with the design of a custom memory manager and at that point some studios do away with most of the C default standard library toolings in favor of in-house tools.
Here are books with a clear exposition of how memory management works:
- The Design of the UNIX Operating System by Maurice J. Bach
- Real Time C++ by Chris Kormanyos

sounds like a MISRAble way to program

>8bit buffer

>right click
what do you do if your mouse only has one button

I didn't know Julian Assange also browses Jow Forums

fast and dirty copy, less disk heavy for larger files
#include
#include

#define BUFFER_SIZE 0x400

int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Usage:\n\t%s ", argv[0]);
return 1;
}
FILE *in = fopen(argv[1], "rb");
FILE *out = fopen(argv[2], "wb");

char buffer[BUFFER_SIZE];

int num;
while(feof(in) == 0) {
num = fread(buffer, 1, BUFFER_SIZE, in);
printf("Read %d bytes:\t", num);
num = fwrite(buffer, 1, num, out);
printf("Wrote %d bytes:\n", num);
}

fclose(in);
fclose(out);
return 0;
}

sample output

Attached: Capture.png (376x130, 6K)

I'm retarded, forgot to free that buffer. also probably should be using
buffer = malloc(BUFFER_SIZE);

instead of
char buffer[BUFFER_SIZE];

This post is the definition of bittersweet

no
echo $(/path/to/destination

enjoy over 5000 syscalls nigger

Shouldnt you be in school, user?

lmao

nice btc miner

Thanks user-kun :3

He's cute.

>cp
>bash
It's a separate program and has nothing to do with bash or any other shell

Get a better one

cat /dev/urandom | hexdump -v -e '/1 "%u\n"' | awk '{ split("0,2,4,5,7,9,11,12",a,","); for (i = 0; i < 1; i+= 0.0001) printf("%08X\n", 100*sin(1382*exp((a[$1 % 8]/12)*log(2))*i)) }' | xxd -r -p | aplay -c 2 -f S32_LE -r 16000


Make sure your speaker and microphone levels are up so the system can transfer files over the airwaves

dead

>Ctrl F
>No y combinator meme.

I'm done with you fa/g/s.