/* This program illustrates the use of Unix/C file descriptors for Disk IO. It copies up to 1k at a time. */ #include #include #include #include #include int main(int argc, char * argv[]) { int i = 1024; int infd, outfd; unsigned char buffer[1024]; if (argc != 3) exit(1); infd = open(argv[1],O_RDONLY,0); outfd = open(argv[2],O_WRONLY | O_CREAT | O_TRUNC,0755); // above line same as outfd = creat(argv[2],0755) while (i==1024) { i = read(infd,buffer,1024); // read up to 1024 bytes; if (i>0) write(outfd,buffer,i); } close(infd); close(outfd); exit(0); }