Here is a simple copy I just wrote in C. It will copy text files and binary files as well. This is copy in its most basic form. This program does not display any error messages if any of the file operations should fail.
Gary
Here it goes: copy.c
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BUFFER_SIZE 1000
main(int argc, char * argv[] )
{
int fdIn = 0;
int fdOut = 0;
int iReadSize = 0;
int iWriteSize = 0;
char szBuffer[ BUFFER_SIZE + 1 ];
if ( argc != 3 )
printf("Usage: copy src dest\n");
fdIn = open( argv[1], O_RDONLY );
fdOut = creat( argv[2], S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH );
while ( (iReadSize = read( fdIn, szBuffer, BUFFER_SIZE )) > 0 )
{
iWriteSize = write( fdOut, szBuffer, iReadSize );
} // end while
close( fdIn );
close( fdOut );
}
|