为什么它的价值,Beginning Linux Programming的第4版是2007年出版;它的一部分可能有点过时。 (这不是对本书的批评,我没有读过。)
看起来OPEN_MAX已被弃用,至少在Linux系统上。原因似乎是,可以同时打开的最大文件数量不是固定的,因此扩展为整数字面值的宏不是获取该信息的好方法。
还有另外一个宏应该是相似的FOPEN_MAX;我想不出为什么OPEN_MAX和FOPEN_MAX,如果它们都定义了,应该有不同的值。但是由于C语言标准规定了FOPEN_MAX,所以系统没有选择不定义它。 C标准说FOPEN_MAX
扩展为一个整数常量表达式是 执行的保证可以是打开的文件的最小数目的同时
(如果词“最小值”是混乱的,它是一个程序可以同时打开至少的很多文件,提供了保障。)
如果你想文件可以的当前最大数量打开,看看sysconf()的功能;我的系统上,sysconf(_SC_OPEN_MAX)收益1024(该sysconf()手册页是指一个符号OPEN_MAX,这是不是一个数,而是由sysconf()识别的值。而且这不是我的系统上定义。)
我搜索过OPEN_MAX我的Ubuntu系统上(词匹配,所以不包括FOPEN_MAX),并发现了以下(这些显然只是简短摘录):
/usr/include/X11/Xos.h:
# ifdef __GNU__
# define PATH_MAX 4096
# define MAXPATHLEN 4096
# define OPEN_MAX 256 /* We define a reasonable limit. */
# endif
/usr/include/i386-linux-gnu/bits/local_lim.h:
/* The kernel header pollutes the namespace with the NR_OPEN symbol
and defines LINK_MAX although filesystems have different maxima. A
similar thing is true for OPEN_MAX: the limit can be changed at
runtime and therefore the macro must not be defined. Remove this
after including the header if necessary. */
#ifndef NR_OPEN
# define __undef_NR_OPEN
#endif
#ifndef LINK_MAX
# define __undef_LINK_MAX
#endif
#ifndef OPEN_MAX
# define __undef_OPEN_MAX
#endif
#ifndef ARG_MAX
# define __undef_ARG_MAX
#endif
/usr/include/i386-linux-gnu/bits/xopen_lim.h:
/* We do not provide fixed values for
ARG_MAX Maximum length of argument to the `exec' function
including environment data.
ATEXIT_MAX Maximum number of functions that may be registered
with `atexit'.
CHILD_MAX Maximum number of simultaneous processes per real
user ID.
OPEN_MAX Maximum number of files that one process can have open
at anyone time.
PAGESIZE
PAGE_SIZE Size of bytes of a page.
PASS_MAX Maximum number of significant bytes in a password.
We only provide a fixed limit for
IOV_MAX Maximum number of `iovec' structures that one process has
available for use with `readv' or writev'.
if this is indeed fixed by the underlying system.
*/