Low Level File Copy Program:
#include "fcntl.h"
#include "types.h"
#include "stat.h"
main(int argc, char *argv[])
{
char buffer[512];
int in, out, bytes;
in = open(argv[1], O_RDONLY|O_BINARY);
if (in == -1)
{
puts("Cannot open file");
exit();
}
out = open(argv[2], O_CREATE|O_WRONLY|O_BINARY|S_IWRITE);
if(out == -1)
{
puts("Cannot open file");
exit();
}
while(1)
{
bytes = read(in, out, 512);
if (bytes > 0)
{
write(out, buffer, bytes);
}
else
{
break;
}
}
close(in);
close(out);
}
No comments:
Post a Comment