From 26f95c7da28d94f663566e9d2132d4c71a1af098 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 25 Oct 2007 10:12:51 +0200 Subject: [PATCH] mount: cleanup error() and die() * moves error() and die() to sundries.h * removes at_die * adds __attribute__ ((__format__ (__printf__ ))) Signed-off-by: Karel Zak --- mount/fstab.c | 1 - mount/mount.c | 3 --- mount/sundries.c | 15 +++++++++++++++ mount/sundries.h | 11 +++++++---- mount/swapon.c | 1 - mount/umount.c | 2 -- mount/xmalloc.c | 18 ------------------ mount/xmalloc.h | 8 ++++---- 8 files changed, 26 insertions(+), 33 deletions(-) diff --git a/mount/fstab.c b/mount/fstab.c index a151df61..7baa68ee 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -813,7 +813,6 @@ update_mtab (const char *dir, struct my_mntent *instead) { /* dummy */ int verbose; -int mount_quiet; char *progname; const char *fsprobe_get_label_by_devname(const char *spec) { return NULL; } diff --git a/mount/mount.c b/mount/mount.c index ca1238f4..f7ff56e1 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -50,9 +50,6 @@ #include "setproctitle.h" #endif -/* Quiet mode */ -int mount_quiet = 0; - /* True for fake mount (-f). */ static int fake = 0; diff --git a/mount/sundries.c b/mount/sundries.c index 1669554c..0c7c6e1e 100644 --- a/mount/sundries.c +++ b/mount/sundries.c @@ -18,6 +18,8 @@ #include "xmalloc.h" #include "nls.h" +int mount_quiet; + char * xstrndup (const char *s, int n) { char *t; @@ -108,6 +110,19 @@ error (const char *fmt, ...) { fputc('\n', stderr); } +/* Fatal error. Print message and exit. */ +void +die(int err, const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + va_end(args); + + exit(err); +} + /* True if fstypes match. Null *TYPES means match anything, except that swap types always return false. */ /* Accept nonfs,proc,devpts and nonfs,noproc,nodevpts diff --git a/mount/sundries.h b/mount/sundries.h index 3d6a1bd2..010eece4 100644 --- a/mount/sundries.h +++ b/mount/sundries.h @@ -22,9 +22,14 @@ extern int sloppy; #define streq(s, t) (strcmp ((s), (t)) == 0) -/* Functions in sundries.c that are used in mount.c and umount.c */ +/* Functions in sundries.c that are used in mount.c and umount.c */ void block_signals (int how); -void error (const char *fmt, ...); + +void error (const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); +void die(int err, const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 2, 3))); + int matching_type (const char *type, const char *types); int matching_opts (const char *options, const char *test_opts); void *xmalloc (size_t size); @@ -35,8 +40,6 @@ char *xstrconcat4 (char *, const char *, const char *, const char *); int parse_spec(const char *spec, char **name, char **value); -void die (int errcode, const char *fmt, ...); - /* exit status - bits below are ORed */ #define EX_USAGE 1 /* incorrect invocation or permission */ #define EX_SYSERR 2 /* out of memory, cannot fork, ... */ diff --git a/mount/swapon.c b/mount/swapon.c index 84b047da..5e8c6eb0 100644 --- a/mount/swapon.c +++ b/mount/swapon.c @@ -36,7 +36,6 @@ int all = 0; int verbose = 0; int priority = -1; /* non-prioritized swap by default */ -int mount_quiet = 0; /* If true, don't complain if the device/file doesn't exist */ int ifexists = 0; diff --git a/mount/umount.c b/mount/umount.c index 18612543..ab179c21 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -400,8 +400,6 @@ usage (FILE *fp, int n) exit (n); } -int mount_quiet = 0; - /* * Look for an option in a comma-separated list */ diff --git a/mount/xmalloc.c b/mount/xmalloc.c index c3f51e50..3fd09fdd 100644 --- a/mount/xmalloc.c +++ b/mount/xmalloc.c @@ -5,24 +5,6 @@ #include "nls.h" /* _() */ #include "sundries.h" /* EX_SYSERR */ -void (*at_die)(void) = NULL; - -/* Fatal error. Print message and exit. */ -void -die(int err, const char *fmt, ...) { - va_list args; - - va_start(args, fmt); - vfprintf(stderr, fmt, args); - fprintf(stderr, "\n"); - va_end(args); - - if (at_die) - (*at_die)(); - - exit(err); -} - static void die_if_null(void *t) { if (t == NULL) diff --git a/mount/xmalloc.h b/mount/xmalloc.h index 91d64c5a..978e541a 100644 --- a/mount/xmalloc.h +++ b/mount/xmalloc.h @@ -1,8 +1,8 @@ -#include -#include +#ifndef MOUNT_XMALLOC_H +#define MOUNT_XMALLOC_H extern void *xmalloc(size_t size); extern void *xrealloc(void *p, size_t size); extern char *xstrdup(const char *s); -extern void die(int err, const char *fmt, ...); -extern void (*at_die)(void); + +#endif /* MOUNT_XMALLOC_H */ -- 2.39.5