From: Wolfgang Stöggl Date: Thu, 28 Mar 2019 14:10:05 +0000 (+0100) Subject: Update strftime.c and use it under MinGW X-Git-Tag: v1.7.2~17 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0cac67347a4ea32e53bd0393f47b658385cdaaf6;p=thirdparty%2Frrdtool-1.x.git Update strftime.c and use it under MinGW - Add %F and %T to strftime.c These format codes are commonly used, part of C99 and used in the test vformatter1 - rrd_graph.c: Include local strftime.h and use strftime_ from strftime.c in case of MinGW or MinGW-w64 builds. - This allows test vformatter1 to pass under MSYS2 (MinGW-w64) --- diff --git a/src/Makefile.am b/src/Makefile.am index 0cae41b9..e1ad246f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -93,8 +93,8 @@ noinst_HEADERS += rrd_rados.h endif if MINGW_W64 -RRD_C_FILES += ../win32/win32-glob.c -noinst_HEADERS += ../win32/win32-glob.h +RRD_C_FILES += ../win32/win32-glob.c strftime.c +noinst_HEADERS += ../win32/win32-glob.h strftime.h endif noinst_LTLIBRARIES = librrdupd.la diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 53d3cae3..2bf53eca 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -10,6 +10,17 @@ #include "rrd_strtod.h" #include "rrd_tool.h" + +/* MinGW and MinGW-w64 use the format codes from msvcrt.dll, + * which does not support e.g. %F, %T or %V. Here we need %V for "Week %V". + * Remark: include of "strftime.h" and use of strftime.c is not required for + * MSVC builds (VS2015 and newer), where strftime format codes are from + * ucrtbase.dll, which supports C99, and therefore %F, %T, %V etc. */ +#if defined(__MINGW32__) +#include "strftime.h" /* This has to be included after rrd_tool.h */ +#define strftime strftime_ +#endif + #include "unused.h" diff --git a/src/strftime.c b/src/strftime.c index 45c39bd0..62a18c2c 100644 --- a/src/strftime.c +++ b/src/strftime.c @@ -10,6 +10,8 @@ * modified 21-Oct-89 by Rob Duff * * modified 08-Dec-04 by Tobi Oetiker (added %V) + * updated 2019-03-28 by Wolfgang Stöggl (added %F and %T) + * **/ #include /* for size_t */ @@ -84,6 +86,7 @@ static void strfmt( * %b abbreviated month name (Jan) * %c standard date and time representation * %d day-of-month (01-31) + * %F equivalent to "%Y-%m-%d" (ISO 8601 date format, C99) * %H hour (24 hour clock) (00-23) * %I hour (12 hour clock) (01-12) * %j day-of-year (001-366) @@ -91,6 +94,7 @@ static void strfmt( * %m month (01-12) * %p local equivalent of AM or PM * %S second (00-59) + * %T equivalent to "%H:%M:%S" (ISO 8601 time format, C99) * %U week-of-year, first day sunday (00-53) * %W week-of-year, first day monday (00-53) * %V ISO 8601 Week number @@ -166,6 +170,10 @@ size_t strftime_( strfmt(r, "%2", t->tm_mday); break; + case 'F': + strfmt(r, "%4-%2-%2", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday); + break; + case 'H': strfmt(r, "%2", t->tm_hour); break; @@ -194,6 +202,10 @@ size_t strftime_( strfmt(r, "%2", t->tm_sec); break; + case 'T': + strfmt(r, "%2:%2:%2", t->tm_hour, t->tm_min, t->tm_sec); + break; + case 'U': w = t->tm_yday / 7; if (t->tm_yday % 7 > t->tm_wday)