当前位置:网站首页>localtime居然不可重入,踩坑了
localtime居然不可重入,踩坑了
2022-07-01 12:33:00 【涛歌依旧】
最近踩坑了,全都拜localtime所赐,因为localtime居然不可重入:
[email protected]:~$ man localtime
CTIME(3) Linux Programmer's Manual CTIME(3)
NAME
asctime, ctime, gmtime, localtime, mktime, asctime_r, ctime_r, gmtime_r, localtime_r - transform date and time to broken-
down time or ASCII
SYNOPSIS
#include <time.h>
char *asctime(const struct tm *tm);
char *asctime_r(const struct tm *tm, char *buf);
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
struct tm *gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);
time_t mktime(struct tm *tm);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
asctime_r(), ctime_r(), gmtime_r(), localtime_r():
_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE || _POSIX_SOURCE
DESCRIPTION
The ctime(), gmtime() and localtime() functions all take an argument of data type time_t, which represents calendar time.
When interpreted as an absolute time value, it represents the number of seconds elapsed since the Epoch, 1970-01-01
00:00:00 +0000 (UTC).
The asctime() and mktime() functions both take an argument representing broken-down time, which is a representation sepa[m
rated into year, month, day, and so on.
Broken-down time is stored in the structure tm, which is defined in <time.h> as follows:
struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};
真的需要小心一点。
边栏推荐
- Chained storage of queues
- 【20211129】Jupyter Notebook遠程服務器配置
- [Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4
- Interpretation of hard threshold function [easy to understand]
- A hole in solder paste
- 【脑洞大开】《西潮》及《走向世界丛书》
- 【语音信号处理】3语音信号可视化——prosody
- 腾讯黎巍:深耕“监管科技”,护航数字经济行稳致远
- 腾讯安全联合毕马威发布监管科技白皮书,解析“3+3”热点应用场景
猜你喜欢
Joint Time-Frequency and Time Domain Learning for Speech Enhancement
Onenet Internet of things platform - create mqtts products and devices
【20220605】文献翻译——虚拟现实中的可视化:一个系统的回顾
【20211129】Jupyter Notebook遠程服務器配置
[speech signal processing] 3 speech signal visualization -- prosody
How to use opcache, an optimization acceleration component of PHP
【20211129】Jupyter Notebook远程服务器配置
redis探索之缓存击穿、缓存雪崩、缓存穿透
双链表有关操作
VS Code 设置单击打开新文件窗口,不覆盖前一个窗口
随机推荐
使用BurpSuite对app抓包教程
VS Code 设置单击打开新文件窗口,不覆盖前一个窗口
Teach you to complete the actual battle of image classification hand in hand -- Image Recognition Based on convolutional neural network
手机便签应用
Consolidate -c operator
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
leetcode 406. Queue reconstruction by height
Mysql database knowledge collation
redis探索之缓存击穿、缓存雪崩、缓存穿透
C serialization simple experiment
(mixed version 1) multiple TXT text to one table
How to use opcache, an optimization acceleration component of PHP
Exploration and practice of inress in kubernetes
Relationship between accuracy factor (DOP) and covariance in GPS data (reference link)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6
[20211129] configuration du serveur distant du carnet de notes jupyter
CPI tutorial - asynchronous interface creation and use
[20211129] jupyter notebook remote server configuration
[20220605] Literature Translation -- visualization in virtual reality: a systematic review
华为面试题: 招聘