summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2016-10-11 23:06:48 +0900
committerMark Wielaard <mjw@redhat.com>2016-10-12 15:43:14 +0200
commit60b2bf1b08c621492410b24e469b2bdf58d167d5 (patch)
tree9a9f16d5a686b42469c190a7d3b0bd245344dc48 /lib
parent7bf4b63a4980788e6c1969cae02f0483e79c069f (diff)
lib: Provide MAX and MIN in system.h
This change also creates a new header file libeu.h to provide the prototypes for the function of libeu. That hides the definition of function crc32, which can conflict with zlib, from libelf. It also prevents mistakes to refer those functions from a component which doesn't link with libeu, such as libelf. Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog14
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/color.c2
-rw-r--r--lib/crc32_file.c2
-rw-r--r--lib/fixedsizehash.h1
-rw-r--r--lib/libeu.h78
-rw-r--r--lib/system.h48
-rw-r--r--lib/xstrdup.c2
-rw-r--r--lib/xstrndup.c3
9 files changed, 106 insertions, 48 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 76b5753d..88c71c9a 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,17 @@
+2015-10-11 Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
+
+ * Makefile.am (noinst_HEADERS): Add libeu.h.
+ * color.c: Remove system.h include, add libeu.h include.
+ * crc32_file.c: Likewise.
+ * fixedsizehash.h: Remove sys/param.h include.
+ * libeu.h: New file.
+ * system.h: Include sys/param.h.
+ (xmalloc, xcalloc, xrealloc, xstrdup, xstrndup, crc32, crc32_file,
+ color_argp, color_enum, color_*): Move definitions to libeu.h.
+ * xstrdup.c: Remove system.h include, add libeu.h include.
+ * xstrndup.c: Remove system.h include, add libeu.h and stdint.h
+ includes.
+
2015-09-24 Jose E. Marchesi <jose.marchesi@oracle.com>
* Makefile.am (AM_CFLAGS): Use -fPIC instead of -fpic to avoid relocation
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 2219eaa4..7ca2bd41 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -37,8 +37,8 @@ libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \
crc32.c crc32_file.c md5.c sha1.c \
color.c
-noinst_HEADERS = fixedsizehash.h system.h dynamicsizehash.h list.h md5.h \
- sha1.h eu-config.h
+noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
+ md5.h sha1.h eu-config.h
EXTRA_DIST = dynamicsizehash.c
if !GPROF
diff --git a/lib/color.c b/lib/color.c
index d1309ed7..fde2d9de 100644
--- a/lib/color.c
+++ b/lib/color.c
@@ -37,7 +37,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "system.h"
+#include "libeu.h"
/* Prototype for option handler. */
diff --git a/lib/crc32_file.c b/lib/crc32_file.c
index c0b18e91..a8434d42 100644
--- a/lib/crc32_file.c
+++ b/lib/crc32_file.c
@@ -30,7 +30,7 @@
# include <config.h>
#endif
-#include "system.h"
+#include "libeu.h"
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
index 06ce6a25..18921a44 100644
--- a/lib/fixedsizehash.h
+++ b/lib/fixedsizehash.h
@@ -31,7 +31,6 @@
#include <stdlib.h>
#include <string.h>
#include <sys/cdefs.h>
-#include <sys/param.h>
#include <system.h>
diff --git a/lib/libeu.h b/lib/libeu.h
new file mode 100644
index 00000000..69fe3d7f
--- /dev/null
+++ b/lib/libeu.h
@@ -0,0 +1,78 @@
+/* Declarations for the common library.
+ Copyright (C) 2006-2011 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of either
+
+ * the GNU Lesser General Public License as published by the Free
+ Software Foundation; either version 3 of the License, or (at
+ your option) any later version
+
+ or
+
+ * the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at
+ your option) any later version
+
+ or both in parallel, as here.
+
+ elfutils 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 copies of the GNU General Public License and
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef LIBEU_H
+#define LIBEU_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+extern void *xmalloc (size_t) __attribute__ ((__malloc__));
+extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__));
+extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__));
+
+extern char *xstrdup (const char *) __attribute__ ((__malloc__));
+extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__));
+
+
+extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len);
+extern int crc32_file (int fd, uint32_t *resp);
+
+
+/* Color handling. */
+
+/* Command line parser. */
+extern const struct argp color_argp;
+
+/* Coloring mode. */
+enum color_enum
+ {
+ color_never = 0,
+ color_always,
+ color_auto
+ } __attribute__ ((packed));
+extern enum color_enum color_mode;
+
+/* Colors to use for the various components. */
+extern char *color_address;
+extern char *color_bytes;
+extern char *color_mnemonic;
+extern char *color_operand1;
+extern char *color_operand2;
+extern char *color_operand3;
+extern char *color_label;
+extern char *color_undef;
+extern char *color_undef_tls;
+extern char *color_undef_weak;
+extern char *color_symbol;
+extern char *color_tls;
+extern char *color_weak;
+
+extern const char color_off[];
+
+#endif
diff --git a/lib/system.h b/lib/system.h
index f31cfd03..ec387c31 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -32,6 +32,7 @@
#include <argp.h>
#include <stddef.h>
#include <stdint.h>
+#include <sys/param.h>
#include <endian.h>
#include <byteswap.h>
#include <unistd.h>
@@ -50,16 +51,14 @@
# error "Unknown byte order"
#endif
-extern void *xmalloc (size_t) __attribute__ ((__malloc__));
-extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__));
-extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__));
-
-extern char *xstrdup (const char *) __attribute__ ((__malloc__));
-extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__));
+#ifndef MAX
+#define MAX(m, n) ((m) < (n) ? (n) : (m))
+#endif
+#ifndef MIN
+#define MIN(m, n) ((m) < (n) ? (m) : (n))
+#endif
-extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len);
-extern int crc32_file (int fd, uint32_t *resp);
/* A special gettext function we use if the strings are too short. */
#define sgettext(Str) \
@@ -142,39 +141,6 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
extern char *__cxa_demangle (const char *mangled_name, char *output_buffer,
size_t *length, int *status);
-
-
-/* Color handling. */
-
-/* Command line parser. */
-extern const struct argp color_argp;
-
-/* Coloring mode. */
-enum color_enum
- {
- color_never = 0,
- color_always,
- color_auto
- } __attribute__ ((packed));
-extern enum color_enum color_mode;
-
-/* Colors to use for the various components. */
-extern char *color_address;
-extern char *color_bytes;
-extern char *color_mnemonic;
-extern char *color_operand1;
-extern char *color_operand2;
-extern char *color_operand3;
-extern char *color_label;
-extern char *color_undef;
-extern char *color_undef_tls;
-extern char *color_undef_weak;
-extern char *color_symbol;
-extern char *color_tls;
-extern char *color_weak;
-
-extern const char color_off[];
-
/* A static assertion. This will cause a compile-time error if EXPR,
which must be a compile-time constant, is false. */
diff --git a/lib/xstrdup.c b/lib/xstrdup.c
index aa10352a..ff1e3d4f 100644
--- a/lib/xstrdup.c
+++ b/lib/xstrdup.c
@@ -31,7 +31,7 @@
#endif
#include <string.h>
-#include "system.h"
+#include "libeu.h"
/* Return a newly allocated copy of STRING. */
diff --git a/lib/xstrndup.c b/lib/xstrndup.c
index 92b79c17..d43e3b9e 100644
--- a/lib/xstrndup.c
+++ b/lib/xstrndup.c
@@ -30,8 +30,9 @@
# include <config.h>
#endif
+#include <stdint.h>
#include <string.h>
-#include "system.h"
+#include "libeu.h"
/* Return a newly allocated copy of STRING. */