用C语言实现类似“cp file1 file2”命令

#include 
#include 
#include 

#define MaxBytes 1024
int main(int argc, char * argv[])
{
	int in, out;
	int need;
	char buffer[MaxBytes + 1];
	if (argc < 3)
	{
		printf("please input source file path and destination file path\n");
		exit(1);
	}
	in=open(argv[1],O_RDONLY);
	out=open(argv[2], O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR);
	while ((need = read(in, buffer, MaxBytes)) > 0)
	{
		write(out, buffer, need);
	}	
	exit(0);
}

你可能感兴趣的:(用C语言实现类似“cp file1 file2”命令)