mycopy.c

来自「在linux下使用c语言编写的一个文件拷贝的源码」· C语言 代码 · 共 62 行

C
62
字号
#include <linux/unistd.h>#include <fcntl.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <errno.h>#include <string.h>_syscall4(int , mycopy, int, SourceFile, int, DestFile, char *, Buffer, int, BUFFER_SIZE);int main(int argc, char **argv){    int SourceFile, DestFile;    int status;    char desc;    int BUFFER_SIZE=1024;    char Buffer[BUFFER_SIZE];    /*  Not Enough Parameters */    if (argc != 3) {	printf("Usage Errot!:%s fromfile tofile\n\a", argv[0]);	exit(1);    }    /*  Source File Not Exit */    if (status = access(argv[1], F_OK)) {	printf("The Source File Not Exit.\n");	exit(1);    }    /*  Destination File Exit */    if ((status = access(argv[2], F_OK)) == 0) {	printf("The Destination File Exit.Overwrite?(y/n)\n");	desc = getchar();	while (desc != 'n' && desc != 'y') {	    printf("The Destination File Exit.Overwrite?(y/n)\n");	    desc = getchar();	}	if (desc == 'n')	    exit(0);    }    /*  Open the Source File  */    if ((SourceFile = open(argv[1], O_RDONLY)) == -1) {	printf("Open %s Error:%s\n", argv[1], strerror(errno));	exit(1);    }    /*  Open the Destination File   */    if ((DestFile =	 open(argv[2], O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR)) == -1) {	printf("Open %s Error:%s\n", argv[2], strerror(errno));	exit(1);    }	mycopy(SourceFile, DestFile, Buffer, BUFFER_SIZE);       close(SourceFile);    close(DestFile);    exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?