From f45bc2de515013c983ee9e8f6898bd3119832fc1 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Sat, 7 Jun 2014 12:26:32 +0200 Subject: libcompat: Make the library testable This will allow us to guarantee the compatibility implementations at least build, and can eventually be tested. --- debian/changelog | 2 ++ lib/compat/Makefile.am | 15 ++++++++++- lib/compat/alphasort.c | 2 ++ lib/compat/asprintf.c | 2 ++ lib/compat/compat.h | 69 +++++++++++++++++++++++++++++++++++++------------- lib/compat/scandir.c | 2 ++ lib/compat/snprintf.c | 3 ++- lib/compat/strerror.c | 4 +++ lib/compat/strndup.c | 3 +-- lib/compat/strsignal.c | 2 ++ lib/compat/unsetenv.c | 2 ++ lib/compat/vasprintf.c | 2 ++ lib/compat/vsnprintf.c | 2 ++ 13 files changed, 88 insertions(+), 22 deletions(-) diff --git a/debian/changelog b/debian/changelog index 203108423..35d2944b9 100644 --- a/debian/changelog +++ b/debian/changelog @@ -5,6 +5,8 @@ dpkg (1.17.11) UNRELEASED; urgency=low latter is available (round two). This includes the quilt patch header templates, and examples in man pages. * Update some dpkg git URLs to the new and newer (cgit switch) scheme. + * Changes to libcompat: + - Make the library testable. [ Updated programs translations ] * Danish (Joe Dalton). Closes: #754127 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 #include +#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 #include +#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 +#endif + +#if TEST_LIBCOMPAT || !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_SNPRINTF) +#include +#endif + +#if TEST_LIBCOMPAT || !defined(HAVE_VA_COPY) +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -51,56 +68,72 @@ extern "C" { #endif #ifndef HAVE_VA_COPY -#include #define va_copy(dest, src) memcpy(&(dest), &(src), sizeof(va_list)) #endif -#ifndef HAVE_C99_SNPRINTF -#include -#include - +#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 - +#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 - -#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 #include +#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 -#include #include #include #include +#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 #include +#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 -#include #include #include -#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 #include +#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 #include +#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 #include +#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 #include +#include "compat.h" + int vsnprintf(char *buf, size_t maxsize, const char *fmt, va_list args) { -- cgit v1.2.3