/**
author lx
date 3.24 2011
contact lxlenovostar@gmail.com
biref cp a big file to anthor file.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#define BUFFSIZE 8192
int main( void )
{
int id_write, id_read;
id_write = open( "temp.pcap", O_WRONLY | O_APPEND | O_CREAT );
id_read = open( "lx03.pcap", O_RDONLY );
int n;
char buf[BUFFSIZE];
while ( ( n = read( id_read, buf, BUFFSIZE ) ) > 0 )
{
if ( write( id_write, buf, n ) != n )
fprintf( stderr, "error is %s\n", strerror(errno) );
}
if ( n < 0 )
printf( "read error\n" );
close( id_write );
close( id_read );
exit( 0 );
}
编译的时候:g++ -o opencp -D_FILE_OFFSET_BITS=64 -g opencp.cpp