POSIX

共 7 篇文章。

errno 的实现

• Kernel

IEEE Std 1003.1-2024 (POSIX) 中对于 errno 的定义如下:

The lvalue to which the macro errno expands is used by many functions to return error values.

在更早期的 POSIX(Issue 5 及以前)以及 X/Open 文档中,曾经规定 errno 是一个外部变量(extern int errno),但这使得 errno 无法实现线程安全,因为所有线程共享同一个全局变量,一个线程的系统调用返回的错误码会覆盖另一个线程的值。因此,POSIX Issue 6(即 SUSv3 / IEEE Std 1003.1-2001)将这一要求删除,改为现在的定义:只要求 errno 是一个展开为 int 类型的可修改左值(modifiable lvalue)的宏。这为实现者提供了足够的自由度,以支持线程安全的 errno。

ISO C 标准在 C90/C89 时期已经不再要求 errno 是外部变量。

阅读全文… ( 本文约 1554 字,阅读大致需要 4 分钟 )

Moving toward a standarized qsort_r(3)

• Development

History of qsort_r(3)

First introduced in Research Unix V3 and eventually standardized as part of C Standard Library as of ANSI/ISO C89, qsort(3) provided an abstract interface where programmers can perform sort operation over an array of objects, by supplying a pointer to that array, the total number of the member objects, the size of individual member object,as well as a compare function. The compare function is expected to take two parameters, both pointers to a member object, and it shall return a negative number, 0, or a positive number, if the first object is considered smaller, equal, or greater respectively.

阅读全文… ( 本文约 2240 字,阅读大致需要 11 分钟 )

关于闰秒

• Kernel

phk 老大如此 吐槽:

来自 X (Twitter)

背景

关于时间,A core 几年前写过一个 时间是什么? 的系列: 序言 续一 续二 续三。

为了兼顾天文观测获得的时间 UT1(更符合普通人的需要)和由铯-133原子震荡获得的时间 TAI (更稳定),将两者综合一下就获得了协调世界时 UTC。UTC 和 UT1 之间的差距永远保持在 1 秒以内。UTC 中的一秒和 TAI 相同,但 UTC 和 UT1 保持最多一秒的差距,这是通过 IERS 在 UTC 事件中人为插入或减少闰秒这样的人为调整来实现的。从1972年这套系统投入运营到今天为止,总共插入了35个闰秒(2015年6月30日还将再插入一个闰秒)。

闰秒只在每年的6月30日和12月31日的UTC时间 23:59:59 之后插入,表示为当天的 23:59:60。

阅读全文… ( 本文约 1446 字,阅读大致需要 3 分钟 )

龌龊的dirname(3)定义

• Development

在POSIX中提到,这个API不仅可以修改输入参数,而且可以返回一个静态存储的指针,说白了,你不能指望某个平台上它是线程安全的,也不能指望它不会修改你发给它的数据……

参与评论

Linux threading bug

• Kernel

A collegue of mine has reported a FreeBSD “bug” that, when the main thread exits, the whole process is terminated. He complained that pthread_detach() would not cause the thread to run without the main thread, while Linux did.

With some experiments we have figured out that this is actually a Linux bug, which violates POSIX. Interestingly, Solaris has the same behavior that FreeBSD have.

The POSIX pthread_create() said:

Note that the thread in which main() was originally invokeddiffers from this. When it returns from main(), the effectshall be as if there was an implicit call to exit() usingthe return value of main() as the exit status."

阅读全文… ( 本文约 161 字,阅读大致需要 1 分钟 )

Microsoft SFU: An impressive product

• Kernel

Microsoft has recently released SFU 3.5 for free download. This is an amazing product because it also enables running Unix programs under Windows natively.

阅读全文… ( 本文约 115 字,阅读大致需要 1 分钟 )