C语言标准库中包括什么?[英] What is included in C Standard library?



我将举一个示例,来自 nonnofollow "> GNU C库文档:


本节描述了用于打开和关闭文件的原始内容 使用文件描述符.开放和创建功能在 标题文件fcntl.h,而关闭在Unistd.h.



可以将unistd.h和fcntl.h视为标准C?据我所知,它们应该成为 posix standard ?

我们可以说C标准库= POSIX函数 + C API吗?我很困惑,因为 wikipedia for C Standard Library 不包括unistd.h文档包括吗?




当涉及实施部分时, gnu c库(glibc)是其中之一.从Wiki页面

glibc提供了单个Unix规范,POSIX(1C,1D和1J)所需的功能,以及ISO C11,ISO C99,Berkeley Unix(BSD)接口所需的某些功能(SVID)和X/OPEN可移植性指南(XPG),第4.2期,XSI(X/Open System接口)符合所有XSI(X/Open System接口)的所有扩展系统以及所有X/OPEN UNIX扩展.






通常,标准C不包括处理低级别文件操作的功能.例如,fopen,fread和fwrite是标准C库的一部分.而posix open,read,write函数不是标准c.



I will give an example from The GNU C Library documentation:

13.1 Opening and Closing Files

This section describes the primitives for opening and closing files using file descriptors. The open and creat functions are declared in the header file fcntl.h, while close is declared in unistd.h.

My question is:

Can unistd.h and fcntl.h be considered as Standard C? As far as I know, they should be part of the Posix standard?

Can we say C Standard Library = Posix functions + C API? I am confused because Wikipedia page for C Standard Library does not include unistd.h but the GNU C Library documentation includes it?


As far as I can see, in C11 standard, there is no unistd.h and fcntl.h. So, strictly speaking, they are not part of the C standard.

When it comes to the implementation part, the GNU C library (glibc) is one of them. From the wiki page

glibc provides the functionality required by the Single UNIX Specification, POSIX (1c, 1d, and 1j) and some of the functionality required by ISO C11, ISO C99, Berkeley Unix (BSD) interfaces, the System V Interface Definition (SVID) and the X/Open Portability Guide (XPG), Issue 4.2, with all extensions common to XSI (X/Open System Interface) compliant systems along with all X/Open UNIX extensions.

In addition, glibc also provides extensions that have been deemed useful or necessary while developing GNU.

So, as a part of the POSIX standard, they are available in glibc.

Reference: Check the C11 standard draft version here.


No, unistd.h, fcntl.h, etc, are not standard C.

In general, standard C doesn't include functions that deal with low level file manipulation. For example, fopen, fread, and fwrite are part of standard C library. While POSIX open, read, write functions are not standard C.