標籤:des style blog os ar strong 檔案 sp div
這兩個函數使我們可以更改現有檔案的存取權限:
#include <sys/stat.h>int chmod( const char *pathname, mode_t mode );int fchmod( int filedes, mode_t mode );兩個函數傳回值:若成功則返回0,若出錯則返回-1
chmod函數在指定的檔案上進行操作,而fchmod函數則對已開啟的檔案進行操作。
為了改變一個檔案的許可權位,進程的有效使用者ID必須等於檔案的所有者ID,或者該進程必須具有超級使用者權限。
參數mode所示常量的某種按位或運算構成的
| mode |
說明 |
S_ISUID
S_ISGID
S_ISVTX |
執行時設定使用者ID
執行時設定組ID
儲存本文(粘住位) |
S_IRWXU
S_IRUSR
S_IWUSR
S_IXUSR |
使用者(所有者)讀、寫和執行
使用者(所有者)讀
使用者(所有者)寫
使用者(所有者)執行 |
S_IRWXG
S_IRGRP
S_IWGRP
S_IXGRP |
組讀、寫和執行
組讀
組寫
組執行 |
S_IRWXO
S_IROTH
S_IWOTH
S_IXOTH |
其他讀、寫和執行
其他讀
其他寫
其他執行
|
chown函數可用於變更檔的使用者ID和組ID:
#include <unistd.h>int chown( const char *pathname, uid_t owner, gid_t group );int fchown( int filedes, uid_t owner, gid_t group );int lchown( const char *pathname, uid_t owner, gid_t group ); 三個函數的傳回值:若成功則返回0,若出錯則返回-1
chmod和fchmod函數 /chown ,fchown,lchown函數