Skip to content

Commit

Permalink
strptime: Add a fallback macro for timezone (#2493)
Browse files Browse the repository at this point in the history
According to the UNIX standard:

    The external variable timezone shall be set to the difference,
    in seconds, between Coordinated Universal Time (UTC) and local
    standard time

FreeBSD is incompatible with this standard. In particular, since it
exposes a function symbol `char* timezone(int, int)`, expressions
like `-(timezone)` causes a compile error.

Fix it by adding a compat macro for FreeBSD.

Signed-off-by: Fujimoto Seiji <[email protected]>
  • Loading branch information
fujimotos authored Sep 24, 2020
1 parent 15254d5 commit bee7feb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/flb_strptime.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ static char *_flb_strptime(const char *, const char *, struct tm *, int);
static const u_char *_find_string(const u_char *, int *, const char * const *,
const char * const *, int);

/*
* FreeBSD does not support `timezone` in time.h.
* https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=24590
*/
#ifdef __FreeBSD__
int flb_timezone(void)
{
struct tm tm;
time_t t = 0;
tzset();
localtime_r(&t, &tm);
return -(tm.tm_gmtoff);
}
#define timezone (flb_timezone())
#endif

char *
flb_strptime(const char *buf, const char *fmt, struct tm *tm)
Expand Down

0 comments on commit bee7feb

Please sign in to comment.