From a807392ec86c49bb5fa6127b94ba39d41d251592 Mon Sep 17 00:00:00 2001 From: Viggo Xia Date: Wed, 2 Dec 2015 07:45:43 +0800 Subject: [PATCH] Delete mycp.c --- mycp.c | 78 ---------------------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 mycp.c diff --git a/mycp.c b/mycp.c deleted file mode 100644 index d026e10..0000000 --- a/mycp.c +++ /dev/null @@ -1,78 +0,0 @@ -#include -#include -#include -#include -#include - -#define BUFSIZE 1024 - -int copy(const char *file1, const char *file2){ - /*copy contents of file1 to file2, ignore the hole*/ - int fd1, fd2, num, i; - int base, probe; - char buf[BUFSIZE]; - /*open the source and target files*/ - if((fd1 = open(file1, O_RDWR)) == -1){ - printf("Error opening %s for copying\n", file1); - return -1; - } - if((fd2 = open(file2, O_RDWR|O_APPEND|O_CREAT|O_TRUNC)) == -1){ - printf("Error creating %s to copy\n", file2); - return -1; - } - - do{ - memset(buf, '\0', BUFSIZE); - - if((num = read(fd1, buf, BUFSIZE)) == -1){ - printf("Error reading %s for copying\n", file1); - return -1; - } - /*clear all "holes"('\0') in the buf array*/ - base =0; - for(i=0; i0); - - close(fd1); - close(fd2); - - return 0; -} - -int main(int argc, char *argv[]){ - char *file1, *file2; - - if(argc != 3){ - printf("parameter error!\n"); - return -1; - } - - file1 = argv[1]; - file2 = argv[2]; - return copy(file1, file2); -}