2011-02-26 27 views

回答

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

或者,你可以運行/usr/includectags -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個源文件,嘗試運行:

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自動化腳本:

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

Download cwhere here

如果安裝desc,您只需鍵入的名字功能使用#define,例如

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

Download desc here

+0

檢查擴展文件是有益的。 :) – John

+0

我想知道爲什麼有2個fcntl.h文件。一個在usr/include中,另一個在usr/include/bits – John

+0

任何人都知道爲什麼? – John