Mingw time functions

I am trying to implement the code indicated on this page

http://msdn.microsoft.com/en-us/library/windows/desktop/aa366062%28v=vs.85%29.aspx

I use mingw (gcc) to compile this. But the following lines cannot be compiled. I have included "time.h". I searched but cannot find this _localtime31_s or its equivalent in gcc.

error = _localtime32_s(&newtime, (__time32_t*) &pAdapter->LeaseObtained); error = asctime_s(buffer, 32, &newtime); 

Where are the time functions here? Thanks

0
source share
2 answers

The localtime_s and asctime_s are extensions for Microsoft provided by (some versions of) the MS runtime library. This is provided by the MS header files. Since these are MS copyrights and are not permitted for free distribution, mingw provides its own versions of headers - and they probably do not contain these extensions (they certainly did not help when I used mingw on my local machine - my main machine in these Linux days working ...).

Note that casting the time value to time32_t * is probably a bad idea - it will almost certainly bite you if you ever compile your code with time_t , which is not a 32-bit value.

The localtime_r function is a semi-standard version that can be used instead of localtime_s (you need to pay attention to 32 versus 64-bit time values). You can also use localtime (besides having to disable MS, the annoying "this function is unsafe, use ..._s instead" - I DO NOT REALLY want to convert 100 uses of strcpy to strcpy_s, which work fine, because it has already been tested elsewhere )

Similarly, there is asctime_r , which provides a re-version.

You could perhaps also add prototypes for these functions to your file somewhere, I believe that if you are compiling for Windows, solve the problem:

Link to MS function documentation: localtime_s and asctime_s .

+1
source

MinGW-w64 provides the ability to enable secure CRT features. Please note that there are compatibility issues with Windows XP, where msvcrt.dll does not contain these functions, and your application will not work in this environment.

They are standardized in C11 Annex K , which is optional and may not be available in C11-compatible systems.

+1
source

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


All Articles