mount: use common libs
PATCH 1/1 mount: use common libs
From: Davidlohr Bueso <[email protected]>
Get rid of the local xmalloc.[c/h] files by using the global xalloc and s= trutils libraries.
---
This is applies to the latest commit in kernel.org's repo, since I have n= ot cloned the new github repository.
mount/Makefile.am | 2 +- mount/devname.c | 1 + mount/fstab.c | 3 ++- mount/lomount.c | 2 +- mount/mount.c | 2 +- mount/mount_mntent.c | 1 + mount/sundries.c | 2 +- mount/sundries.h | 3 +-- mount/umount.c | 2 ++ mount/xmalloc.c | 48 --------------------------------------------= ---- mount/xmalloc.h | 14 -------------- 11 files changed, 11 insertions(+), 69 deletions(-) delete mode 100644 mount/xmalloc.c delete mode 100644 mount/xmalloc.h
mount/Makefile.am +0 -0
@@ -7,7 +7,7 @@ sbin_PROGRAMS =3D losetup swapon dist_man_MANS =3D fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
=20
# generic sources for all programs (mount, umount, losetup) -srcs_common =3D sundries.c xmalloc.c $(top_srcdir)/lib/canonicalize.c su= ndries.h xmalloc.h +srcs_common =3D sundries.c $(top_srcdir)/lib/canonicalize.c sundries.h =20 # generic header for mount and umount hdrs_mount =3D fstab.h mount_mntent.h mount_constants.h \
mount/devname.c +0 -0
@@ -2,6 +2,7 @@
=20
#include "devname.h"
#include "sundries.h" /* for xstrdup */
+#include "xalloc.h"
=20
const char *
spec_to_devname(const char *spec)
mount/fstab.c +2 -1
@@ -12,10 +12,11 @@#include <sys/time.h> #include <time.h> #include <mntent.h> +#include "mount_mntent.h" #include "fstab.h" #include "sundries.h" -#include "xmalloc.h" +#include "xalloc.h" #include "fsprobe.h" #include "pathnames.h" #include "nls.h"
mount/lomount.c +1 -1
@@ -21,7 +21,7 @@#include "strutils.h" #include "nls.h" #include "sundries.h" -#include "xmalloc.h" +#include "xalloc.h" #include "pathnames.h"
=20
#ifdef LOOP_SET_FD
mount/mount.c +1 -1
@@ -32,7 +32,7 @@#include "devname.h" #include "mount_constants.h" #include "sundries.h" -#include "xmalloc.h" +#include "xalloc.h" #include "mount_mntent.h" #include "fstab.h" #include "lomount.h"
mount/mount_mntent.c +0 -0
@@ -10,6 +10,7 @@#include <ctype.h> /* for isdigit */ #include <sys/stat.h> /* for umask */
=20
+#include "xalloc.h"
#include "mount_mntent.h"
#include "sundries.h" /* for xmalloc */
#include "nls.h"
mount/sundries.c +0 -0
@@ -15,7 +15,7 @@#include "canonicalize.h"
=20
#include "sundries.h"
-#include "xmalloc.h"
+#include "xalloc.h"
#include "nls.h"
=20
int mount_quiet;
mount/sundries.h +0 -0
@@ -20,6 +20,7 @@ extern int nocanonicalize;extern char *progname;
=20
#define streq(s, t) (strcmp ((s), (t)) =3D=3D 0)
+#define my_free(_p) free((void *) _p)
=20
void block_signals (int how);
=20
@@ -30,8 +31,6 @@ void die(int err, const char *fmt, ...) =20
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 *);
mount/umount.c +2 -0
@@ -11,6 +11,8 @@#include <sys/stat.h> #include <sys/wait.h> #include <sys/mount.h> + +#include "xalloc.h" #include "mount_constants.h" #include "sundries.h" #include "getusername.h"
mount/xmalloc.c deleted +0 -48
48 lines not on this page · raw message
mount/xmalloc.h deleted +0 -10
@@ -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 =E2=80=98free=E2=80=99 discards qua=
lifiers from pointer target type
- */
-#define my_free(_p) free((void *) _p)
-
-#endif /* MOUNT_XMALLOC_H */
--=20
1.7.4.1
Karel Zak
maintainermount/devname.c line 5
Quoted 7 lines · Davidlohr Bueso
mount/devname.c +1
-0@@ -2,6 +2,7 @@#include "devname.h" #include "sundries.h" /* for xstrdup */ +#include "xalloc.h"
It would be better to include xalloc.h in sunders.h only.
mount/devname.c
Quoted 4 lines
mount/devname.c +0
-4-static void -die_if_null (void *t) { -if (t ==NULL ) -die (EX_SYSERR ,_ ("not enough memory" ));
^^^^^^^^
Quoted 1 line
-}
it means that you have to use:
#define XALLOC_EXIT_CODE EX_SYSERR
#include "xalloc.h"
to keep it backwardly compatible.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 11 lines · Karel Zak
mount/devname.c line 5
Quoted 7 lines · Davidlohr Bueso
mount/devname.c +1
-0@@ -2,6 +2,7 @@#include "devname.h" #include "sundries.h" /* for xstrdup */ +#include "xalloc.h" It would be better to include
xalloc.hinsunders.honly.
Quoted 6 lines
mount/devname.c
Quoted 4 lines
mount/devname.c +0
-4-static void -die_if_null (void *t) { -if (t ==NULL ) -die (EX_SYSERR ,_ ("not enough memory" ));^^^^^^^^Quoted 1 line
-}
The reason I kept this silly function was because gcc complains about freeing const char * variables, which is quite correct. What do you think about un consitifying them and getting rid of die_if_null()?
-Davidlohr
Quoted 10 lines
it means that you have to use:
#define
XALLOC_EXIT_CODEEX_SYSERR
#include "xalloc.h"to keep it backwardly compatible.
Karel
Quoted 17 lines · Karel Zak
Quoted 7 lines · Davidlohr Bueso
mount/devname.c +0
-0@@ -2,6 +2,7 @@=20
#include "devname.h"
#include "sundries.h" /* for xstrdup */
+#include "xalloc.h"=20
It would be better to includexalloc.hinsunders.honly.
=20mount/devname.c
Quoted 4 lines
mount/devname.c +0
-4-static void -die_if_null (void *t) { - if (t =3D=3D NULL) -die (EX_SYSERR ,_ ("not enough memory" ));^^^^^^^^Quoted 1 line
-}
Quoted 8 lines
=20
it means that you have to use:
=20
#defineXALLOC_EXIT_CODEEX_SYSERR
#include "xalloc.h"
=20
to keep it backwardly compatible.
=20
Ok, below is v2.
Thanks.
From: Davidlohr Bueso <[email protected]>
Date: Wed, 14 Sep 2011 15:05:22 -0300
Subject: [PATCH] mount: use common libs
Get rid of the local xmalloc.[c/h] files by using the global xalloc and s= trutils libraries.
--- mount/Makefile.am | 2 +- mount/fstab.c | 2 +- mount/lomount.c | 1 - mount/mount.c | 1 - mount/sundries.c | 1 - mount/sundries.h | 6 ++++-- mount/umount.c | 1 + mount/xmalloc.c | 48 -----------------------------------------------= - mount/xmalloc.h | 14 -------------- 9 files changed, 7 insertions(+), 69 deletions(-) delete mode 100644 mount/xmalloc.c delete mode 100644 mount/xmalloc.h
mount/Makefile.am +0 -0
@@ -7,7 +7,7 @@ sbin_PROGRAMS =3D losetup swapon dist_man_MANS =3D fstab.5 mount.8 swapoff.8 swapon.8 umount.8 losetup.8
=20
# generic sources for all programs (mount, umount, losetup) -srcs_common =3D sundries.c xmalloc.c $(top_srcdir)/lib/canonicalize.c su= ndries.h xmalloc.h +srcs_common =3D sundries.c $(top_srcdir)/lib/canonicalize.c sundries.h =20 # generic header for mount and umount hdrs_mount =3D fstab.h mount_mntent.h mount_constants.h \
mount/fstab.c +1 -1
@@ -12,10 +12,10 @@#include <sys/time.h> #include <time.h> #include <mntent.h> +#include "mount_mntent.h" #include "fstab.h" #include "sundries.h" -#include "xmalloc.h" #include "fsprobe.h" #include "pathnames.h" #include "nls.h"
mount/lomount.c +0 -1
@@ -21,7 +21,6 @@#include "strutils.h" #include "nls.h" #include "sundries.h" -#include "xmalloc.h" #include "pathnames.h"
=20
#ifdef LOOP_SET_FD
mount/mount.c +0 -1
@@ -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"
mount/sundries.c +0 -0
@@ -15,7 +15,6 @@#include "canonicalize.h"
=20
#include "sundries.h"
-#include "xmalloc.h"
#include "nls.h"
=20
int mount_quiet;
mount/sundries.h +0 -0
@@ -13,6 +13,9 @@#include <stdarg.h> #include <stdlib.h>
=20
+#define XALLOC_EXIT_CODE 2 /* same as EX_SYSERR, for backwards compatibi= lity */
+#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;
=20
#define streq(s, t) (strcmp ((s), (t)) =3D=3D 0)
+#define my_free(_p) free((void *) _p)
=20
void block_signals (int how);
=20
@@ -30,8 +34,6 @@ void die(int err, const char *fmt, ...)
=20
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 *);
mount/umount.c +1 -0
@@ -11,6 +11,7 @@#include <sys/stat.h> #include <sys/wait.h> #include <sys/mount.h> +#include "mount_constants.h" #include "sundries.h" #include "getusername.h"
mount/xmalloc.c deleted +0 -48
48 lines not on this page · raw message
mount/xmalloc.h deleted +0 -10
@@ -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 =E2=80=98free=E2=80=99 discards qua=
lifiers from pointer target type
- */
-#define my_free(_p) free((void *) _p)
-
-#endif /* MOUNT_XMALLOC_H */
--=20
1.7.4.1
Quoted 4 lines · Davidlohr Bueso
mount/Makefile.am | 2 +- mount/fstab.c | 2 +- mount/lomount.c | 1 - mount/mount.c | 1 -
Quoted 8 lines
mount/sundries.c | 1 - mount/sundries.h | 6 ++++-- mount/umount.c | 1 + mount/xmalloc.c | 48 ------------------------------------------------ mount/xmalloc.h | 14 -------------- 9 files changed, 7 insertions(+), 69 deletions(-) delete mode 100644 mount/xmalloc.c delete mode 100644 mount/xmalloc.h
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com