UNIX環境高階程式設計學習筆記 第三章 檔案I O

2021-08-21 17:18:59 字數 585 閱讀 6884

#include

int creat(const char *path,mode_t mode);

成功返回只寫開啟的檔案描述符,錯誤放回 -1;

等效 open(path, o_wronly|o_creat|o_trunc,mode);

o_trunc 如果檔案存在,只寫或讀-寫成功開啟,則其長度截斷為0;

creator()只寫方式開啟所創造的檔案,需讀時先要close,在呼叫open。現在用open即可完成建立、寫、讀。

open(path,o_rdwr|o_creat|o_trunc,mode);

#include

int close (int fd); 成功返回 0;失敗返回-1;

#include

off_t lseek(int fd ,off_t offset,int whence);成功返回新的檔案偏移量;出錯返回 -1;

whence 是 seek_set,從開始偏移 offset 個位元組;

whence 是 seek_cur,從當前值加offset,可正可負;

whence 是 seek_end,從檔案長度加offset ,可正可負。

UNIX環境高階程式設計學習筆記

include include include include int main int argc,char argv err sys can t open s argv 1 while dirp readdir dp null printf s n dirp d name closedir dp ...

UNIX環境高階程式設計學習筆記 程序

2.程序控制 在提出這個問題的時候,我想了一下,大概就是核心執行的乙個程式 錯誤回答 吧。但是這麼說,連我自己下次看都不明白在說什麼。於是我查了一下,它代表著cpu所能處理的單個任務,及執行例項。在面向程序設計的系統 如早期 unix,linux 2.4及更早版本中 程序是程式的基本執行實體 在面向...

Unix環境高階程式設計學習筆記 二

三種主要的標準 iso c ieee posix single unix specification xsi 一層一層遞增,ieee posix 是iso c的超集。xsi 是posix的超集。要想提高軟體的可移植性,就必須有限制 編譯時限制 因為某些限制是固定的,則可以在標頭檔案中定義。執行時限制...