replace non-thread-safe functions

replace all uses of strtok, localtime, gmtime and readdir

on platforms without safe versions, use homebrew or unsafe...
This commit is contained in:
ac-stef
2016-02-28 23:14:47 +01:00
parent 98d01d1f34
commit 32ffd3a4cd
11 changed files with 60 additions and 38 deletions
+18
View File
@@ -2,12 +2,30 @@
#include "cube.h"
#ifdef NO_POSIX_R
char *strtok_r(char *s, const char *delim, char **b)
{
if(s) *b = s;
*b += strspn(*b, delim);
if(!**b) return NULL;
s = *b;
*b += strcspn(s, delim);
if(**b) *(*b)++ = '\0';
return s;
}
#endif
const char *timestring(bool local, const char *fmt)
{
static string asciitime;
time_t t = time(NULL);
#ifdef NO_POSIX_R
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;
}