diff options
author | Matt Kraai <kraai@debian.org> | 2000-10-25 19:10:08 +0400 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-10-25 19:10:08 +0400 |
commit | 324a778f31ac99f2c9d947a99dc4c37902bde6fe (patch) | |
tree | 137420d5835bb40bc9712e895da5377c664bd4b3 | |
parent | b60208dd8fe3328a5db8be1dc958e62c9898a73b (diff) |
Added a fatalPerror function to simplify error handling.
-rw-r--r-- | busybox.h | 1 | ||||
-rw-r--r-- | coreutils/dd.c | 6 | ||||
-rw-r--r-- | dd.c | 6 | ||||
-rw-r--r-- | include/busybox.h | 1 | ||||
-rw-r--r-- | utility.c | 17 |
5 files changed, 23 insertions, 8 deletions
@@ -345,6 +345,7 @@ extern const char *applet_name; extern void usage(const char *usage) __attribute__ ((noreturn)); extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); +extern void fatalPerror(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); const char *modeString(int mode); const char *timeString(time_t timeVal); diff --git a/coreutils/dd.c b/coreutils/dd.c index 1002c0771..6868a913e 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c @@ -116,8 +116,7 @@ extern int dd_main(int argc, char **argv) * here anyways... */ /* free(buf); */ - perror(inFile); - exit(FALSE); + fatalPerror("%s", inFile); } if (outFile == NULL) @@ -132,8 +131,7 @@ extern int dd_main(int argc, char **argv) /* close(inFd); free(buf); */ - perror(outFile); - exit(FALSE); + fatalPerror("%s", outFile); } lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); @@ -116,8 +116,7 @@ extern int dd_main(int argc, char **argv) * here anyways... */ /* free(buf); */ - perror(inFile); - exit(FALSE); + fatalPerror("%s", inFile); } if (outFile == NULL) @@ -132,8 +131,7 @@ extern int dd_main(int argc, char **argv) /* close(inFd); free(buf); */ - perror(outFile); - exit(FALSE); + fatalPerror("%s", outFile); } lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); diff --git a/include/busybox.h b/include/busybox.h index 7f4d55f3d..e55f17cdd 100644 --- a/include/busybox.h +++ b/include/busybox.h @@ -345,6 +345,7 @@ extern const char *applet_name; extern void usage(const char *usage) __attribute__ ((noreturn)); extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); +extern void fatalPerror(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); const char *modeString(int mode); const char *timeString(time_t timeVal); @@ -109,6 +109,23 @@ extern void fatalError(const char *s, ...) exit(EXIT_FAILURE); } +extern void fatalPerror(const char *s, ...) +{ + va_list p; + + va_start(p, s); + fflush(stdout); + fprintf(stderr, "%s: ", applet_name); + if (s && *s) { + vfprintf(stderr, s, p); + fputs(": ", stderr); + } + fprintf(stderr, "%s\n", strerror(errno)); + va_end(p); + fflush(stderr); + exit(EXIT_FAILURE); +} + #if defined BB_INIT /* Returns kernel version encoded as major*65536 + minor*256 + patch, * so, for example, to check if the kernel is greater than 2.2.11: |