C stat () and daylight saving time

I have serious problems with the stat () function. I have an application compiled under cygwin ond Windows 7 and the same application compiled with MSVC ++ in Windows 7. The application contains the following code:

struct stat stb;
memset( &stb, 0, sizeof( stb ) );

stat( szPath, &stb );

cout << hex << uppercase << setw(8) << stb.st_mtime << endl;

szPathis the path to the file. The file is not modified in any way by the application. The problem is that I get different results for some files. For instance:

cygwin version: 40216D72
MSVC++ version: 40217B82

The difference is always E10 = 3600 = 1 hour

Using google, I found this and it looks like the same thing I see. Is there any way how to fix this? I can not use any WinAPI calls. The simplest and most reliable solution is what I'm looking for, but if it should be complicated, so be it. Reliability and portability (win + linux) - the most important thing here.

+3
source share
3 answers

To get both reliability and portability here (or in most situations of this kind, where two platforms do different things with what should be “the same” code), you probably need to use some form of target code, for example

#ifdef _MSC_VER
   // do MSVC++-specific code
#else
   // do Linux/Cygwin/generic code
#endif

WinAPI _MSC_VER, MSV++

+2

-, http://support.microsoft.com/kb/190315 , . , , " " " /" .

, dst, , MSVC, .

+1

, , , Windows Linux -. Windows ( DST) . Linux ( , ) GMT ( UTC, ) . , cygwin.

If the Linux system uses hardware with windows, it must be configured to use system clocks such as windows, or mixed up every time windows configure DST.

0
source

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


All Articles