From da8d1392c15b56a55f3d98108072c7fa9d73fe79 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 5 Mar 2019 13:20:06 -0800 Subject: Fix the issue for strptime * Define _XOPEN_SOURCE * Exclude usage on windows --- upb/json/parser.rl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'upb/json/parser.rl') diff --git a/upb/json/parser.rl b/upb/json/parser.rl index 70a45cb..2fc5027 100644 --- a/upb/json/parser.rl +++ b/upb/json/parser.rl @@ -19,6 +19,9 @@ ** - handling of keys/escape-sequences/etc that span input buffers. */ +/* Need to define _XOPEN_SOURCE before any include to make strptime work. */ +#define _XOPEN_SOURCE 700 + #include #include #include @@ -27,10 +30,6 @@ #include #include -/* Need to define __USE_XOPEN before including time.h to make strptime work. */ -#ifndef __USE_XOPEN -#define __USE_XOPEN -#endif #include #include "upb/json/parser.h" @@ -1545,12 +1544,19 @@ static bool end_timestamp_base(upb_json_parser *p, const char *ptr) { memcpy(timestamp_buf + UPB_TIMESTAMP_BASE_SIZE, "GMT", 3); timestamp_buf[UPB_TIMESTAMP_BASE_SIZE + 3] = 0; +#if defined __MINGW32__ || defined __MINGW64__ + upb_status_seterrf( + &p->status, "error parsing timestamp: mingw doesn't support strptime"); + upb_env_reporterror(p->env, &p->status); + return false; +#else /* Parse seconds */ if (strptime(timestamp_buf, "%FT%H:%M:%S%Z", &p->tm) == NULL) { upb_status_seterrf(&p->status, "error parsing timestamp: %s", buf); upb_env_reporterror(p->env, &p->status); return false; } +#endif /* Clean up buffer */ multipart_end(p); -- cgit v1.2.3