stat函式的用法
標頭檔案: #include
函式定義: int stat(const char *file_name, struct stat *buf);
函式說明: 通過檔名filename獲取檔案資訊,並儲存在buf所指的結構體stat中
返回值: 執行成功則返回0,失敗返回-1,錯誤**存於errno(需要include )
errno錯誤**:
enoent 引數file_name指定的檔案不存在
enotdir 路徑中的目錄存在但卻非真正的目錄
eloop 欲開啟的檔案有過多符號連線問題,上限為16符號連線
efault 引數buf為無效指標,指向無法存在的記憶體空間
eaccess 訪問檔案時被拒絕
enomem 核心記憶體不足
enametoolong 引數file_name的路徑名稱太長
stat結構體定義:
struct stat ;
示例**:
#include
#include
#include
int main()
return 0;
}
關於stat的用法
看了個關於stat的帖子 原來還公尺用過滴 在網上查了資料 自己除錯了下 原來stat 是這麼好用哇 以下是 別人的blog 函式都是獲取檔案 普通檔案,目錄,管道,socket,字元,塊 的屬性。函式原型 include int stat const char restrict pathname,...
stat函式與stat結構體
在linux中,可以利用stat 函式來獲取乙個檔案的狀態 include include int stat const char file name,struct stat buf 這個函式執行成功返回0,失敗返回 1。取得的檔案狀態存放在buf指標指向的struct stat結構提中,struc...
stat 函式解析
stat 函式是用來獲取檔案的各種屬性的乙個linux下的常用api函式。函式原型為int stat const char path,struct stat buf stat定義如下 struct stat st mode 的定義 16位整數 0 2 其他人許可權 8進製 s iroth 00004...