diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-08-09 14:51:22 +0100 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2015-08-09 14:51:22 +0100 |
commit | da77e9c91c555c66fc669bd9ac7fba60c2b06e8c (patch) | |
tree | f5587142f553fa955e947b34794478d240127770 /javascript/duktape | |
parent | 3b9a91312584dcf223c9d1f6314bc5b2bde868a1 (diff) | |
download | netsurf-da77e9c91c555c66fc669bd9ac7fba60c2b06e8c.tar.gz netsurf-da77e9c91c555c66fc669bd9ac7fba60c2b06e8c.tar.bz2 |
Avoid strptime on platforms where NetSurf knows we don't have a good one
Diffstat (limited to 'javascript/duktape')
-rw-r--r-- | javascript/duktape/duktape.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/javascript/duktape/duktape.c b/javascript/duktape/duktape.c index cb39caffe..b05b95c39 100644 --- a/javascript/duktape/duktape.c +++ b/javascript/duktape/duktape.c @@ -21005,6 +21005,7 @@ DUK_LOCAL duk_int_t duk__get_local_tzoffset(duk_double_t d) { #endif /* DUK_USE_DATE_TZO_WINDOWS */ #ifdef DUK_USE_DATE_PRS_STRPTIME +#ifdef HAVE_STRPTIME DUK_LOCAL duk_bool_t duk__parse_string_strptime(duk_context *ctx, const char *str) { struct tm tm; time_t t; @@ -21037,6 +21038,30 @@ DUK_LOCAL duk_bool_t duk__parse_string_strptime(duk_context *ctx, const char *st return 0; } +#else +#include "utils/config.h" +#include "utils/errors.h" +#include "utils/time.h" +DUK_LOCAL duk_bool_t duk__parse_string_strptime(duk_context *ctx, const char *str) { + time_t t; + char buf[DUK__STRPTIME_BUF_SIZE]; + + /* copy to buffer with spare to avoid Valgrind gripes from strptime */ + DUK_ASSERT(str != NULL); + DUK_MEMZERO(buf, sizeof(buf)); /* valgrind whine without this */ + DUK_SNPRINTF(buf, sizeof(buf), "%s", (const char *) str); + buf[sizeof(buf) - 1] = (char) 0; + + DUK_DDD(DUK_DDDPRINT("parsing: '%s'", (const char *) buf)); + + if (nsc_snptimet(buf, strlen(buf), &t) == NSERROR_OK) { + duk_push_number(ctx, ((duk_double_t) t) * 1000.0); + return 1; + } + + return 0; +} +#endif /* HAVE_STRPTIME */ #endif /* DUK_USE_DATE_PRS_STRPTIME */ #ifdef DUK_USE_DATE_PRS_GETDATE |