1

我一直在浏览头文件,但找不到任何带有状态标志定义的文件(如 O_RDONLY)。

谢谢,约翰

4

1 回答 1

2

概括

如果你在 Linux 上,它应该在/usr/include/bits/fcntl.h.

#define O_RDONLY 00

您可以使用rgrep、 或ctagsVim、 或cpp、 或找到它cwhere


rgrep

最简单的方法是使用rgrep,也就是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

或者,您可以运行然后运行ctags -R​​./usr/includevim -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

表示O_WRONLY如果/usr/include/bits/fcntl.h您包含man fcntl.


哪里

我有一个脚本调用cwhere来自动运行cpp

$ cwhere O_WRONLY sys/types.h sys/stat.h fcntl.h
/usr/include/bits/fcntl.h: #define O_WRONLY 01

在此处下载 c

如果desc已安装,您只需键入使用它的函数的名称#define,例如

$ cwhere O_WRONLY 'fcntl()'
/usr/include/bits/fcntl.h: #define O_WRONLY 01

在此处下载说明

于 2011-02-26T06:25:21.710 回答