Skip to content

Instantly share code, notes, and snippets.

@Winand
Created March 31, 2017 21:28
Show Gist options
  • Save Winand/c41e10ae6bd88c0f5d0a9acab276e8c8 to your computer and use it in GitHub Desktop.
Save Winand/c41e10ae6bd88c0f5d0a9acab276e8c8 to your computer and use it in GitHub Desktop.
....
/*
* Wraps `localtime` functionality for multiple platforms. This
* converts a time value to a time structure in the local timezone.
*
* Returns 0 on success, -1 on failure.
*/
static int get_localtime(NPY_TIME_T *ts, struct tm *tms) {
char *func_name = "<unknown>";
#if defined(_WIN32)
/*#if defined(_MSC_VER) && (_MSC_VER >= 1400)*/
if (localtime_s(tms, ts) != 0) {
func_name = "localtime_s";
goto fail;
}
/*#elif defined(__GNUC__) && defined(NPY_MINGW_USE_CUSTOM_MSVCR)
if (_localtime64_s(tms, ts) != 0) {
func_name = "_localtime64_s";
goto fail;
}
#else
struct tm *tms_tmp;
localtime_r(ts, tms_tmp);
if (tms_tmp == NULL) {
func_name = "localtime";
goto fail;
}
memcpy(tms, tms_tmp, sizeof(struct tm));
#endif
#else
if (localtime_r(ts, tms) == NULL) {
func_name = "localtime_r";
goto fail;
}*/
#endif
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment