Commit dc9462ce authored by rswindell's avatar rswindell
Browse files

Win32 implementations of recursive (thread-safe) std C time functions on Unix:

localtime_r, gmtime_r, ctime_r, and asctime_r.
parent b3b0ce9f
......@@ -234,3 +234,57 @@ char* DLLCALL os_version(char *str)
return(str);
}
#if !defined(__unix__)
/****************************************************************************/
/* Win32 implementations of the recursive (thread-safe) versions of std C */
/* time functions (gmtime, localtime, ctime, and asctime) used in Unix. */
/* The native Win32 versions of these functions are already thread-safe. */
/****************************************************************************/
struct tm* DLLCALL gmtime_r(time_t* t, struct tm* tm)
{
struct tm* tmp = gmtime(t);
if(tmp==NULL)
return(NULL);
*tm = *tmp;
return(tm);
}
struct tm* DLLCALL localtime_r(time_t* t, struct tm* tm)
{
struct tm* tmp = localtime(t);
if(tmp==NULL)
return(NULL);
*tm = *tmp;
return(tm);
}
char* DLLCALL ctime_r(const time_t *t, char *buf, int buflen)
{
char* p = ctime(t);
if(p==NULL)
return(NULL);
strncpy(buf,p,buflen);
return(buf);
}
char* DLLCALL asctime_r(const struct tm *tm, char *buf, int buflen)
{
char* p = asctime(tm);
if(p==NULL)
return(NULL);
strncpy(buf,p,buflen);
return(buf);
}
#endif /* !defined(__unix__) */
......@@ -160,6 +160,19 @@ extern "C" {
#endif
/* Win32 implementations of recursive (thread-safe) std C time functions on Unix */
#if !defined(__unix__)
#include <time.h> /* time_t, etc. */
DLLEXPORT struct tm* DLLCALL gmtime_r(time_t* t, struct tm* tm);
DLLEXPORT struct tm* DLLCALL localtime_r(time_t* t, struct tm* tm);
DLLEXPORT char* DLLCALL ctime_r(const time_t *t, char *buf, int buflen);
DLLEXPORT char* DLLCALL asctime_r(const struct tm *tm, char *buf, int buflen);
#endif
DLLEXPORT int DLLCALL xp_random(int);
DLLEXPORT char* DLLCALL os_version(char *str);
DLLEXPORT char* DLLCALL lastchar(const char* str);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment