[ovs-dev] [PATCH 02/10] timeval: Workaround strftime bug in VS 2013.

Gurucharan Shetty shettyg at nicira.com
Tue May 13 16:03:16 UTC 2014


Visual Studio 2013's behavior is to crash when 0 is passed as second
argument to strftime.

Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
 lib/timeval.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/timeval.c b/lib/timeval.c
index d2a4380..014fd7d 100644
--- a/lib/timeval.c
+++ b/lib/timeval.c
@@ -670,7 +670,17 @@ timeval_dummy_register(void)
                              timeval_warp_cb, NULL);
 }
 
+static size_t
+xstrftime(char *s, size_t max, const char *format, const struct tm *tm)
+{
+    /* Visual Studio 2013's behavior is to crash when 0 is passed as second
+     * argument to strftime. */
+    if (max == 0) {
+        return 0;
+    }
 
+    return strftime(s, max, format, tm);
+}
 
 /* strftime() with an extension for high-resolution timestamps.  Any '#'s in
  * 'format' will be replaced by subseconds, e.g. use "%S.###" to obtain results
@@ -681,7 +691,7 @@ strftime_msec(char *s, size_t max, const char *format,
 {
     size_t n;
 
-    n = strftime(s, max, format, &tm->tm);
+    n = xstrftime(s, max, format, &tm->tm);
     if (n) {
         char decimals[4];
         char *p;
-- 
1.7.9.5




More information about the dev mailing list