0
点赞
收藏
分享

微信扫一扫

LINUX下C语言用access()检查文件可读、可写权限


  有时还是很有必要的:

#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);
}



举报

相关推荐

0 条评论