Skip to content
Snippets Groups Projects
Commit c43eef30 authored by rswindell's avatar rswindell
Browse files

Define a MSFT macro for the GLIBC/BSD timegm() function and a sane_timegm()

equivalent to sane_mktime() for broken-down date/time's in UTC.
parent 353a13ab
Branches
Tags
No related merge requests found
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -64,6 +64,18 @@ time_t DLLCALL sane_mktime(struct tm* tm)
return mktime(tm);
}
/* Compensates for struct tm "weirdness" */
time_t DLLCALL sane_timegm(struct tm* tm)
{
if(tm->tm_year>=1900)
tm->tm_year-=1900;
if(tm->tm_mon) /* Month is zero-based */
tm->tm_mon--;
tm->tm_isdst=0; /* Don't adjust for DST */
return timegm(tm);
}
time32_t DLLCALL time32(time32_t* tp)
{
time_t t;
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -47,8 +47,9 @@ extern "C" {
/* Return difference (in seconds) in time() result from standard (0 on success) */
DLLEXPORT time_t DLLCALL checktime(void);
/* Implementation of mktime() that handles common tm element conversions for you */
/* Implementation of mktime()/timegm() that handles common tm element conversions for you */
DLLEXPORT time_t DLLCALL sane_mktime(struct tm*);
DLLEXPORT time_t DLLCALL sane_timegm(struct tm*);
/* Legacy (32-bit time_t) versions of time() and mktime() */
DLLEXPORT time32_t DLLCALL time32(time32_t* tp);
......@@ -71,6 +72,11 @@ DLLEXPORT struct tm* DLLCALL localtime32(const time32_t* t, struct tm* tm);
#endif
/* Microsoft's equivalent of GLIBC/BSD timegm() */
#ifdef _MSC_VER
#define timegm _mkgmtime
#endif
/***********************************/
/* Borland DOS date/time functions */
/***********************************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment