summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog30
-rw-r--r--lib/Makefile.am45
-rw-r--r--lib/eu-config.h40
-rw-r--r--lib/eu_compat.def.in10
-rw-r--r--lib/features.h.in43
-rw-r--r--lib/libeu_compat.h77
-rw-r--r--lib/printversion.h10
-rw-r--r--lib/system.h21
-rw-r--r--lib/xstrndup.c2
9 files changed, 264 insertions, 14 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 86a53d2c..8aa19734 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,28 @@
+2017-05-04 Ulf Hermann <[email protected]>
+
+ * Makefile.am: On windows, build an eu_compat.dll to forward symbols
+ from the C and std C++ libraries elfutils links against.
+ * eu_compat.def.in: New file.
+
+2017-05-04 Ulf Hermann <[email protected]>
+
+ * printversion.h: Define ARGP_PROGRAM_VERSION_HOOK_DEF and
+ ARGP_BUG_ADDRESS_DEF to be non-const and drop the asm tricks.
+
+2017-05-04 Ulf Hermann <[email protected]>
+
+ * system.h: Define FILE_SYSTEM_PREFIX_LEN, ISDIRSEP, DIRSEP, PATHSEP,
+ and IS_ABSOLUTE_PATH to help with handling file system paths.
+
+2017-05-04 Ulf Hermann <[email protected]>
+
+ * eu-config.h: Define O_BINARY to 0 if it doesn't exist.
+
+2017-05-04 Ulf Hermann <[email protected]>
+
+ * eu-config.h: Define unlocked I/O functions to locked ones if they
+ are unavailable.
+
2018-07-04 Ross Burton <[email protected]>
* color.c: Remove error.h, add system.h include.
@@ -33,6 +58,11 @@
* Makefile.am: Use fpic_CFLAGS.
+2017-04-27 Ulf Hermann <[email protected]>
+
+ * system.h: Drop mempcpy replacement.
+ * xstrndup.c: Don't include system.h.
+
2017-07-18 Mark Wielaard <[email protected]>
* bpf.h: New file.
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 36d21a07..edd669fb 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -31,6 +31,7 @@ include $(top_srcdir)/config/eu.am
AM_CFLAGS += $(fpic_CFLAGS)
AM_CPPFLAGS += -I$(srcdir)/../libelf
+pkginclude_HEADERS = libeu_compat.h
noinst_LIBRARIES = libeu.a
libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \
@@ -39,8 +40,50 @@ libeu_a_SOURCES = xstrdup.c xstrndup.c xmalloc.c next_prime.c \
noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
eu-config.h color.h printversion.h bpf.h
-EXTRA_DIST = dynamicsizehash.c
+EXTRA_DIST = dynamicsizehash.c features.h.in
if !GPROF
xmalloc_CFLAGS = -ffunction-sections
endif
+
+if SELFCONTAINED
+install-headers: install-am features.h.in
+ $(mkinstalldirs) $(DESTDIR)$(includedir)
+ $(INSTALL_HEADER) $(top_srcdir)/lib/features.h.in $(DESTDIR)$(includedir)/features.h
+
+uninstall-headers: uninstall-am
+ rm -f $(DESTDIR)$(includedir)/features.h
+else
+install-headers:
+uninstall-headers:
+endif
+
+EXTRA_DIST += eu_compat.def.in
+if NATIVE_PE
+
+eu_compat.def: eu_compat.def.in
+ cp $< $@
+
+CLEANFILES += eu_compat.def
+
+$(libeu_compat_BARE): eu_compat.def
+ $(CCLD) $(dso_LDFLAGS) $(LDFLAGS) -o $@ $< -lstdc++
+
+noinst_DATA = $(libeu_compat_BARE)
+
+install-lib: $(libeu_compat_BARE:.dll=.lib) $(libeu_compat_BARE)
+ $(mkinstalldirs) $(DESTDIR)$(libdir)
+ $(INSTALL_PROGRAM) $(libeu_compat_BARE) $(DESTDIR)$(libdir)/$(libeu_compat_BARE)
+ $(INSTALL_PROGRAM) $< $(DESTDIR)$(libdir)/$(libeu_compat_BARE:.dll=.lib)
+uninstall-lib:
+ rm -f $(DESTDIR)$(libdir)/$(libeu_compat_BARE)
+ rm -f $(DESTDIR)$(libdir)/$(libeu_compat_BARE:.dll=.lib)
+
+CLEANFILES += $(libeu_compat_BARE) $(libeu_compat_BARE:.dll=.lib) $(libeu_compat_BARE:.dll=.exp)
+else
+install-lib:
+uninstall-lib:
+endif
+
+install: install-am install-headers install-lib
+uninstall: uninstall-am uninstall-headers uninstall-lib
diff --git a/lib/eu-config.h b/lib/eu-config.h
index 84b22d7c..567a8238 100644
--- a/lib/eu-config.h
+++ b/lib/eu-config.h
@@ -198,6 +198,46 @@ asm (".section predict_data, \"aw\"; .previous\n"
# define COMPAT_VERSION(name, version, prefix) error "should use #ifdef SYMBOL_VERSIONING"
#endif
+#if !HAVE_FLOCKFILE
+# define flockfile(fp) /* nop */
+#endif
+
+#if !HAVE_FUNLOCKFILE
+# define funlockfile(fp) /* nop */
+#endif
+
+#if !HAVE_DECL_FEOF_UNLOCKED
+#define feof_unlocked(x) feof (x)
+#endif
+
+#if !HAVE_DECL_FERROR_UNLOCKED
+#define ferror_unlocked(x) ferror (x)
+#endif
+
+#if !HAVE_DECL_FPUTC_UNLOCKED
+#define fputc_unlocked(x,y) fputc (x,y)
+#endif
+
+#if !HAVE_DECL_FPUTS_UNLOCKED
+#define fputs_unlocked(x,y) fputs (x,y)
+#endif
+
+#if !HAVE_DECL_FWRITE_UNLOCKED
+#define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z)
+#endif
+
+#if !HAVE_DECL_PUTC_UNLOCKED
+#define putc_unlocked(x,y) putc (x,y)
+#endif
+
+#if !HAVE_DECL_PUTCHAR_UNLOCKED
+#define putchar_unlocked(x) putchar (x)
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
#ifndef FALLTHROUGH
# ifdef HAVE_FALLTHROUGH
# define FALLTHROUGH __attribute__ ((fallthrough))
diff --git a/lib/eu_compat.def.in b/lib/eu_compat.def.in
new file mode 100644
index 00000000..bed5c83c
--- /dev/null
+++ b/lib/eu_compat.def.in
@@ -0,0 +1,10 @@
+LIBRARY "eu_compat.dll"
+EXPORTS
+eu_compat_demangle=__cxa_demangle
+eu_compat_open=msvcrt._open
+eu_compat_close=msvcrt._close
+eu_compat_malloc=msvcrt.malloc
+eu_compat_realloc=msvcrt.realloc
+eu_compat_calloc=msvcrt.calloc
+eu_compat_free=msvcrt.free
+eu_compat_strdup=msvcrt._strdup
diff --git a/lib/features.h.in b/lib/features.h.in
new file mode 100644
index 00000000..6eb3c67d
--- /dev/null
+++ b/lib/features.h.in
@@ -0,0 +1,43 @@
+/* This file defines uid_t, gid_t, mode_t, pid_t
+ Copyright (C) 2017 The Qt Company Ltd
+ 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 _FEATURES_H
+#define _FEATURES_H 1
+
+#include <stdint.h>
+
+typedef uint32_t uid_t;
+typedef uint32_t gid_t;
+typedef uint32_t mode_t;
+#ifdef _WIN64
+typedef int64_t pid_t;
+#else
+typedef int32_t pid_t;
+#endif
+
+#endif /* features.h */
diff --git a/lib/libeu_compat.h b/lib/libeu_compat.h
new file mode 100644
index 00000000..fe73e237
--- /dev/null
+++ b/lib/libeu_compat.h
@@ -0,0 +1,77 @@
+/* Interface for libeu_compat.
+ Copyright (C) 2018 The Qt Company Ltd.
+ 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_COMPAT_H
+#define _LIBEU_COMPAT_H 1
+
+#if (defined _WIN32 || defined __WIN32__)
+
+#include <io.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char *eu_compat_demangle(const char *mangled_name, char *output_buffer,
+ size_t *length, int *status);
+
+extern int eu_compat_open(const char *, int);
+extern int eu_compat_close(int);
+
+extern void *eu_compat_malloc(size_t);
+extern void *eu_compat_realloc(void *, size_t);
+extern void *eu_compat_calloc(size_t);
+extern void eu_compat_free(void *);
+
+extern char* eu_compat_strdup(const char* string);
+
+#ifdef __cplusplus
+}
+#endif
+
+#else
+
+#include <cxxabi.h>
+#include <unistd.h>
+
+#define eu_compat_demangle abi::__cxa_demangle
+
+#define eu_compat_open open
+#define eu_compat_close close
+#define O_BINARY 0
+
+#define eu_compat_malloc malloc
+#define eu_compat_realloc realloc
+#define eu_compat_calloc calloc
+#define eu_compat_free free
+
+#define eu_compat_strdup strdup
+
+#endif
+
+#endif // _LIBEU_COMPAT_H
diff --git a/lib/printversion.h b/lib/printversion.h
index a9e059ff..090b53ab 100644
--- a/lib/printversion.h
+++ b/lib/printversion.h
@@ -36,14 +36,10 @@
void print_version (FILE *stream, struct argp_state *state);
/* We need define two variables, argp_program_version_hook and
- argp_program_bug_address, in all programs. argp.h declares these
- variables as non-const (which is correct in general). But we can
- do better, it is not going to change. So we want to move them into
- the .rodata section. Define macros to do the trick. */
+ argp_program_bug_address, in all programs. */
#define ARGP_PROGRAM_VERSION_HOOK_DEF \
- void (*const apvh) (FILE *, struct argp_state *) \
- __asm ("argp_program_version_hook")
+ void (*argp_program_version_hook) (FILE *, struct argp_state *)
#define ARGP_PROGRAM_BUG_ADDRESS_DEF \
- const char *const apba__ __asm ("argp_program_bug_address")
+ const char *argp_program_bug_address
#endif // PRINTVERSION_H
diff --git a/lib/system.h b/lib/system.h
index 292082bd..5275a7b2 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -52,6 +52,22 @@
# error "Unknown byte order"
#endif
+#if (defined _WIN32 || defined __WIN32__)
+# define _IS_DRIVE_LETTER(c) (((unsigned int) (c) | ('a' - 'A')) - 'a' <= 'z' - 'a')
+# define FILE_SYSTEM_PREFIX_LEN(filename) \
+ (_IS_DRIVE_LETTER ((filename)[0]) && (filename)[1] == ':' ? 2 : 0)
+# define ISDIRSEP(c) ((c) == '/' || (c) == '\\')
+# define DIRSEP '\\'
+# define PATHSEP ';'
+# define IS_ABSOLUTE_PATH(f) ISDIRSEP ((f)[FILE_SYSTEM_PREFIX_LEN (f)])
+#else
+# define FILE_SYSTEM_PREFIX_LEN(filename) 0
+# define ISDIRSEP(c) ((c) == '/')
+# define DIRSEP '/'
+# define PATHSEP ':'
+# define IS_ABSOLUTE_PATH(p) (ISDIRSEP ((p)[0]))
+#endif
+
#ifndef MAX
#define MAX(m, n) ((m) < (n) ? (n) : (m))
#endif
@@ -64,11 +80,6 @@
#define powerof2(x) (((x) & ((x) - 1)) == 0)
#endif
-#if !HAVE_DECL_MEMPCPY
-#define mempcpy(dest, src, n) \
- ((void *) ((char *) memcpy (dest, src, n) + (size_t) n))
-#endif
-
/* A special gettext function we use if the strings are too short. */
#define sgettext(Str) \
({ const char *__res = strrchr (gettext (Str), '|'); \
diff --git a/lib/xstrndup.c b/lib/xstrndup.c
index a257aa9a..d43e3b9e 100644
--- a/lib/xstrndup.c
+++ b/lib/xstrndup.c
@@ -33,7 +33,7 @@
#include <stdint.h>
#include <string.h>
#include "libeu.h"
-#include "system.h"
+
/* Return a newly allocated copy of STRING. */
char *