Basically, I was attempting to create something that copied files over, and it
works fine for any non-binary files, but only reads part-way into a binary file.
My code was very basic and should work, I have check the return values of each
of the functions to make sure everything else works properly and it is.
My code looks basically like this:
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
int main(int argc, char **argv)
{
int i, numread, fd, fd2;
char buf[1024];
if (argc<3)
{
printf("Usage: %s <source-file> <destination-file>\n", argv[0]);
exit(1);
}
fd=open(argv[1], O_RDONLY, 0);
fd2=open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0777);
while((numread=read(fd, buf, 1024))>0)
{
write(fd2, buf, numread);
}
close(fd);
close(fd2);
exit(0);
}