Windows与Unix函数gmtime

编程入门 行业动态 更新时间:2024-10-26 01:18:38
本文介绍了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

本文发布于:2023-10-07 15:40:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   Windows   Unix   gmtime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!