From 1a3ee6090d2fdb81bef935929938af20279bc879 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 13 May 2014 16:37:49 +0100 Subject: add strptime compatability --- content/llcache.c | 2 ++ utils/config.h | 8 ++++++++ utils/utils.c | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/content/llcache.c b/content/llcache.c index 653352d3f..5137b2240 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -38,6 +38,8 @@ #include #include +#include "utils/config.h" + #include "utils/corestrings.h" #include "utils/log.h" #include "utils/messages.h" diff --git a/utils/config.h b/utils/config.h index 543bafa1b..12b4b7fc0 100644 --- a/utils/config.h +++ b/utils/config.h @@ -38,6 +38,14 @@ char *strndup(const char *s, size_t n); char *strcasestr(const char *haystack, const char *needle); #endif +#if (defined(riscos) || defined(_WIN32)) +#undef HAVE_STRPTIME +#define strptime nsc_time_strptime +char *nsc_time_strptime(const char *s, const char *format, struct tm *tm); +#else +#define HAVE_STRPTIME +#endif + /* For some reason, UnixLib defines this unconditionally. * Assume we're using UnixLib if building for RISC OS. */ #if ((defined(_GNU_SOURCE) && !defined(__APPLE__)) || defined(riscos)) diff --git a/utils/utils.c b/utils/utils.c index c036ff2f7..9bccf2b90 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -560,4 +560,31 @@ int inet_pton(int af, const char *src, void *dst) #endif +#endif + +#ifndef HAVE_STRPTIME + +/** + * naff strptime implementation for risc os and windows. + * + * @warning only supports %s format + */ +char *nsc_time_strptime(const char *s, const char *format, struct tm *tm) +{ + time_t esecs; + struct tm *gtm; + char *endptr; + + if ((format[0] != '%') || (format[1] != 's')) { + return NULL + } + + esecs = (time_t)strtoll(a, &endptr, 10); + + gtm = gmtime(esecs); + *tm = *gtm; + + return endptr; +} + #endif -- cgit v1.2.3