stat 函數與結構體

來源:互聯網
上載者:User

學習,stat,lstat,fstat
1 函數都是擷取檔案(普通檔案,目錄,管道,socket,字元,塊()的屬性。
函數原型
#include <sys/stat.h>

int stat(const char *restrictpathname, struct stat *restrictbuf);
提供檔案名稱字,擷取檔案對應屬性。
int fstat(intfiledes, struct stat *buf);
通過檔案描述符擷取檔案對應的屬性。
int lstat(const char *restrictpathname, struct stat *restrictbuf);
串連檔案描述命,擷取檔案屬性。
2 檔案對應的屬性
struct stat {
mode_t st_mode; //檔案對應的模式,檔案,目錄等
ino_t st_ino; //inode節點號
dev_t st_dev; //裝置號碼
dev_t st_rdev; //特殊裝置號碼
nlink_t st_nlink; //檔案的串連數
uid_t st_uid; //檔案所有者
gid_t st_gid; //檔案所有者對應的組
off_t st_size; //普通檔案,對應的檔案位元組數
time_t st_atime; //檔案最後被訪問的時間
time_t st_mtime; //檔案內容最後被修改的時間
time_t st_ctime; //檔案狀態改變時間
blksize_t st_blksize; //檔案內容對應的塊大小
blkcnt_t st_blocks; //偉建內容對應的塊數量
};
可以通過上面提供的函數,返回一個結構體,儲存著檔案的資訊。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.