diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-05 03:03:07 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-05 03:03:07 +0200 |
commit | dcd27abcc4471ac04d7f196905907eb9a28bf0d8 (patch) | |
tree | 24ed60e8325dcfccc99b36b5cab663cd693f29bf | |
parent | be168b119750beacc0d0212607c6fa3ee87f238c (diff) | |
download | busybox-w32-dcd27abcc4471ac04d7f196905907eb9a28bf0d8.tar.gz busybox-w32-dcd27abcc4471ac04d7f196905907eb9a28bf0d8.tar.bz2 busybox-w32-dcd27abcc4471ac04d7f196905907eb9a28bf0d8.zip |
unpackers: check errors from close() too
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/bbunzip.c | 10 | ||||
-rw-r--r-- | include/libbb.h | 3 | ||||
-rw-r--r-- | libbb/xfuncs_printf.c | 6 |
3 files changed, 14 insertions, 5 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c index d25f50939..d6625e476 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c | |||
@@ -98,6 +98,7 @@ int FAST_FUNC bbunpack(char **argv, | |||
98 | status = unpacker(&info); | 98 | status = unpacker(&info); |
99 | if (status < 0) | 99 | if (status < 0) |
100 | exitcode = 1; | 100 | exitcode = 1; |
101 | xclose(STDOUT_FILENO); /* with error check! */ | ||
101 | 102 | ||
102 | if (filename) { | 103 | if (filename) { |
103 | char *del = new_name; | 104 | char *del = new_name; |
@@ -108,12 +109,11 @@ int FAST_FUNC bbunpack(char **argv, | |||
108 | 109 | ||
109 | times.actime = info.mtime; | 110 | times.actime = info.mtime; |
110 | times.modtime = info.mtime; | 111 | times.modtime = info.mtime; |
111 | /* Close first. | 112 | /* Note: we closed it first. |
112 | * On some systems calling utime | 113 | * On some systems calling utime |
113 | * then closing resets the mtime. */ | 114 | * then closing resets the mtime |
114 | close(STDOUT_FILENO); | 115 | * back to current time. */ |
115 | /* Ignoring errors */ | 116 | utime(new_name, ×); /* ignoring errors */ |
116 | utime(new_name, ×); | ||
117 | } | 117 | } |
118 | 118 | ||
119 | /* Delete _compressed_ file */ | 119 | /* Delete _compressed_ file */ |
diff --git a/include/libbb.h b/include/libbb.h index a02355cc5..dca14b40d 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -631,6 +631,9 @@ extern void xwrite(int fd, const void *buf, size_t count) FAST_FUNC; | |||
631 | extern void xwrite_str(int fd, const char *str) FAST_FUNC; | 631 | extern void xwrite_str(int fd, const char *str) FAST_FUNC; |
632 | extern void xopen_xwrite_close(const char* file, const char *str) FAST_FUNC; | 632 | extern void xopen_xwrite_close(const char* file, const char *str) FAST_FUNC; |
633 | 633 | ||
634 | /* Close fd, but check for failures (some types of write errors) */ | ||
635 | extern void xclose(int fd) FAST_FUNC; | ||
636 | |||
634 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ | 637 | /* Reads and prints to stdout till eof, then closes FILE. Exits on error: */ |
635 | extern void xprint_and_close_file(FILE *file) FAST_FUNC; | 638 | extern void xprint_and_close_file(FILE *file) FAST_FUNC; |
636 | 639 | ||
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index 5f56b36de..aaf9989a0 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
@@ -213,6 +213,12 @@ void FAST_FUNC xwrite_str(int fd, const char *str) | |||
213 | xwrite(fd, str, strlen(str)); | 213 | xwrite(fd, str, strlen(str)); |
214 | } | 214 | } |
215 | 215 | ||
216 | void FAST_FUNC xclose(int fd) | ||
217 | { | ||
218 | if (close(fd)) | ||
219 | bb_perror_msg_and_die("close failed"); | ||
220 | } | ||
221 | |||
216 | // Die with an error message if we can't lseek to the right spot. | 222 | // Die with an error message if we can't lseek to the right spot. |
217 | off_t FAST_FUNC xlseek(int fd, off_t offset, int whence) | 223 | off_t FAST_FUNC xlseek(int fd, off_t offset, int whence) |
218 | { | 224 | { |