檔案內容拷貝

cn_shift發表於2011-12-03
/*
*FileCopy.c - 檔案內容拷貝
*writed by cn_shift
*2006.4.1
*/


#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>


#define BUFFERSIZE 1


main()
{
int in,out,n;
char buffer[BUFFERSIZE];


in=open("./file1",O_RDONLY);
if(in<0)
{
printf("Open errir!\n");
exit(-1);
}


out=open("./file2",O_WRONLY | O_CREAT);
if(out<0)
{
printf("Open error!\n");
exit(-1);
}

while((n=read(in,buffer,BUFFERSIZE))>0)
{
write(out,buffer,BUFFERSIZE);
}

close(in);
close(out);
}

相關文章