Mercurial > repos > david-hoover > local_file_tools
diff cpx.c @ 7:e5a905df7e0b draft
Uploaded
| author | david-hoover |
|---|---|
| date | Thu, 04 Oct 2012 14:48:02 -0400 |
| parents | c772c8912663 |
| children |
line wrap: on
line diff
--- a/cpx.c Thu Mar 08 09:18:40 2012 -0500 +++ b/cpx.c Thu Oct 04 14:48:02 2012 -0400 @@ -143,10 +143,13 @@ { // printf("Copying %s to %s\n",src,dst); - int c; + char *c; FILE *fs,*ft; struct stat fileStat; - + size_t st=10000000; + int numr,numw; + +// buffer = 10000; /* must be able to stat file */ if (stat(src, &fileStat) < 0) { @@ -172,14 +175,28 @@ exit(1); } - c = getc(fs); - while (c != EOF) { - putc(c,ft); - c = getc(fs); - } - + c=malloc(st); + while(feof(fs)==0) + { + if((numr=fread(c,1,st,fs))!=st) + { + if(ferror(fs)!=0) + { + fprintf(stderr,"read file error.\n"); + exit(1); + } + else if(feof(fs)!=0); + } + if((numw=fwrite(c,1,numr,ft))!=numr) + { + fprintf(stderr,"write file error.\n"); + exit(1); + } + } + fclose(fs); fclose(ft); + free(c); return 0; @@ -240,12 +257,21 @@ exit(1); } + if (!strncmp(argv[1],"/data",5) || !strncmp(argv[1],"/home",5)) + { + /* is file readable by given user? */ - explodePath(argv[1],argv[3]); + explodePath(argv[1],argv[3]); /* copy the file and change the owner */ - copyFile(argv[1],argv[2]); - chownToUser(argv[2]); + copyFile(argv[1],argv[2]); + chownToUser(argv[2]); + } + else + { + fprintf(stderr,"%s: Permission denied.\n",argv[1]); + exit(1); + } exit(0); }
