一、复制的三种情况:
-
将文件复制成另外一个文件;
int copy_file2file( char *cpSrcPath,char *cpDstPath ) { int iFdSrc = 0; int iFdDst = 0; int iRdNum = 0; int iWrNum = 0; char caLine[ LINELEN ]; /* open thhe source file */ if( ( iFdSrc = open( cpSrcPath, O_RDONLY ) ) < 0 { /* fail to open the source file */ return -1; } /* open the dest file */ if( ( iFdDst = open( cpDstPath, O_WRONLY | O_CREAT | O_TRUNC, S_IWUSR |S_IRUSR ) ) < 0 ) { return -1; } /* read the file until the EOF or some error */ while( ( iRdNum = read( iFdSrc, caLine, sizeof( caLine ) ) ) > 0 ) { if( ( iWrNum = write( iFdDst, caLine,iRdNum ) ) != iRdNum ) {