標頭檔案:
為了節省時間,僅簡單記錄函式的名字忽略原型, 重點在於記下自己實踐中的感悟。
function
creat
open
close
read
write
lseek
fcntl
file_io.h
#pragma once
#include
#include "include/apue.h"
#include "include/inc.h"
#include
ns_begin(elloop);
class fileio
static
bool creatfile()
static
bool openfileread()
close(fd);
return
true;
}static
void openfilewrite()
static off_t getfilesize(int fd)
static
bool canseek()
else
}static
void createholefile()
static
void copyfile()
err_if_neg(n, err_sys, "read error");
}static
void printfileflag(int argc, char** argv)
}if (val & o_nonblock)
if (val & o_sync)
#if !defined(_posix_c_source) && defined(o_fsync) && (o_fsync != o_sync)
if (val & o_fsync)
#endif
cr;}
static
void setfl(int fd, int flags)
static
void clrfl(int fd, int flags)
};ns_end(elloop);
作者水平有限,對相關知識的理解和總結難免有錯誤,還望給予指正,非常感謝! APUE學習筆記 檔案IO
1 lseek的返回值應該判斷是否為0,而不是小於0。2 偏移量可以大於檔案大小。這個時候會有檔案空洞。4 open加上標誌 o create和o excl可以判斷檔案是否存在。5 dup和dup2可複製檔案描述符。並可指定複製後的描述符。6 linux ext2檔案系統不支援o sync標誌。可以...
APUE 學習筆記 檔案I O
本章節主要講了 linux 系統下的關於檔案i o操作的幾個函式 open read write lseek close 的使用和需要注意的一些細節。接著,又介紹了多程序見如何共享檔案。下面開始知識點梳理。對於核心來說,所有開啟的檔案,都是通過檔案描述符來引用。當開啟或建立乙個新的檔案的時候,核心都...
APUE筆記(1) 配置APUE環境
本人用的是centos6.5版本的linux 寫這個環境配置是因為自己這一天被這個環境配置給搞的很難受 首先,我們在linux下找乙個資料夾,存放apue3的包 cd home src wget 然後解壓 tar zxv f src.3e.tar.gz 進入apue.3e資料夾 cd home sr...