Support for localtime_r on MinGW

I am working on a multi-threaded C ++ project Win32, and I would like to use one of the localtime_* alternative streams localtime() .

Unfortunately, I have to use the MinGW compiler, and localtime_s cannot be used outside of Microsoft.

The problem is that neither localtime_r works: the associated code snippet

 #include <ctime> ... string getCurrentTime() { time_t t; time(&t); struct tm timeinfo; //localtime_s(&timeinfo, &t); localtime_r(&t, &timeinfo); char buf[128]; strftime(buf, 128, "%d-%m-%Y %X", &timeinfo); return string(buf); } ... 

This is the compiler output:

 error: 'localtime_r' was not declared in this scope 

Does MinGW support localtime_r ?

If not, is there a thread-safe alternative? (excluding boost / QT / etc which I cannot use).


EDIT: this is the <time.h> provided by my MinGW installation: http://pastebin.com/0CYBfMzg

+6
source share
2 answers

Does MinGW support localtime_r?

No.

If not, is there a thread-safe alternative? (excluding boost / QT / etc which I cannot use)

mingw will use the built-in localtime function in windows, which is thread safe. (But this is not reentrant, so stay tuned).

+6
source

Try using the localtime function instead of localtime_r :

 time_t t; struct tm *timeinfo; time(&t); timeinfo = localtime(&t); printf ("%s", asctime(timeinfo)); 
-2
source

Source: https://habr.com/ru/post/952890/


All Articles