fcntl.h不包含所有状态标志常量

我一直在浏览头文件,但我找不到任何带状态标志定义的文件(如O_RDONLY)。 谢谢, 约翰     
已邀请:
摘要 如果你在Linux上,那应该是
/usr/include/bits/fcntl.h
#define O_RDONLY 00
您可以使用
rgrep
,或
ctags
Vim
,或
cpp
cwhere
找到它。 rgrep 最简单的方法是使用
rgrep
,a.k.a。
grep -R
$ rgrep O_WRONLY .
./X11/Xw32defs.h:#  define O_WRONLY    _O_WRONLY
./linux/fs.h: * to O_WRONLY and O_RDWR via the strange trick in __dentry_open()
./linux/smbno.h:#define SMB_O_WRONLY    0x0001
./asm-generic/fcntl.h:#define O_WRONLY  00000001
./security/_pam_macros.h:    if ((fd = open(_PAM_LOGFILE, O_WRONLY|O_NOFOLLOW|O_APPEND)) != -1) {
./security/_pam_macros.h:    if ((fd = open(_PAM_LOGFILE, O_WRONLY|O_APPEND)) != -1) {
./security/_pam_macros.h:    if ((fd = open(_PAM_LOGFILE, O_WRONLY|O_NOFOLLOW|O_APPEND)) != -1) {
./security/_pam_macros.h:    if ((fd = open(_PAM_LOGFILE, O_WRONLY|O_APPEND)) != -1) {
./bits/fcntl.h:#define O_WRONLY      01
CTAGS 或者,你可以在
/usr/include
中运行
ctags -R
然后运行
vim -t O_WRONLY
。 或者,更好一点,但更多的打字:
find . /usr/include -name "*.h" | 
ctags -f - -L - |
grep "^O_WRONLY   " |
cut -d "    " -f 1,2,3 |
sed -e 's# /^#    #;s#$/;"$##'
CPP 我找到的最好的方法是使用
cpp
。 假设您有一个名为YOUR_SOURCE_FILE的源文件,其中包含必要的
#include
s,请尝试运行:
cpp -dD YOUR_SOURCE_FILE | less
然后搜索你的
#define
,例如
/O_WRONLY
,然后向上滚动以找到它上面的第一个文件名。在这种情况下:
# 27 "/usr/include/bits/fcntl.h" 2 3 4
表示如果包含
man fcntl
中提到的三个头文件,则从
/usr/include/bits/fcntl.h
中拾取
O_WRONLY
。 cwhere 我有一个名为
cwhere
的脚本来自动运行
cpp
$ cwhere O_WRONLY sys/types.h sys/stat.h fcntl.h
/usr/include/bits/fcntl.h: #define O_WRONLY 01
在这里下载cwhere 如果安装了
desc
,您只需输入使用该功能的功能的名称,例如:
$ cwhere O_WRONLY 'fcntl()'
/usr/include/bits/fcntl.h: #define O_WRONLY 01
在这里下载desc     

要回复问题请先登录注册