add thread-safe variant of timestring()
This commit is contained in:
@@ -15,19 +15,19 @@ char *strtok_r(char *s, const char *delim, char **b)
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *timestring(bool local, const char *fmt)
|
||||
string _timestringbuffer;
|
||||
|
||||
const char *timestring(time_t t, bool local, const char *fmt, char *buf)
|
||||
{
|
||||
static string asciitime;
|
||||
time_t t = time(NULL);
|
||||
#ifdef NO_POSIX_R
|
||||
struct tm * timeinfo;
|
||||
struct tm *timeinfo;
|
||||
timeinfo = local ? localtime(&t) : gmtime (&t);
|
||||
#else
|
||||
struct tm *timeinfo, b;
|
||||
timeinfo = local ? localtime_r(&t, &b) : gmtime_r(&t, &b);
|
||||
#endif
|
||||
strftime(asciitime, sizeof(string) - 1, fmt ? fmt : "%Y%m%d_%H.%M.%S", timeinfo); // sortable time for filenames
|
||||
return asciitime;
|
||||
strftime(buf, sizeof(string) - 1, fmt ? fmt : "%Y%m%d_%H.%M.%S", timeinfo); // sortable time for filenames
|
||||
return buf;
|
||||
}
|
||||
|
||||
const char *asctime()
|
||||
|
||||
+3
-1
@@ -934,7 +934,9 @@ struct stream
|
||||
#endif
|
||||
};
|
||||
|
||||
extern const char *timestring(bool local = false, const char *fmt = NULL);
|
||||
extern string _timestringbuffer;
|
||||
extern const char *timestring(time_t t, bool local = false, const char *fmt = NULL, char *buf = _timestringbuffer);
|
||||
inline const char *timestring(bool local = false, const char *fmt = NULL, char *buf = _timestringbuffer) { return timestring(time(NULL), local, fmt, buf); }
|
||||
extern const char *asctime();
|
||||
extern const char *numtime();
|
||||
extern void transformoldentitytypes(int mapversion, uchar &enttype);
|
||||
|
||||
Reference in New Issue
Block a user