什么是与Unix函数gmtime_r等价的Windows ?

时间:2021-10-07 22:28:01

I am porting some Unix code into Windows Visual Studio 2010. I have run into the following line

我正在将一些Unix代码移植到Windows Visual Studio 2010中。我遇到了下面这一行

gmtime_r(&now, &tm_time);

I found that gmtime_r() is a standard Unix function, but I am hoping to find the Windows equivalent. I found quite a few gmtime functions in time.h, but I am having trouble finding which one is equivalent, if it even exists. Could someone point me in the right direction?

我发现gmtime_r()是一个标准的Unix函数,但我希望找到与Windows等价的函数。我发现了相当多的gmtime函数。h,但是我很难找到哪个是等价的,如果它存在的话。有人能给我指出正确的方向吗?

1 个解决方案

#1


11  

gmtime_r() is the thread-safe version of gmtime(). The MSVC implementation of gmtime() is already thread safe, the returned struct tm* is allocated in thread-local storage.

gmtime_r()是gmtime()的线程安全版本。gmtime()的MSVC实现已经是线程安全的,返回的struct tm*被分配到线程本地存储中。

That doesn't make it immune from trouble if the function is called multiple times on the same thread and the returned pointer is stored. You can use gmtime_s() instead. Closest to gmtime_r() but with the arguments reversed ;)

如果在同一个线程上多次调用该函数,并存储返回的指针,那么它就无法避免麻烦。您可以使用gmtime_s()。与gmtime_r()最接近,但参数颠倒;

#1


11  

gmtime_r() is the thread-safe version of gmtime(). The MSVC implementation of gmtime() is already thread safe, the returned struct tm* is allocated in thread-local storage.

gmtime_r()是gmtime()的线程安全版本。gmtime()的MSVC实现已经是线程安全的,返回的struct tm*被分配到线程本地存储中。

That doesn't make it immune from trouble if the function is called multiple times on the same thread and the returned pointer is stored. You can use gmtime_s() instead. Closest to gmtime_r() but with the arguments reversed ;)

如果在同一个线程上多次调用该函数,并存储返回的指针,那么它就无法避免麻烦。您可以使用gmtime_s()。与gmtime_r()最接近,但参数颠倒;