Added a fatalPerror function to simplify error handling.
authorMatt Kraai <kraai@debian.org>
Wed, 25 Oct 2000 15:10:08 +0000 (15:10 -0000)
committerMatt Kraai <kraai@debian.org>
Wed, 25 Oct 2000 15:10:08 +0000 (15:10 -0000)
busybox.h
coreutils/dd.c
dd.c
include/busybox.h
utility.c

index 7f4d55f3d585f41a45c1f0b1a5f7f8ed094d7caf..e55f17cddcc6de1aaaba0dd21bb8ffb899744e71 100644 (file)
--- a/busybox.h
+++ b/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);
index 1002c077172037aed9a9eacaaed5ed3041b80679..6868a913e811aa5e1b198eca2f80fa167e2419f4 100644 (file)
@@ -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/dd.c b/dd.c
index 1002c077172037aed9a9eacaaed5ed3041b80679..6868a913e811aa5e1b198eca2f80fa167e2419f4 100644 (file)
--- a/dd.c
+++ b/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);
index 7f4d55f3d585f41a45c1f0b1a5f7f8ed094d7caf..e55f17cddcc6de1aaaba0dd21bb8ffb899744e71 100644 (file)
@@ -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);
index c8a1820d8a8ec79befe1d946b51264aca132b94f..39ed1b66aad2fb5e14cd8a857c85bb8552d7a6cf 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -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: