diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-10-11 23:42:20 +0200 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2018-10-11 23:42:20 +0200 |
commit | c16e5cd5473e321036e435117495d17c832f292e (patch) | |
tree | 8e57f544a80e303b241a049bc7e48da0d6e30186 | |
parent | d0f1a546012d41fae63e35a1e1c670beae43d667 (diff) | |
download | embedlog-c16e5cd5473e321036e435117495d17c832f292e.tar.gz embedlog-c16e5cd5473e321036e435117495d17c832f292e.tar.bz2 embedlog-c16e5cd5473e321036e435117495d17c832f292e.zip |
make code more c89 compatible
-rw-r--r-- | src/el-print.c | 36 | ||||
-rw-r--r-- | src/el-private.h | 39 | ||||
-rw-r--r-- | src/el-ts.c | 7 | ||||
-rw-r--r-- | src/snprintf.c | 10 |
4 files changed, 64 insertions, 28 deletions
diff --git a/src/el-print.c b/src/el-print.c index 9db5f6f..b1cc33f 100644 --- a/src/el-print.c +++ b/src/el-print.c @@ -92,15 +92,15 @@ static const char char_level[8] = { 'f', 'a', 'c', 'e', 'w', 'n', 'i', 'd' }; static const char *color[] = { - "\e[91m", /* fatal light red */ - "\e[31m", /* alert red */ - "\e[95m", /* critical light magenta */ - "\e[35m", /* error magenta */ - "\e[93m", /* warning light yellow */ - "\e[92m", /* notice light green */ - "\e[32m", /* information green */ - "\e[34m", /* debug blue */ - "\e[0m" /* remove all formats */ + "\033[91m", /* fatal light red */ + "\033[31m", /* alert red */ + "\033[95m", /* critical light magenta */ + "\033[35m", /* error magenta */ + "\033[93m", /* warning light yellow */ + "\033[92m", /* notice light green */ + "\033[32m", /* information green */ + "\033[34m", /* debug blue */ + "\033[0m" /* remove all formats */ }; #else @@ -113,15 +113,15 @@ static const char *color[] = static const char *color[] = { - "\e[31m", /* fatal red */ - "\e[31m", /* alert red */ - "\e[35m", /* critical magenta */ - "\e[35m", /* error magenta */ - "\e[33m", /* warning yellow */ - "\e[32m", /* notice green */ - "\e[32m", /* information green */ - "\e[34m", /* debug blue */ - "\e[0m" /* remove all formats */ + "\033[31m", /* fatal red */ + "\033[31m", /* alert red */ + "\033[35m", /* critical magenta */ + "\033[35m", /* error magenta */ + "\033[33m", /* warning yellow */ + "\033[32m", /* notice green */ + "\033[32m", /* information green */ + "\033[34m", /* debug blue */ + "\033[0m" /* remove all formats */ }; #endif /* COLORS_EXTENDED */ diff --git a/src/el-private.h b/src/el-private.h index e81d61c..3b3aa66 100644 --- a/src/el-private.h +++ b/src/el-private.h @@ -10,6 +10,41 @@ #ifndef EL_PRIVATE_H #define EL_PRIVATE_H 1 + +/* ========================================================================== + ____ __ __ __ + / __/___ ____ _ / /_ __ __ _____ ___ / /_ ___ _____ / /_ + / /_ / _ \ / __ `// __// / / // ___// _ \ / __// _ \ / ___// __/ + / __// __// /_/ // /_ / /_/ // / / __/ / /_ / __/(__ )/ /_ + /_/ \___/ \__,_/ \__/ \__,_//_/ \___/ \__/ \___//____/ \__/ + + ========================================================================== */ + + +#if HAVE_CONFIG_H +# include "config.h" +#endif + +#if PREFER_PORTABLE_SNPRINTF +# include <stddef.h> +# include <stdarg.h> + 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. + */ +# define _XOPEN_SOURCE 500 +#endif + +#if ENABLE_TIMESTAMP +# if ENABLE_REALTIME || ENABLE_MONOTONIC +# define _POSIX_C_SOURCE 199309L +# endif +#endif + + /* ========================================================================== _ __ __ ____ _ __ (_)____ _____ / /__ __ ____/ /___ / __/(_)/ /___ _____ @@ -19,9 +54,6 @@ ========================================================================== */ -#if HAVE_CONFIG_H -# include "config.h" -#endif #include "embedlog.h" #include "valid.h" @@ -32,6 +64,7 @@ #include <limits.h> + /* ========================================================================== __ __ __ ____ _ / /____ / /_ ____ _ / / _ __ ____ _ _____ _____ diff --git a/src/el-ts.c b/src/el-ts.c index 503c437..a9f4af7 100644 --- a/src/el-ts.c +++ b/src/el-ts.c @@ -3,7 +3,6 @@ Author: Michał Łyszczek <michal.lyszczek@bofc.pl> ========================================================================== */ - /* ========================================================================== _ __ __ ____ _ __ (_)____ _____ / /__ __ ____/ /___ / __/(_)/ /___ _____ @@ -22,7 +21,6 @@ #include <time.h> - /* ========================================================================== returns seconds and nanoseconds calculated from clock() function ========================================================================== */ @@ -295,6 +293,11 @@ size_t el_timestamp } #else /* ENABLE_TIMESTAMP */ + + (void)options; + (void)b; + (void)binary; return 0; + #endif /* ENABLE_TIMESTAMP */ } diff --git a/src/snprintf.c b/src/snprintf.c index ae36fff..3c6d079 100644 --- a/src/snprintf.c +++ b/src/snprintf.c @@ -950,7 +950,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { if (n > 0) { if (str_l < str_m) { size_t avail = str_m-str_l; - fast_memset(str+str_l, (zero_padding?'0':' '), (n>avail?avail:n)); + fast_memset(str+str_l, (zero_padding?'0':' '), ((size_t)n>avail?avail:n)); } str_l += n; } @@ -967,7 +967,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { if (n > 0) { if (str_l < str_m) { size_t avail = str_m-str_l; - fast_memcpy(str+str_l, str_arg, (n>avail?avail:n)); + fast_memcpy(str+str_l, str_arg, ((size_t)n>avail?avail:n)); } str_l += n; } @@ -976,7 +976,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { if (n > 0) { if (str_l < str_m) { size_t avail = str_m-str_l; - fast_memset(str+str_l, '0', (n>avail?avail:n)); + fast_memset(str+str_l, '0', ((size_t)n>avail?avail:n)); } str_l += n; } @@ -988,7 +988,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { if (str_l < str_m) { size_t avail = str_m-str_l; fast_memcpy(str+str_l, str_arg+zero_padding_insertion_ind, - (n>avail?avail:n)); + ((size_t)n>avail?avail:n)); } str_l += n; } @@ -999,7 +999,7 @@ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) { if (n > 0) { if (str_l < str_m) { size_t avail = str_m-str_l; - fast_memset(str+str_l, ' ', (n>avail?avail:n)); + fast_memset(str+str_l, ' ', ((size_t)n>avail?avail:n)); } str_l += n; } |