From: Davidlohr Bueso Date: Wed, 14 Sep 2011 18:07:06 +0000 (-0300) Subject: mount: use common libs X-Git-Tag: v2.21-rc1~403 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ef9fd7;p=thirdparty%2Futil-linux.git mount: use common libs Get rid of the local xmalloc.[c/h] files by using the global xalloc and strutils libraries. Signed-off-by: Davidlohr Bueso --- diff --git a/mount/Makefile.am b/mount/Makefile.am index 7aebfff666..e9237b75af 100644 --- a/mount/Makefile.am +++ b/mount/Makefile.am @@ -5,7 +5,7 @@ sbin_PROGRAMS = losetup swapon dist_man_MANS = fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8 # generic sources for all programs (mount, umount, losetup) -srcs_common = sundries.c xmalloc.c $(top_srcdir)/lib/canonicalize.c sundries.h xmalloc.h +srcs_common = sundries.c $(top_srcdir)/lib/canonicalize.c sundries.h # generic header for mount and umount hdrs_mount = fstab.h mount_mntent.h mount_constants.h \ diff --git a/mount/fstab.c b/mount/fstab.c index 77bf81cb95..6c0e89f305 100644 --- a/mount/fstab.c +++ b/mount/fstab.c @@ -12,10 +12,10 @@ #include #include #include + #include "mount_mntent.h" #include "fstab.h" #include "sundries.h" -#include "xmalloc.h" #include "fsprobe.h" #include "pathnames.h" #include "nls.h" diff --git a/mount/lomount.c b/mount/lomount.c index fad58d57f9..74a874929a 100644 --- a/mount/lomount.c +++ b/mount/lomount.c @@ -21,7 +21,6 @@ #include "strutils.h" #include "nls.h" #include "sundries.h" -#include "xmalloc.h" #include "pathnames.h" #ifdef LOOP_SET_FD diff --git a/mount/mount.c b/mount/mount.c index e5e781f816..d2ecb1de69 100644 --- a/mount/mount.c +++ b/mount/mount.c @@ -32,7 +32,6 @@ #include "devname.h" #include "mount_constants.h" #include "sundries.h" -#include "xmalloc.h" #include "mount_mntent.h" #include "fstab.h" #include "lomount.h" diff --git a/mount/sundries.c b/mount/sundries.c index 2dec37f451..58f7b5de77 100644 --- a/mount/sundries.c +++ b/mount/sundries.c @@ -15,7 +15,6 @@ #include "canonicalize.h" #include "sundries.h" -#include "xmalloc.h" #include "nls.h" int mount_quiet; diff --git a/mount/sundries.h b/mount/sundries.h index 3b6a4644db..5e3ddc3a90 100644 --- a/mount/sundries.h +++ b/mount/sundries.h @@ -13,6 +13,9 @@ #include #include +#define XALLOC_EXIT_CODE 2 /* same as EX_SYSERR, for backwards compatibility */ +#include "xalloc.h" + /* global mount, umount, and losetup variables */ extern int mount_quiet; extern int verbose; @@ -20,6 +23,7 @@ extern int nocanonicalize; extern char *progname; #define streq(s, t) (strcmp ((s), (t)) == 0) +#define my_free(_p) free((void *) _p) void block_signals (int how); @@ -30,8 +34,6 @@ void die(int err, const char *fmt, ...) int matching_type (const char *type, const char *types); int matching_opts (const char *options, const char *test_opts); -void *xmalloc (size_t size); -char *xstrdup (const char *s); char *xstrndup (const char *s, int n); char *xstrconcat3 (char *, const char *, const char *); char *xstrconcat4 (char *, const char *, const char *, const char *); diff --git a/mount/umount.c b/mount/umount.c index 64f320c71b..5000aa5692 100644 --- a/mount/umount.c +++ b/mount/umount.c @@ -11,6 +11,7 @@ #include #include #include + #include "mount_constants.h" #include "sundries.h" #include "getusername.h" diff --git a/mount/xmalloc.c b/mount/xmalloc.c deleted file mode 100644 index 3fd09fdd51..0000000000 --- a/mount/xmalloc.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#include -#include /* strdup() */ -#include "xmalloc.h" -#include "nls.h" /* _() */ -#include "sundries.h" /* EX_SYSERR */ - -static void -die_if_null(void *t) { - if (t == NULL) - die(EX_SYSERR, _("not enough memory")); -} - -void * -xmalloc (size_t size) { - void *t; - - if (size == 0) - return NULL; - - t = malloc(size); - die_if_null(t); - - return t; -} - -void * -xrealloc (void *p, size_t size) { - void *t; - - t = realloc(p, size); - die_if_null(t); - - return t; -} - -char * -xstrdup (const char *s) { - char *t; - - if (s == NULL) - return NULL; - - t = strdup(s); - die_if_null(t); - - return t; -} diff --git a/mount/xmalloc.h b/mount/xmalloc.h deleted file mode 100644 index 2fc0a7e55f..0000000000 --- a/mount/xmalloc.h +++ /dev/null @@ -1,14 +0,0 @@ -#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); - -/* - * free(p); when 'p' is 'const char *' makes gcc unhappy: - * warning: passing argument 1 of ‘free’ discards qualifiers from pointer target type - */ -#define my_free(_p) free((void *) _p) - -#endif /* MOUNT_XMALLOC_H */