- 论坛徽章:
- 0
|
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#define BUFFSIZE 8192
int main(int argc, char* argv[])
{
int n;
int fdin, fdout;
char buf[BUFFSIZE];
if( (fdin = open(argv[1], O_RDONLY)) < 0 ) {
printf("cannot open %s for read\n", argv[1]);
exit(-1);
}
if( (fdout = open(argv[2], O_RDWR|O_CREAT|O_TRUNC, S_IRUSR|
S_IWUSR|S_IRGRP|S_IROTH)) < 0 ) {
printf("cannot open %s for write\n", argv[2]);
exit(-1);
}
while(( n = read(fdin, buf, BUFFSIZE)) > 0 ) {
if( write(fdout, buf, n) != n ) {
exit(-1);
}
}
exit(0);
}
说得没错,用这个程序
time ./test libx.a a.a
real 0m2.75s
user 0m0.01s
sys 0m0.44s
结果和cp差不多 |
|