From 5247808140360bc76b00445d9cf490bca981aa64 Mon Sep 17 00:00:00 2001 From: Snaipe Date: Tue, 8 Sep 2015 22:12:22 +0200 Subject: [PATCH] Renamed asprintf to cr_asprintf for compatibility --- CMakeLists.txt | 7 +------ include/criterion/asprintf-compat.h | 16 +++------------- include/criterion/assert.h | 2 +- src/asprintf.c | 7 ++++--- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2038e17..37e02d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,7 @@ set(SOURCE_FILES src/ordered-set.c src/posix-compat.c src/theories.c + src/asprintf.c src/main.c src/entry.c ) @@ -110,12 +111,6 @@ if (PCRE_FOUND) set(HAVE_PCRE 1) endif () -if ("${CMAKE_SYSTEM_NAME}" EQUAL "Linux") - set (SOURCE_FILES ${SOURCE_FILES} - src/asprintf.c - ) -endif () - set(INTERFACE_FILES include/criterion/assert.h include/criterion/abort.h diff --git a/include/criterion/asprintf-compat.h b/include/criterion/asprintf-compat.h index 35997ba..6f78efd 100644 --- a/include/criterion/asprintf-compat.h +++ b/include/criterion/asprintf-compat.h @@ -24,30 +24,20 @@ #ifndef CRITERION_ASPRINTF_COMPAT_H_ # define CRITERION_ASPRINTF_COMPAT_H_ -# ifdef __UNIX__ -# define _GNU_SOURCE 1 -# endif - # ifdef __cplusplus # include # else # include # endif -# ifdef __UNIX__ -# include -# else - -# include "common.h" +# include "common.h" CR_BEGIN_C_API FORMAT(printf, 2, 3) -CR_API int asprintf(char **strp, const char *fmt, ...) CR_NOTHROW; -CR_API int vasprintf(char **strp, const char *fmt, va_list ap) CR_NOTHROW; +CR_API int cr_asprintf(char **strp, const char *fmt, ...); +CR_API int cr_vasprintf(char **strp, const char *fmt, va_list ap); CR_END_C_API -# endif - #endif /* !CRITERION_ASPRINTF_COMPAT_H_ */ diff --git a/include/criterion/assert.h b/include/criterion/assert.h index ab57767..8c28e30 100644 --- a/include/criterion/assert.h +++ b/include/criterion/assert.h @@ -67,7 +67,7 @@ struct criterion_assert_args { do { \ const char *default_msg = "" CR_VA_HEAD(__VA_ARGS__); \ char *formatted_msg = NULL; \ - int msglen = asprintf(&formatted_msg, "" CR_VA_TAIL(__VA_ARGS__)); \ + int msglen = cr_asprintf(&formatted_msg, "" CR_VA_TAIL(__VA_ARGS__));\ MsgVar = formatted_msg && *formatted_msg ? \ formatted_msg : default_msg; \ \ diff --git a/src/asprintf.c b/src/asprintf.c index 2eada51..c2a4a12 100644 --- a/src/asprintf.c +++ b/src/asprintf.c @@ -24,17 +24,18 @@ #include #include +#include #include "criterion/asprintf-compat.h" -int asprintf(char **strp, const char *fmt, ...) { +int cr_asprintf(char **strp, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - int res = vasprintf(strp, fmt, ap); + int res = cr_vasprintf(strp, fmt, ap); va_end(ap); return res; } -int vasprintf(char **strp, const char *fmt, va_list ap) { +int cr_vasprintf(char **strp, const char *fmt, va_list ap) { va_list vl; va_copy(vl, ap);