Added timegm() for Android in platform_unix.c
authorEdouard Tisserant
Tue, 11 Oct 2016 17:58:15 +0200
changeset 12671b7df2133aab
parent 1266 dd1f08543df2
child 1268 10397798d2b3
Added timegm() for Android in platform_unix.c
src/platform_unix.c
src/platform_unix.h
     1.1 --- a/src/platform_unix.c	Tue Oct 11 17:22:27 2016 +0200
     1.2 +++ b/src/platform_unix.c	Tue Oct 11 17:58:15 2016 +0200
     1.3 @@ -1,5 +1,11 @@
     1.4  #define _POSIX_C_SOURCE 200809L
     1.5  
     1.6 +#ifdef ANDROID
     1.7 +#ifndef __LP64__ 
     1.8 +#include <time64.h>
     1.9 +#endif
    1.10 +#endif
    1.11 +
    1.12  #include <time.h>
    1.13  #include <string.h>
    1.14  #include <stdlib.h>
    1.15 @@ -25,6 +31,19 @@
    1.16  
    1.17  #ifdef ANDROID
    1.18  #include <uuid.h>
    1.19 +
    1.20 +/* FIXME : timegm will miss when linking for x86_64 on android, when supported */
    1.21 +#ifndef __LP64__ 
    1.22 +time_t timegm(struct tm* const t) {
    1.23 +    static const time_t kTimeMax = ~(1L << (sizeof(time_t) * CHAR_BIT - 1));
    1.24 +    static const time_t kTimeMin = (1L << (sizeof(time_t) * CHAR_BIT - 1));
    1.25 +    time64_t result = timegm64(t);
    1.26 +    if (result < kTimeMin || result > kTimeMax)
    1.27 +        return -1;
    1.28 +    return result;
    1.29 +}
    1.30 +#endif
    1.31 +
    1.32  char *stpncpy(char *dst, const char *src, size_t n)
    1.33  {
    1.34      if (n != 0) {
     2.1 --- a/src/platform_unix.h	Tue Oct 11 17:22:27 2016 +0200
     2.2 +++ b/src/platform_unix.h	Tue Oct 11 17:58:15 2016 +0200
     2.3 @@ -25,6 +25,8 @@
     2.4  
     2.5  #ifdef ANDROID
     2.6  
     2.7 +time_t timegm(struct tm* const t);
     2.8 +
     2.9  char *stpncpy(char *, const char *, size_t);
    2.10  char *stpcpy(char *, const char *);
    2.11