diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-10-12 10:01:06 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-10-12 11:14:21 +0200 |
commit | ffc88fc5ba638f95648ee2b7599fc72b2a0ffd77 (patch) | |
tree | 2e6cebd076f462720734a200993fa1f117fa8b1d | |
parent | c113e6b3a6fec0b2af0c067682db631d5641dccb (diff) | |
download | embedlog-ffc88fc5ba638f95648ee2b7599fc72b2a0ffd77.tar.gz embedlog-ffc88fc5ba638f95648ee2b7599fc72b2a0ffd77.tar.bz2 embedlog-ffc88fc5ba638f95648ee2b7599fc72b2a0ffd77.zip |
fix: compilation error with bad feature test macro on some systems
some systems defines features in different posix versions
-rw-r--r-- | src/el-file.c | 11 | ||||
-rw-r--r-- | src/el-print.c | 7 | ||||
-rw-r--r-- | src/el-private.h | 33 | ||||
-rw-r--r-- | src/el-ts.c | 37 |
4 files changed, 59 insertions, 29 deletions
diff --git a/src/el-file.c b/src/el-file.c index 0dba76d..94fca8d 100644 --- a/src/el-file.c +++ b/src/el-file.c @@ -43,9 +43,14 @@ #endif #if HAVE_FSYNC && HAVE_FILENO -# ifndef _POSIX_C_SOURCE -# define _POSIX_C_SOURCE 1 -# endif +# define _POSIX_C_SOURCE 1 +#endif + +#if !NEED_SNPRINTF_ONLY && !PREFER_PORTABLE_SNPRINTF + /* if portable snprintf is not used, define _XOPEN_SOURCE to include + * snprintf() and vsnprintf() functions + */ +# define _XOPEN_SOURCE 500 #endif #include "el-private.h" diff --git a/src/el-print.c b/src/el-print.c index b1cc33f..635a7f5 100644 --- a/src/el-print.c +++ b/src/el-print.c @@ -48,6 +48,13 @@ #include "config.h" #endif +#if !NEED_SNPRINTF_ONLY && !PREFER_PORTABLE_SNPRINTF + /* if portable snprintf is not used, define _XOPEN_SOURCE to include + * snprintf() and vsnprintf() functions + */ +# define _XOPEN_SOURCE 500 +#endif + #include "el-private.h" #include <errno.h> diff --git a/src/el-private.h b/src/el-private.h index d55f72e..bf06f43 100644 --- a/src/el-private.h +++ b/src/el-private.h @@ -12,11 +12,11 @@ /* ========================================================================== - ____ __ __ __ - / __/___ ____ _ / /_ __ __ _____ ___ / /_ ___ _____ / /_ - / /_ / _ \ / __ `// __// / / // ___// _ \ / __// _ \ / ___// __/ - / __// __// /_/ // /_ / /_/ // / / __/ / /_ / __/(__ )/ /_ - /_/ \___/ \__,_/ \__/ \__,_//_/ \___/ \__/ \___//____/ \__/ + _ __ __ ____ _ __ + (_)____ _____ / /__ __ ____/ /___ / __/(_)/ /___ _____ + / // __ \ / ___// // / / // __ // _ \ / /_ / // // _ \ / ___/ + / // / / // /__ / // /_/ // /_/ // __/ / __// // // __/(__ ) + /_//_/ /_/ \___//_/ \__,_/ \__,_/ \___/ /_/ /_//_/ \___//____/ ========================================================================== */ @@ -25,9 +25,9 @@ # include "config.h" #endif -#if PREFER_PORTABLE_SNPRINTF +#if PREFER_PORTABLE_SNPRINTF || NEED_SNPRINTF_ONLY /* in case we use portable sprintf.c, declare function we use, - * som compiler don't scream at us + * so compiler don't scream at us */ # include <stddef.h> @@ -35,27 +35,8 @@ int snprintf(char *str, size_t str_m, const char *fmt, ...); int vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap); -#else - /* this is needed for vsnprintf when using system implementation - * and stdio.h file. When portable snprintf is used, this is not - * needed as vsnprintf is defined manually right up. - */ -# ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 500 -# endif #endif - -/* ========================================================================== - _ __ __ ____ _ __ - (_)____ _____ / /__ __ ____/ /___ / __/(_)/ /___ _____ - / // __ \ / ___// // / / // __ // _ \ / /_ / // // _ \ / ___/ - / // / / // /__ / // /_/ // /_/ // __/ / __// // // __/(__ ) - /_//_/ /_/ \___//_/ \__,_/ \__,_/ \___/ /_/ /_//_/ \___//____/ - - ========================================================================== */ - - #include "embedlog.h" #include "valid.h" diff --git a/src/el-ts.c b/src/el-ts.c index bd187f2..c07ec3a 100644 --- a/src/el-ts.c +++ b/src/el-ts.c @@ -17,6 +17,34 @@ # include "config.h" #endif +/* features definitions, order must from higher posix standard to + * lowest one to avoid redefinitions + */ + +/* clock_gettime() was defined in 199303 issue of posix + * but some systems need posix = 200112 for the feature + */ +#if ENABLE_TIMESTAMP +# if ENABLE_REALTIME || ENABLE_MONOTONIC +# if __FreeBSD__ || __QNX__ || __QNXNTO__ +# define _POSIX_C_SOURCE 200112L +# endif +# endif +#endif + +/* gmtime_r() was defined in posix issue 1, but these systems + * define them in issue 199506 + */ +#if ENABLE_TIMESTAMP +# if __DragonFly__ +# ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 199506L +# endif +# endif +#endif + +/* clock_gettime() was defined in 199303 issue of posix + */ #if ENABLE_TIMESTAMP # if ENABLE_REALTIME || ENABLE_MONOTONIC # ifndef _POSIX_C_SOURCE @@ -25,10 +53,19 @@ # endif #endif +/* gmtime_r() was defined in posix issue 1 + */ +#if ENABLE_TIMESTAMP +# ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 1 +# endif +#endif + #include "el-private.h" #include <time.h> + /* ========================================================================== returns seconds and nanoseconds calculated from clock() function ========================================================================== */ |