diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-02-01T17·28+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-02-01T17·28+0000 |
commit | 6e2eaaec96e96ce593dd1e38d03fcf8d1f62eb55 (patch) | |
tree | 3c14ac793f57d64d90e1dab2b629ab443547b0cf /src/bsdiff-4.3 | |
parent | d9d6ff9f8eb4269bb697912154ef9d6d96ab1481 (diff) |
* Print a better error message when writing the patched file (e.g.,
"No space left on device" instead of "Success"). Reported by Karina Olmos.
Diffstat (limited to 'src/bsdiff-4.3')
-rw-r--r-- | src/bsdiff-4.3/bspatch.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/bsdiff-4.3/bspatch.c b/src/bsdiff-4.3/bspatch.c index f4b821cba757..741d4de0ebb8 100644 --- a/src/bsdiff-4.3/bspatch.c +++ b/src/bsdiff-4.3/bspatch.c @@ -33,6 +33,7 @@ __FBSDID("$FreeBSD: src/usr.bin/bsdiff/bspatch/bspatch.c,v 1.1 2005/08/06 01:59: #include <stdio.h> #include <string.h> #include <err.h> +#include <errno.h> #include <unistd.h> #include <fcntl.h> @@ -54,6 +55,22 @@ static off_t offtin(u_char *buf) return y; } + +void writeFull(const char * name, int fd, + const unsigned char * buf, size_t count) +{ + while (count) { + ssize_t res = write(fd, (char *) buf, count); + if (res == -1) { + if (errno == EINTR) continue; + err(1,"writing to %s",name); + } + count -= res; + buf += res; + } +} + + int main(int argc,char * argv[]) { FILE * f, * cpf, * dpf, * epf; @@ -193,8 +210,10 @@ int main(int argc,char * argv[]) err(1, "fclose(%s)", argv[3]); /* Write the new file */ - if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) || - (write(fd,new,newsize)!=newsize) || (close(fd)==-1)) + if((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY,0666))<0) + err(1,"%s",argv[2]); + writeFull(argv[2], fd, new, newsize); + if(close(fd)==-1) err(1,"%s",argv[2]); free(new); |