LINUX下C語言用access()檢查檔案可讀、可寫許可權
阿新 • • 發佈:2021-02-02
技術標籤:Linux/ShellC/C++
有時還是很有必要的:
#include <unistd.h> #include <fcntl.h> int access(const char *pPath, int mode); F_OK:檔案是否存在 R_OK:讀 W_OK:寫 X_OK:執行 #define LOCK_FILE "quantum6.lock" if (access(LOCK_FILE, W_OK) != -1) { printf("%s can write.\n", LOCK_FILE); } else { printf("%s can not write.\n", LOCK_FILE); }