<div class="motadou_spec_line">0 -- 定位errno.h的位置</div>
我想看看errno.h檔案的內容,咋知道它在哪裡呢?<br />
<br />
<strong>第一個方法:全盤搜尋errno.h。命令:find / -name errno.h</strong>
<pre class="pre_style">find / -name errno.h
/usr/include/asm/errno.h
/usr/include/asm-generic/errno.h
/usr/include/bits/errno.h
/usr/include/errno.h
/usr/include/linux/errno.h
/usr/include/sys/errno.h
</pre>
發現能夠搜到errno.h,當不知道gcc具體使用的那個標頭檔,需要進一步判斷才能確認。
<br />
<br />
<strong>第二個方法:查看gcc編譯器時標頭檔的搜尋路徑,來決定errno.h所處的目錄。命令:gcc -v test.cpp</strong>
<pre class="pre_style">gcc version 4.1.0 (SUSE Linux)
/usr/lib/gcc/i586-suse-linux/4.1.0/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -auxbase test -version -o /tmp/ccXnnD7Y.s
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.1.0
/usr/include/c++/4.1.0/i586-suse-linux
/usr/include/c++/4.1.0/backward
/usr/local/include
/usr/lib/gcc/i586-suse-linux/4.1.0/include
/usr/lib/gcc/i586-suse-linux/4.1.0/http://www.cnblogs.com/http://www.cnblogs.com/i586-suse-linux/include
/usr/include
End of search list.
</pre>
上面列出了標頭檔搜尋路徑,根據第一個方法得出的檔案清單,大概就能定位出errno.h的位置。
<br />
<br />
在我的機器上errno.h的位置是:<br />
/usr/include/asm-generic/errno-base.h<br />
/usr/include/asm-generic/errno.h<br />
<div class="motadou_spec_line">1 -- 直接查看errno的說明</div>
我們可以使用“man errno”直接查看errno的定義,也可以使用“man -a errno | col -b > errno.man”將manual匯出來作為一個txt文檔閱讀。<br />
<pre class="pre_style">man -a errno | col -b > errno.man
Reformatting errno(3), please wait...
Reformatting errno(3p), please wait...
Reformatting Errno(3pm), please wait...
Reformatting errno.h(0p), please wait...
</pre>
<div class="motadou_spec_line">2 -- errno的值以及含義解析</div>
檔案:/usr/include/asm-generic/errno-base.h
<pre class="pre_style">#ifndef _ASM_GENERIC_ERRNO_BASE_H
#define _ASM_GENERIC_ERRNO_BASE_H
#defineEPERM 1/* Operation not permitted */
#defineENOENT 2/* No such file or directory */
#defineESRCH 3/* No such process */
#defineEINTR 4/* Interrupted system call */
#defineEIO 5/* I/O error */
#defineENXIO 6/* No such device or address */
#defineE2BIG 7/* Argument list too long */
#defineENOEXEC 8/* Exec format error */
#defineEBADF 9/* Bad file number */
#defineECHILD 10/* No child processes */
#defineEAGAIN 11/* Try again */
#defineENOMEM 12/* Out of memory */
#defineEACCES 13/* Permission denied */
#defineEFAULT 14/* Bad address */
#defineENOTBLK 15/* Block device required */
#defineEBUSY 16/* Device or resource busy */
#defineEEXIST 17/* File exists */
#defineEXDEV 18/* Cross-device link */
#defineENODEV 19/* No such device */
#defineENOTDIR 20/* Not a directory */
#defineEISDIR 21/* Is a directory */
#defineEINVAL 22/* Invalid argument */
#defineENFILE 23/* File table overflow */
#defineEMFILE 24/* Too many open files */
#defineENOTTY 25/* Not a typewriter */
#defineETXTBSY 26/* Text file busy */
#defineEFBIG 27/* File too large */
#defineENOSPC 28/* No space left on device */
#defineESPIPE 29/* Illegal seek */
#defineEROFS 30/* Read-only file system */
#defineEMLINK 31/* Too many links */
#defineEPIPE 32/* Broken pipe */
#defineEDOM 33/* Math argument out of domain of func */
#defineERANGE 34/* Math result not representable */
#endif
</pre>
<br />
<br />
檔案:/usr/include/asm-generic/errno.h
<pre class="pre_style">#ifndef _ASM_GENERIC_ERRNO_H
#define _ASM_GENERIC_ERRNO_H
#include <asm-generic/errno-base.h>
#defineEDEADLK 35/* Resource deadlock would occur */
#defineENAMETOOLONG36/* File name too long */
#defineENOLCK 37/* No record locks available */
#defineENOSYS 38/* Function not implemented */
#defineENOTEMPTY39/* Directory not empty */
#defineELOOP 40/* Too many symbolic links encountered */
#defineEWOULDBLOCKEAGAIN/* Operation would block */
#defineENOMSG 42/* No message of desired type */
#defineEIDRM 43/* Identifier removed */
#defineECHRNG 44/* Channel number out of range */
#defineEL2NSYNC45/* Level 2 not synchronized */
#defineEL3HLT 46/* Level 3 halted */
#defineEL3RST 47/* Level 3 reset */
#defineELNRNG 48/* Link number out of range */
#defineEUNATCH 49/* Protocol driver not attached */
#defineENOCSI 50/* No CSI structure available */
#defineEL2HLT 51/* Level 2 halted */
#defineEBADE 52/* Invalid exchange */
#defineEBADR 53/* Invalid request descriptor */
#defineEXFULL 54/* Exchange full */
#defineENOANO 55/* No anode */
#defineEBADRQC 56/* Invalid request code */
#defineEBADSLT 57/* Invalid slot */
#defineEDEADLOCKEDEADLK
#defineEBFONT 59/* Bad font file format */
#defineENOSTR 60/* Device not a stream */
#defineENODATA 61/* No data available */
#defineETIME 62/* Timer expired */
#defineENOSR 63/* Out of streams resources */
#defineENONET 64/* Machine is not on the network */
#defineENOPKG 65/* Package not installed */
#defineEREMOTE 66/* Object is remote */
#defineENOLINK 67/* Link has been severed */
#defineEADV 68/* Advertise error */
#defineESRMNT 69/* Srmount error */
#defineECOMM 70/* Communication error on send */
#defineEPROTO 71/* Protocol error */
#defineEMULTIHOP72/* Multihop attempted */
#defineEDOTDOT 73/* RFS specific error */
#defineEBADMSG 74/* Not a data message */
#defineEOVERFLOW75/* Value too large for defined data type */
#defineENOTUNIQ76/* Name not unique on network */
#defineEBADFD 77/* File descriptor in bad state */
#defineEREMCHG 78/* Remote address changed */
#defineELIBACC 79/* Can not access a needed shared library */
#defineELIBBAD 80/* Accessing a corrupted shared library */
#defineELIBSCN 81/* .lib section in a.out corrupted */
#defineELIBMAX 82/* Attempting to link in too many shared libraries */
#defineELIBEXEC83/* Cannot exec a shared library directly */
#defineEILSEQ 84/* Illegal byte sequence */
#defineERESTART85/* Interrupted system call should be restarted */
#defineESTRPIPE86/* Streams pipe error */
#defineEUSERS 87/* Too many users */
#defineENOTSOCK88/* Socket operation on non-socket */
#defineEDESTADDRREQ89/* Destination address required */
#defineEMSGSIZE90/* Message too long */
#defineEPROTOTYPE91/* Protocol wrong type for socket */
#defineENOPROTOOPT92/* Protocol not available */
#defineEPROTONOSUPPORT93/* Protocol not supported */
#defineESOCKTNOSUPPORT94/* Socket type not supported */
#defineEOPNOTSUPP95/* Operation not supported on transport endpoint */
#defineEPFNOSUPPORT96/* Protocol family not supported */
#defineEAFNOSUPPORT97/* Address family not supported by protocol */
#defineEADDRINUSE98/* Address already in use */
#defineEADDRNOTAVAIL99/* Cannot assign requested address */
#defineENETDOWN100/* Network is down */
#defineENETUNREACH101/* Network is unreachable */
#defineENETRESET102/* Network dropped connection because of reset */
#defineECONNABORTED103/* Software caused connection abort */
#defineECONNRESET104/* Connection reset by peer */
#defineENOBUFS 105/* No buffer space available */
#defineEISCONN 106/* Transport endpoint is already connected */
#defineENOTCONN107/* Transport endpoint is not connected */
#defineESHUTDOWN108/* Cannot send after transport endpoint shutdown */
#defineETOOMANYREFS109/* Too many references: cannot splice */
#defineETIMEDOUT110/* Connection timed out */
#defineECONNREFUSED111/* Connection refused */
#defineEHOSTDOWN112/* Host is down */
#defineEHOSTUNREACH113/* No route to host */
#defineEALREADY114/* Operation already in progress */
#defineEINPROGRESS115/* Operation now in progress */
#defineESTALE 116/* Stale NFS file handle */
#defineEUCLEAN 117/* Structure needs cleaning */
#defineENOTNAM 118/* Not a XENIX named type file */
#defineENAVAIL 119/* No XENIX semaphores available */
#defineEISNAM 120/* Is a named type file */
#defineEREMOTEIO121/* Remote I/O error */
#defineEDQUOT 122/* Quota exceeded */
#defineENOMEDIUM123/* No medium found */
#defineEMEDIUMTYPE124/* Wrong medium type */
#defineECANCELED125/* Operation Canceled */
#defineENOKEY 126/* Required key not available */
#defineEKEYEXPIRED127/* Key has expired */
#defineEKEYREVOKED128/* Key has been revoked */
#defineEKEYREJECTED129/* Key was rejected by service */
/* for robust mutexes */
#defineEOWNERDEAD130/* Owner died */
#defineENOTRECOVERABLE131/* State not recoverable */
#endif
</pre>