Windows与Unix函数gmtime_r等效吗? [英] What is the Windows equivalent of the Unix function gmtime_r?

查看:704
本文介绍了Windows与Unix函数gmtime_r等效吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些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_r等效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆