This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH 1/3] unify xmalloc prototypes & friends
These prototypes are duplicated in many places. Add a dedicated
header for holding prototypes for program-specific functions to
avoid that.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
2012-12-30 Mike Frysinger <vapier@gentoo.org>
* catgets/gencat.c: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
(xrealloc): Likewise.
(xstrdup): Likewise.
* elf/pldd.c: Include locale/programs/programs.h.
(xmalloc): Delete.
(xrealloc): Likewise.
* iconv/iconv_charmap.c: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
* iconv/iconvconfig.c: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
(xrealloc): Likewise.
* iconv/strtab.c: Include locale/programs/programs.h.
(xmalloc): Delete.
* locale/programs/locale.c: Include locale/programs/programs.h.
(xmalloc): Delete.
(xstrdup): Likewise.
* locale/programs/localedef.h: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
(xrealloc): Likewise.
(xstrdup): Likewise.
* locale/programs/programs.h: New file.
* locale/programs/simple-hash.c: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
* nscd/nscd.h: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
(xrealloc): Likewise.
* nss/makedb.c: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
* sysdeps/generic/ldconfig.h: Include locale/programs/programs.h.
(xmalloc): Delete.
(xcalloc): Likewise.
(xrealloc): Likewise.
(xstrdup): Likewise.
---
catgets/gencat.c | 8 +-------
elf/pldd.c | 5 +----
iconv/iconv_charmap.c | 5 +----
iconv/iconvconfig.c | 7 +------
iconv/strtab.c | 3 +--
locale/programs/locale.c | 5 +----
locale/programs/localedef.h | 8 +-------
locale/programs/programs.h | 34 ++++++++++++++++++++++++++++++++++
locale/programs/simple-hash.c | 5 +----
nscd/nscd.h | 7 +------
nss/makedb.c | 5 +----
sysdeps/generic/ldconfig.h | 8 +-------
12 files changed, 45 insertions(+), 55 deletions(-)
create mode 100644 locale/programs/programs.h
diff --git a/catgets/gencat.c b/catgets/gencat.c
index 5078e3c..02392ab 100644
--- a/catgets/gencat.c
+++ b/catgets/gencat.c
@@ -137,13 +137,7 @@ static struct argp argp =
/* Wrapper functions with error checking for standard functions. */
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
-extern void *xrealloc (void *o, size_t n)
- __attribute_malloc__ __attribute_alloc_size (2);
-extern char *xstrdup (const char *) __attribute_malloc__;
+#include <locale/programs/programs.h>
/* Prototypes for local functions. */
static void error_print (void);
diff --git a/elf/pldd.c b/elf/pldd.c
index a8e2e5c..de2621d 100644
--- a/elf/pldd.c
+++ b/elf/pldd.c
@@ -43,10 +43,7 @@ extern char *program_invocation_short_name;
#define PACKAGE _libc_intl_domainname
/* External functions. */
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xrealloc (void *o, size_t n)
- __attribute_malloc__ __attribute_alloc_size (2);
+#include <locale/programs/programs.h>
/* Name and version of program. */
static void print_version (FILE *stream, struct argp_state *state);
diff --git a/iconv/iconv_charmap.c b/iconv/iconv_charmap.c
index 1a0de35..ec44a8e 100644
--- a/iconv/iconv_charmap.c
+++ b/iconv/iconv_charmap.c
@@ -32,10 +32,7 @@
/* Prototypes for a few program-wide used functions. */
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
+#include <locale/programs/programs.h>
struct convtable
diff --git a/iconv/iconvconfig.c b/iconv/iconvconfig.c
index d70b013..e0593f8 100644
--- a/iconv/iconvconfig.c
+++ b/iconv/iconvconfig.c
@@ -247,12 +247,7 @@ static struct
static const char gconv_module_ext[] = MODULE_EXT;
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
-extern void *xrealloc (void *o, size_t n)
- __attribute_malloc__ __attribute_alloc_size (2);
+#include <locale/programs/programs.h>
/* C string table handling. */
diff --git a/iconv/strtab.c b/iconv/strtab.c
index 10b51b4..89bce02 100644
--- a/iconv/strtab.c
+++ b/iconv/strtab.c
@@ -65,8 +65,7 @@ struct Strtab
static size_t ps;
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
+#include <locale/programs/programs.h>
/* Prototypes for our functions that are used from iconvconfig.c. If
you change these, change also iconvconfig.c. */
diff --git a/locale/programs/locale.c b/locale/programs/locale.c
index 6bbd9d6..6299b94 100644
--- a/locale/programs/locale.c
+++ b/locale/programs/locale.c
@@ -42,10 +42,7 @@
#include "localeinfo.h"
#include "charmap-dir.h"
#include "../locarchive.h"
-
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern char *xstrdup (const char *) __attribute_malloc__;
+#include "programs.h"
#define ARCHIVE_NAME LOCALEDIR "/locale-archive"
diff --git a/locale/programs/localedef.h b/locale/programs/localedef.h
index d58299b..3fb17b4 100644
--- a/locale/programs/localedef.h
+++ b/locale/programs/localedef.h
@@ -120,13 +120,7 @@ extern const char *alias_file;
/* Prototypes for a few program-wide used functions. */
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
-extern void *xrealloc (void *o, size_t n)
- __attribute_malloc__ __attribute_alloc_size (2);
-extern char *xstrdup (const char *) __attribute_malloc__;
+#include "programs.h"
/* Wrapper to switch LC_CTYPE back to the locale specified in the
diff --git a/locale/programs/programs.h b/locale/programs/programs.h
new file mode 100644
index 0000000..3e9a257
--- /dev/null
+++ b/locale/programs/programs.h
@@ -0,0 +1,34 @@
+/* General definitions for program modules.
+ Copyright (C) 1998-2012 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation; version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _PROGRAMS_H
+#define _PROGRAMS_H 1
+
+#include <features.h>
+#include <stdlib.h>
+
+/* Prototypes for a few program-wide used functions. */
+extern void *xmalloc (size_t n)
+ __attribute_malloc__ __attribute_alloc_size (1);
+extern void *xcalloc (size_t n, size_t s)
+ __attribute_malloc__ __attribute_alloc_size (1, 2);
+extern void *xrealloc (void *o, size_t n)
+ __attribute_malloc__ __attribute_alloc_size (2);
+extern char *xstrdup (const char *) __attribute_malloc__;
+
+#endif /* programs.h */
diff --git a/locale/programs/simple-hash.c b/locale/programs/simple-hash.c
index bb30766..43385c4 100644
--- a/locale/programs/simple-hash.c
+++ b/locale/programs/simple-hash.c
@@ -52,10 +52,7 @@
#define hashval_t uint32_t
#include "hashval.h"
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
+#include "programs.h"
typedef struct hash_entry
{
diff --git a/nscd/nscd.h b/nscd/nscd.h
index 86ac278..3af44f7 100644
--- a/nscd/nscd.h
+++ b/nscd/nscd.h
@@ -200,12 +200,7 @@ extern gid_t old_gid;
/* Prototypes for global functions. */
/* Wrapper functions with error checking for standard functions. */
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
-extern void *xrealloc (void *o, size_t n)
- __attribute_malloc__ __attribute_alloc_size (2);
+#include <locale/programs/programs.h>
/* nscd.c */
extern void termination_handler (int signum) __attribute__ ((__noreturn__));
diff --git a/nss/makedb.c b/nss/makedb.c
index e372f5d..7b2dda8 100644
--- a/nss/makedb.c
+++ b/nss/makedb.c
@@ -173,10 +173,7 @@ static void reset_file_creation_context (void);
/* External functions. */
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
+#include <locale/programs/programs.h>
int
diff --git a/sysdeps/generic/ldconfig.h b/sysdeps/generic/ldconfig.h
index 43cb9bd..cf6152b 100644
--- a/sysdeps/generic/ldconfig.h
+++ b/sysdeps/generic/ldconfig.h
@@ -83,12 +83,6 @@ extern int opt_verbose;
extern int opt_format;
/* Prototypes for a few program-wide used functions. */
-extern void *xmalloc (size_t n)
- __attribute_malloc__ __attribute_alloc_size (1);
-extern void *xcalloc (size_t n, size_t s)
- __attribute_malloc__ __attribute_alloc_size (1, 2);
-extern void *xrealloc (void *o, size_t n)
- __attribute_malloc__ __attribute_alloc_size (2);
-extern char *xstrdup (const char *) __attribute_malloc__;
+#include <locale/programs/programs.h>
#endif /* ! _LDCONFIG_H */
--
1.8.0