summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGuillem Jover <guillem@debian.org>2014-06-07 12:26:32 +0200
committerGuillem Jover <guillem@debian.org>2014-08-09 22:04:10 +0200
commitf45bc2de515013c983ee9e8f6898bd3119832fc1 (patch)
tree087539f23f7d02984446a216c3a3feead99b08a8 /lib
parent5a7ed8dcb798baec356e48466ec4c5fa4754103e (diff)
downloaddpkg-f45bc2de515013c983ee9e8f6898bd3119832fc1.tar.gz
libcompat: Make the library testable
This will allow us to guarantee the compatibility implementations at least build, and can eventually be tested.
Diffstat (limited to 'lib')
-rw-r--r--lib/compat/Makefile.am15
-rw-r--r--lib/compat/alphasort.c2
-rw-r--r--lib/compat/asprintf.c2
-rw-r--r--lib/compat/compat.h69
-rw-r--r--lib/compat/scandir.c2
-rw-r--r--lib/compat/snprintf.c3
-rw-r--r--lib/compat/strerror.c4
-rw-r--r--lib/compat/strndup.c3
-rw-r--r--lib/compat/strsignal.c2
-rw-r--r--lib/compat/unsetenv.c2
-rw-r--r--lib/compat/vasprintf.c2
-rw-r--r--lib/compat/vsnprintf.c2
12 files changed, 86 insertions, 22 deletions
diff --git a/lib/compat/Makefile.am b/lib/compat/Makefile.am
index 693c975f8..975f86357 100644
--- a/lib/compat/Makefile.am
+++ b/lib/compat/Makefile.am
@@ -5,7 +5,20 @@ AM_CPPFLAGS = \
-I$(top_builddir)
-noinst_LTLIBRARIES = libcompat.la
+noinst_LTLIBRARIES = libcompat-test.la libcompat.la
+
+libcompat_test_la_CPPFLAGS = $(AM_CPPFLAGS) -DTEST_LIBCOMPAT=1
+libcompat_test_la_SOURCES = \
+ compat.h \
+ strnlen.c \
+ strndup.c \
+ strerror.c \
+ strsignal.c \
+ snprintf.c vsnprintf.c \
+ asprintf.c vasprintf.c \
+ alphasort.c \
+ scandir.c \
+ unsetenv.c
libcompat_la_SOURCES = \
empty.c \
diff --git a/lib/compat/alphasort.c b/lib/compat/alphasort.c
index 145292ae7..0c8f3853c 100644
--- a/lib/compat/alphasort.c
+++ b/lib/compat/alphasort.c
@@ -22,6 +22,8 @@
#include <string.h>
#include <dirent.h>
+#include "compat.h"
+
int
alphasort(const void *a, const void *b)
{
diff --git a/lib/compat/asprintf.c b/lib/compat/asprintf.c
index bfdc07de8..9605faf33 100644
--- a/lib/compat/asprintf.c
+++ b/lib/compat/asprintf.c
@@ -22,6 +22,8 @@
#include <stdarg.h>
#include <stdio.h>
+#include "compat.h"
+
int
asprintf(char **strp, char const *fmt, ...)
{
diff --git a/lib/compat/compat.h b/lib/compat/compat.h
index d445a451e..d30520bbd 100644
--- a/lib/compat/compat.h
+++ b/lib/compat/compat.h
@@ -22,6 +22,23 @@
#ifndef COMPAT_H
#define COMPAT_H
+#ifndef TEST_LIBCOMPAT
+#define TEST_LIBCOMPAT 0
+#endif
+
+#if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN) || !defined(HAVE_STRNDUP) || \
+ !defined(HAVE_C99_SNPRINTF)
+#include <stddef.h>
+#endif
+
+#if TEST_LIBCOMPAT || !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_SNPRINTF)
+#include <stdarg.h>
+#endif
+
+#if TEST_LIBCOMPAT || !defined(HAVE_VA_COPY)
+#include <string.h>
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -51,56 +68,72 @@ extern "C" {
#endif
#ifndef HAVE_VA_COPY
-#include <string.h>
#define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list))
#endif
-#ifndef HAVE_C99_SNPRINTF
-#include <stddef.h>
-#include <stdarg.h>
-
+#if TEST_LIBCOMPAT
+#undef snprintf
+#define snprintf test_snprintf
+#undef vsnprintf
+#define vsnprintf test_vsnprintf
+#undef asprintf
+#define asprintf test_asprintf
+#undef vasprintf
+#define vasprintf test_vasprintf
+#undef strndup
+#define strndup test_strndup
+#undef strnlen
+#define strnlen test_strnlen
+#undef strerror
+#define strerror test_strerror
+#undef strsignal
+#define strsignal test_strsignal
+#undef scandir
+#define scandir test_scandir
+#undef alphasort
+#define alphasort test_alphasort
+#undef unsetenv
+#define unsetenv test_unsetenv
+#endif
+
+#if TEST_LIBCOMPAT || !defined(HAVE_C99_SNPRINTF)
int snprintf(char *str, size_t n, char const *fmt, ...);
int vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args);
#endif
-#ifndef HAVE_ASPRINTF
-#include <stdarg.h>
-
+#if TEST_LIBCOMPAT || !defined(HAVE_ASPRINTF)
int asprintf(char **str, char const *fmt, ...);
int vasprintf(char **str, const char *fmt, va_list args);
#endif
-#ifndef HAVE_STRNLEN
+#if TEST_LIBCOMPAT || !defined(HAVE_STRNLEN)
size_t strnlen(const char *s, size_t n);
#endif
-#ifndef HAVE_STRNDUP
-#include <stddef.h>
-
-#undef strndup
+#if TEST_LIBCOMPAT || !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n);
#endif
-#ifndef HAVE_STRERROR
+#if TEST_LIBCOMPAT || !defined(HAVE_STRERROR)
const char *strerror(int);
#endif
-#ifndef HAVE_STRSIGNAL
+#if TEST_LIBCOMPAT || !defined(HAVE_STRSIGNAL)
const char *strsignal(int);
#endif
-#ifndef HAVE_SCANDIR
+#if TEST_LIBCOMPAT || !defined(HAVE_SCANDIR)
struct dirent;
int scandir(const char *dir, struct dirent ***namelist,
int (*filter)(const struct dirent *),
int (*cmp)(const void *, const void *));
#endif
-#ifndef HAVE_ALPHASORT
+#if TEST_LIBCOMPAT || !defined(HAVE_ALPHASORT)
int alphasort(const void *a, const void *b);
#endif
-#ifndef HAVE_UNSETENV
+#if TEST_LIBCOMPAT || !defined(HAVE_UNSETENV)
int unsetenv(const char *x);
#endif
diff --git a/lib/compat/scandir.c b/lib/compat/scandir.c
index f5a9de363..3d5a0da11 100644
--- a/lib/compat/scandir.c
+++ b/lib/compat/scandir.c
@@ -26,6 +26,8 @@
#include <dirent.h>
#include <stdlib.h>
+#include "compat.h"
+
static int
cleanup(DIR *dir, struct dirent **dirlist, int used)
{
diff --git a/lib/compat/snprintf.c b/lib/compat/snprintf.c
index f973224e7..94cdce6ee 100644
--- a/lib/compat/snprintf.c
+++ b/lib/compat/snprintf.c
@@ -18,12 +18,13 @@
*/
#include <config.h>
-#include <compat.h>
#include <stddef.h>
#include <stdarg.h>
#include <stdio.h>
+#include "compat.h"
+
int
snprintf(char *str, size_t n, char const *fmt, ...)
{
diff --git a/lib/compat/strerror.c b/lib/compat/strerror.c
index 9893e49a0..d5cc5cab1 100644
--- a/lib/compat/strerror.c
+++ b/lib/compat/strerror.c
@@ -22,10 +22,14 @@
#include <stdio.h>
#include <gettext.h>
+#include "compat.h"
+
#define _(str) gettext(str)
+#ifndef HAVE_STRERROR
extern const char *const sys_errlist[];
extern const int sys_nerr;
+#endif
const char *
strerror(int e)
diff --git a/lib/compat/strndup.c b/lib/compat/strndup.c
index 744fffb9d..788c0139f 100644
--- a/lib/compat/strndup.c
+++ b/lib/compat/strndup.c
@@ -18,12 +18,11 @@
*/
#include <config.h>
-#include <compat.h>
#include <string.h>
#include <stdlib.h>
-#undef strndup
+#include "compat.h"
char *
strndup(const char *s, size_t n)
diff --git a/lib/compat/strsignal.c b/lib/compat/strsignal.c
index ea2d81ac9..1f497019e 100644
--- a/lib/compat/strsignal.c
+++ b/lib/compat/strsignal.c
@@ -24,6 +24,8 @@
#include <stdio.h>
#include <gettext.h>
+#include "compat.h"
+
#define _(str) gettext(str)
#ifndef HAVE_DECL_SYS_SIGLIST
diff --git a/lib/compat/unsetenv.c b/lib/compat/unsetenv.c
index 10c291ce9..f4f05f5d3 100644
--- a/lib/compat/unsetenv.c
+++ b/lib/compat/unsetenv.c
@@ -22,6 +22,8 @@
#include <string.h>
#include <stdlib.h>
+#include "compat.h"
+
int
unsetenv(const char *p)
{
diff --git a/lib/compat/vasprintf.c b/lib/compat/vasprintf.c
index 1c8588ca5..9d53a3237 100644
--- a/lib/compat/vasprintf.c
+++ b/lib/compat/vasprintf.c
@@ -23,6 +23,8 @@
#include <stdio.h>
#include <stdlib.h>
+#include "compat.h"
+
int
vasprintf(char **strp, char const *fmt, va_list args)
{
diff --git a/lib/compat/vsnprintf.c b/lib/compat/vsnprintf.c
index 8c1592470..77101f511 100644
--- a/lib/compat/vsnprintf.c
+++ b/lib/compat/vsnprintf.c
@@ -26,6 +26,8 @@
#include <stdarg.h>
#include <stdio.h>
+#include "compat.h"
+
int
vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args)
{