檔案屬性操作函式(12)

2022-09-23 14:39:10 字數 1385 閱讀 3497

4修改檔案的許可權

5引數:

6- pathname: 需要修改的檔案的路徑

7- mode:需要修改的許可權值,八進位制的數

8返回值:成功返回0,失敗返回-1910

*/11 #include 12 #include 13

intmain()

2122

return0;

23 }

1/*2

#include

3int access(const char *pathname, int mode);

4作用:判斷某個檔案是否有某個許可權,或者判斷檔案是否存在

5引數:

6- pathname: 判斷的檔案路徑

7- mode:

8r_ok: 判斷是否有讀許可權

9w_ok: 判斷是否有寫許可權

10x_ok: 判斷是否有執行許可權

11f_ok: 判斷檔案是否存在

12返回值:成功返回0, 失敗返回-1

13*/

1415 #include 16 #include 17

18int

main()

2425 printf("

檔案存在!!!\n");

2627

return0;

28 }

1/*2

#include

3#include

4int truncate(const char *path, off_t length);

5作用:縮減或者擴充套件檔案的尺寸至指定的大小

6引數:

7- path: 需要修改的檔案的路徑

8- length: 需要最終檔案變成的大小

9返回值:

10成功返回0, 失敗返回-1

11*/

1213 #include 14 #include 15 #include 16

17int

main()

2526

return0;

27 }

檔案屬性函式stat fstat lstat

stat,lstat,fstat1 函式都是獲取檔案 普通檔案,目錄,管道,socket,字元,塊 的屬性。函式原型 include int stat const char restrict pathname,struct stat restrict buf 提供檔案名字,獲取檔案對應屬性。int ...

獲取檔案屬性函式

表頭檔案 include 函式定義 int stat const char file name,struct stat buf 函式說明 通過檔名filename獲取檔案資訊,並儲存在buf所指的結構體stat中 返回值 執行成功則返回0,失敗返回 1,錯誤 存於errno 需要include er...

linux檔案屬性函式

1.int access const char pathname,int mode 測試當前使用者指定檔案是否具有某種屬性 引數 pathname 檔名 mode 4種許可權 r ok 讀 w ok 寫 x ok 執行 f ok 檔案是否存在 返回值 0 具有某種許可權 1 沒有許可權,或檔案不存在...