【问题标题】:Why the UNIX time(2) system call is designed like that?为什么 UNIX time(2) 系统调用是这样设计的?
【发布时间】:2013-03-12 03:28:22
【问题描述】:

UNIX time(2) 系统调用time_t time(time_t *t); 以两种方式返回当前时间:返回值和按引用返回。这种冗余的原因是什么?为什么不直接定义它time_t time(void);

【问题讨论】:

标签: unix pass-by-reference system-calls


【解决方案1】:

古代历史,但它可能与两个 16 位 int 值串联模拟 long 的时间有关。否则,没有真正明显的原因。有趣的是,UNIX™ 第 7 版手册文档 time 已过时:

姓名

time, ftime – 获取日期和时间

概要

long time(0)
long time(tloc)
long *tloc;

#include <sys/types.h>
#include <sys/timeb.h>
ftime(tp)
struct timeb *tp;

描述

Time 返回自 1970 年 1 月 1 日 00:00:00 GMT 以来的时间,以秒为单位。 如果 tloc 不为空,则返回值也存储在 tloc 指向的位置。 ftime 条目填充其参数指向的结构,由<sys/timeb.h> 定义:

/*
* Structure returned by ftime system call
*/
struct timeb
{
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};

该结构包含自纪元以来的时间(以秒为单位),更精确的最多为 1000 毫秒 间隔、当地时区(以格林威治向西的时间分钟数衡量)和一个标志,如果 非零,表示夏令时在一年中的适当部分在当地应用。

另见

日期(1)、时间(2)、时间(3)

汇编器

(ftime = 35.)
sys ftime; bufptr

(time = 13.; obsolete call)
sys time
(time since 1970 in r0-r1)

注意“废弃调用”的名称,并注意返回值在两个(16 位)寄存器中,r0r1

【讨论】:

    猜你喜欢
    • 2014-09-28
    • 1970-01-01
    • 2012-04-23
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 2018-06-23
    • 1970-01-01
    • 2022-11-13
    相关资源
    最近更新 更多