我正在将一些Unix代码移植到Windows Visual Studio 2010中.我遇到了以下行
I am porting some Unix code into Windows Visual Studio 2010. I have run into the following line
gmtime_r(&now, &tm_time);我发现gmtime_r()是标准的Unix函数,但是我希望找到与Windows等效的函数.我在time.h中找到了很多gmtime函数,但是我很难找到哪一个等效(甚至存在).有人可以指出我正确的方向吗?
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()是gmtime()的线程安全版本. gmtime()的MSVC实现已经是线程安全的,返回的struct tm *已分配在线程本地存储中.
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_s().最接近gmtime_r(),但参数颠倒了;)
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 ;)
更多推荐
Windows与Unix函数gmtime
发布评论