1, 三個標準
1.1, ISO C標準由ISO/IEC維護開發
最新版本是C11,共有29個標準頭文件。
1.2, POSIX是一系列由IEEE制定的標準
POSIX包括ISO C標準庫函數。
POSIX標準的1988版本是IEEE 1003.1-1988,經過修改后作為IEEE Std.1003.1-1990提交ISO,成為國際標準ISO/IEC 9945-1:1990,該標準通常稱為POSIX.1。
當前最新版本是POSIX.1-2008,由IEEE和Open Group共同開發。
1.3, SUS是POSIX的超集,其系統接口全集稱為XSI
The core specifications of the SUS are developed and maintained by the Austin Group, which is a joint working group of IEEE, ISO JTC 1 SC22 and The Open Group.
只有遵循XSI的實現才能稱為UNIX系統。
當前的最新版本是SUSv4。
1.4, 找到一些網址
C11
http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853
POSIX.1-2008
http://pubs.opengroup.org/onlinepubs/9699919799/
https://standards.ieee.org/findstds/standard/1003.1-2008.html
SUSv4
https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?publicationid=12310
https://en.wikipedia.org/wiki/Single_UNIX_Specification#cite_note-11
2, 限制
2.1 兩種限制
編譯時限制和運行時限制。
編譯時限制通過頭文件獲取;
不與文件或目錄相關的運行時限制通過sysconf函數獲取;
與文件或目錄相關的運行時限制通過pathconf和fpathconf函數獲取。
2.2 ISO C限制
都是編譯時限制,主要定義在<limits.h>里面。
http://en.cppreference.com/w/c/types/limits
2.3 POSIX限制和XSI限制
書中列出的都是實現中必須支持的各種最小值,特定系統實際支持的限制值需要通過頭文件或者三個函數函數獲取。
三個函數的name參數是限制名前面加_SC_或者_PC_前綴得到。
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
2.4 書中代碼
3, 選項
3.1, 選項確定方式
編譯時選項定義在<unistd.h>中;
與文件或目錄無關的選項用sysconf確定;
與文件或目錄有關的選項用pathconf或者fpathconf確定;
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
3.2, 選項確定流程
如果符號常量未定義,
對_POSIX前綴的選項,將_POSIX前綴替換為_SC或_PC前綴,
對_XOPEN前綴的選項,在_XOPEN前面加上_SC或_PC前綴,
然后調用sysconf, pathconf或fpathconf函數。
如果符號常量已經定義,則有三種可能:
值為-1,不支持相應的選項;
值大于0,支持相應的選項;
值為0,需調用函數確定選項是否支持。
注:某些系統可能出現定義了符號常量,但沒有定義值的情況。
3.4, 代碼示例
先占坑。
4, 功能測試宏
Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled.
NOTE: In order to be effective, a feature test macro must be defined before including any header files. This can be done either in the compilation command (cc -DMACRO=value) or by defining the macro within the source code before including any headers.
see man page feature_test_macros(7).
1.1, ISO C標準由ISO/IEC維護開發
最新版本是C11,共有29個標準頭文件。
1.2, POSIX是一系列由IEEE制定的標準
POSIX包括ISO C標準庫函數。
POSIX標準的1988版本是IEEE 1003.1-1988,經過修改后作為IEEE Std.1003.1-1990提交ISO,成為國際標準ISO/IEC 9945-1:1990,該標準通常稱為POSIX.1。
當前最新版本是POSIX.1-2008,由IEEE和Open Group共同開發。
1.3, SUS是POSIX的超集,其系統接口全集稱為XSI
The core specifications of the SUS are developed and maintained by the Austin Group, which is a joint working group of IEEE, ISO JTC 1 SC22 and The Open Group.
只有遵循XSI的實現才能稱為UNIX系統。
當前的最新版本是SUSv4。
1.4, 找到一些網址
C11
http://www.iso.org/iso/home/store/catalogue_tc/catalogue_detail.htm?csnumber=57853
POSIX.1-2008
http://pubs.opengroup.org/onlinepubs/9699919799/
https://standards.ieee.org/findstds/standard/1003.1-2008.html
SUSv4
https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?publicationid=12310
https://en.wikipedia.org/wiki/Single_UNIX_Specification#cite_note-11
2, 限制
2.1 兩種限制
編譯時限制和運行時限制。
編譯時限制通過頭文件獲取;
不與文件或目錄相關的運行時限制通過sysconf函數獲取;
與文件或目錄相關的運行時限制通過pathconf和fpathconf函數獲取。
2.2 ISO C限制
都是編譯時限制,主要定義在<limits.h>里面。
http://en.cppreference.com/w/c/types/limits
2.3 POSIX限制和XSI限制
書中列出的都是實現中必須支持的各種最小值,特定系統實際支持的限制值需要通過頭文件或者三個函數函數獲取。
三個函數的name參數是限制名前面加_SC_或者_PC_前綴得到。
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html
2.4 書中代碼
/*
* If name is invalid, -1 is returned, and errno is set to EINVAL.
* Otherwise, the value returned is the value of the system resource and errno is not changed.
* In the case of options, a positive value is returned if a queried option is available, and -1 if it is not.
* In the case of limits, -1 means that there is no definite limit.
*/
#include "apue.h"
#include <errno.h>
#include <limits.h>
#ifdef OPEN_MAX
static long openmax = OPEN_MAX;
#else
static long openmax = 0;
#endif
/*
* If OPEN_MAX is indeterminate, we're not
* guaranteed that this is adequate
*/
#define OPEN_MAX_GUESS 256
long
open_max(void)
{
if (openmax == 0) { /* first time through */
errno = 0;
if ((openmax = sysconf(_SC_OPEN_MAX)) < 0) {
if (errno == 0)
openmax = OPEN_MAX_GUESS; /* it's indeterminate */
else
err_sys("sysconf error for _SC_OPEN_MAX";)
}
}
return(openmax);
}
* If name is invalid, -1 is returned, and errno is set to EINVAL.
* Otherwise, the value returned is the value of the system resource and errno is not changed.
* In the case of options, a positive value is returned if a queried option is available, and -1 if it is not.
* In the case of limits, -1 means that there is no definite limit.
*/
#include "apue.h"
#include <errno.h>
#include <limits.h>
#ifdef OPEN_MAX
static long openmax = OPEN_MAX;
#else
static long openmax = 0;
#endif
/*
* If OPEN_MAX is indeterminate, we're not
* guaranteed that this is adequate
*/
#define OPEN_MAX_GUESS 256
long
open_max(void)
{
if (openmax == 0) { /* first time through */
errno = 0;
if ((openmax = sysconf(_SC_OPEN_MAX)) < 0) {
if (errno == 0)
openmax = OPEN_MAX_GUESS; /* it's indeterminate */
else
err_sys("sysconf error for _SC_OPEN_MAX";)
}
}
return(openmax);
}
3, 選項
3.1, 選項確定方式
編譯時選項定義在<unistd.h>中;
與文件或目錄無關的選項用sysconf確定;
與文件或目錄有關的選項用pathconf或者fpathconf確定;
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html
3.2, 選項確定流程
如果符號常量未定義,
對_POSIX前綴的選項,將_POSIX前綴替換為_SC或_PC前綴,
對_XOPEN前綴的選項,在_XOPEN前面加上_SC或_PC前綴,
然后調用sysconf, pathconf或fpathconf函數。
如果符號常量已經定義,則有三種可能:
值為-1,不支持相應的選項;
值大于0,支持相應的選項;
值為0,需調用函數確定選項是否支持。
注:某些系統可能出現定義了符號常量,但沒有定義值的情況。
3.4, 代碼示例
先占坑。
4, 功能測試宏
Feature test macros allow the programmer to control the definitions that are exposed by system header files when a program is compiled.
NOTE: In order to be effective, a feature test macro must be defined before including any header files. This can be done either in the compilation command (cc -DMACRO=value) or by defining the macro within the source code before including any headers.
see man page feature_test_macros(7).