apue.h的擷取與使用

來源:互聯網
上載者:User

 

初學《UNIX環境進階編程》的朋友都會遇到一個問題,運行裡面的執行個體(download: http://www.apuebook.com/)時就出現問題,提示 "錯誤:apue.h:沒有那個檔案或目錄". apue.h是作者自訂的一個標頭檔,包括程式所需的常用標頭檔及出錯處理函數。所以因該將它放入系統標頭檔中(Linux下是 /usr/include),這樣gcc編譯器就可以找到它了。

 先去那個網站downlowd apue 的 tar.gz包,然後解壓至電腦中的某個目錄,比如我的是在/home/user/下,然後進入解壓目錄apue.2e,修改 Make.defines.linux中的WKDIR=/home/xxx/apue.2e,為WKDIR=/home/user/apue.2e,這就是我們將要make的工作目錄,然後再進入std目錄,用vi開啟linux.mk,將裡面的nawk全部改為awk,可以使用這個命令 :%s/nawk/awk/g (注意前面有冒號)

 然後 make

 然後按下面的步驟做

 1. 超級使用者權限登入 #cd /usr/include

 2. 將apue.h和error.c兩個檔案copy到該目錄下。(apue.h位於 your_apue_path/inlcude ; error.c位於your_apue_path/lib )

 以我的了路徑為例:

 #cp /home/ucfree/apue.2e/inlcude/apue.h .

 #cp /home/ucfree/apue.2e/lib/error.c . (實現apue.h中的出錯處理函數)

 3. 編輯apue.h

 #vi apue.h

 在最後一行 #endif 前面添加一行 #include "error.c"

 :wq 儲存,退出.

 

 這樣你就可以運行下載的apue程式了.

 

 

STDIN_FILENO and STDOUT_FILENO are part of the POSIX standard defined in
<unistd.h>.

 

the end-of-file character (usually Control-D).

 

 

getchar() is equivalent to getc(stdin). Never use gets(), use fgets() instead. A '/0' is stored after the last character in the buffer.

 

 

ferror() 它的一般調用形式為 ferroe(fp);如果ferror傳回值為0(假),表示未出錯。在執行fopen函數時,ferror函數的初始值自動置為0。

 

There are three primary functions for process control: fork,
exec, and waitpid.

 

The call wait(&status) is equivalent to:

           waitpid(-1, &status, 0);

 

 

In figure1.7, deal with '/n'. Replace it with '/0'

 

abort()沒有錯誤提示,c++中不釋放任何變數。

exit(1)有錯誤提示,c++中不釋放auto變數。

 

The header <sys/types.h> defines some implementation-dependent data types, called the
primitive system data types.

 

caddr_t  core address (Section 14.9)

clock_t  counter of clock ticks (process time) (Section
1.10)

comp_t  compressed clock ticks (Section 8.14)

dev_t  device numbers (major and minor) (Section
4.23)

fd_set  file descriptor sets (Section 14.5.1)

fpos_t  file position (Section 5.10)

gid_t  numeric group IDs

ino_t  i-node numbers (Section
4.14)

mode_t  file type, file creation mode (Section
4.5)

nlink_t  link counts for directory entries (Section
4.14)

off_t  file sizes and offsets (signed) (lseek,

Section 3.6)

pid_t  process IDs and process group IDs (signed) (Sections
8.2 and
9.4)

ptrdiff_t  result of subtracting two pointers (signed)

rlim_t  resource limits (Section
7.11)

sig_atomic_t  data type that can be accessed atomically (Section
10.15)

sigset_t  signal set (Section
10.11)

size_t  sizes of objects (such as strings) (unsigned) (Section
3.7)

ssize_t  functions that return a count of bytes (signed) (read,
write,
Section 3.7)

time_t  counter of seconds of calendar time (Section
1.10)

uid_t  numeric user IDs

wchar_t  can represent all distinct character codes

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.