diff options
author | Matt Kraai <kraai@debian.org> | 2000-10-25 15:10:08 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-10-25 15:10:08 +0000 |
commit | 324a778f31ac99f2c9d947a99dc4c37902bde6fe (patch) | |
tree | 137420d5835bb40bc9712e895da5377c664bd4b3 | |
parent | b60208dd8fe3328a5db8be1dc958e62c9898a73b (diff) | |
download | busybox-w32-324a778f31ac99f2c9d947a99dc4c37902bde6fe.tar.gz busybox-w32-324a778f31ac99f2c9d947a99dc4c37902bde6fe.tar.bz2 busybox-w32-324a778f31ac99f2c9d947a99dc4c37902bde6fe.zip |
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; | |||
345 | extern void usage(const char *usage) __attribute__ ((noreturn)); | 345 | extern void usage(const char *usage) __attribute__ ((noreturn)); |
346 | extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | 346 | extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
347 | extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | 347 | extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
348 | extern void fatalPerror(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
348 | 349 | ||
349 | const char *modeString(int mode); | 350 | const char *modeString(int mode); |
350 | const char *timeString(time_t timeVal); | 351 | 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) | |||
116 | * here anyways... */ | 116 | * here anyways... */ |
117 | 117 | ||
118 | /* free(buf); */ | 118 | /* free(buf); */ |
119 | perror(inFile); | 119 | fatalPerror("%s", inFile); |
120 | exit(FALSE); | ||
121 | } | 120 | } |
122 | 121 | ||
123 | if (outFile == NULL) | 122 | if (outFile == NULL) |
@@ -132,8 +131,7 @@ extern int dd_main(int argc, char **argv) | |||
132 | 131 | ||
133 | /* close(inFd); | 132 | /* close(inFd); |
134 | free(buf); */ | 133 | free(buf); */ |
135 | perror(outFile); | 134 | fatalPerror("%s", outFile); |
136 | exit(FALSE); | ||
137 | } | 135 | } |
138 | 136 | ||
139 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); | 137 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); |
@@ -116,8 +116,7 @@ extern int dd_main(int argc, char **argv) | |||
116 | * here anyways... */ | 116 | * here anyways... */ |
117 | 117 | ||
118 | /* free(buf); */ | 118 | /* free(buf); */ |
119 | perror(inFile); | 119 | fatalPerror("%s", inFile); |
120 | exit(FALSE); | ||
121 | } | 120 | } |
122 | 121 | ||
123 | if (outFile == NULL) | 122 | if (outFile == NULL) |
@@ -132,8 +131,7 @@ extern int dd_main(int argc, char **argv) | |||
132 | 131 | ||
133 | /* close(inFd); | 132 | /* close(inFd); |
134 | free(buf); */ | 133 | free(buf); */ |
135 | perror(outFile); | 134 | fatalPerror("%s", outFile); |
136 | exit(FALSE); | ||
137 | } | 135 | } |
138 | 136 | ||
139 | lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET); | 137 | 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; | |||
345 | extern void usage(const char *usage) __attribute__ ((noreturn)); | 345 | extern void usage(const char *usage) __attribute__ ((noreturn)); |
346 | extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); | 346 | extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2))); |
347 | extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | 347 | extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); |
348 | extern void fatalPerror(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))); | ||
348 | 349 | ||
349 | const char *modeString(int mode); | 350 | const char *modeString(int mode); |
350 | const char *timeString(time_t timeVal); | 351 | const char *timeString(time_t timeVal); |
@@ -109,6 +109,23 @@ extern void fatalError(const char *s, ...) | |||
109 | exit(EXIT_FAILURE); | 109 | exit(EXIT_FAILURE); |
110 | } | 110 | } |
111 | 111 | ||
112 | extern void fatalPerror(const char *s, ...) | ||
113 | { | ||
114 | va_list p; | ||
115 | |||
116 | va_start(p, s); | ||
117 | fflush(stdout); | ||
118 | fprintf(stderr, "%s: ", applet_name); | ||
119 | if (s && *s) { | ||
120 | vfprintf(stderr, s, p); | ||
121 | fputs(": ", stderr); | ||
122 | } | ||
123 | fprintf(stderr, "%s\n", strerror(errno)); | ||
124 | va_end(p); | ||
125 | fflush(stderr); | ||
126 | exit(EXIT_FAILURE); | ||
127 | } | ||
128 | |||
112 | #if defined BB_INIT | 129 | #if defined BB_INIT |
113 | /* Returns kernel version encoded as major*65536 + minor*256 + patch, | 130 | /* Returns kernel version encoded as major*65536 + minor*256 + patch, |
114 | * so, for example, to check if the kernel is greater than 2.2.11: | 131 | * so, for example, to check if the kernel is greater than 2.2.11: |