品牌公司网站建设,wordpress怎么实现注册登录,夏天做哪个网站致富,吉林百度查关键词排名access()函数的用法#xff1a;int access(const char *filenpath, int mode)
一、access()函数的作用
access()函数用来判断某个指定路径的文件#xff08;第一个参数 filenpath#xff09;#xff0c;是否符合第二个参数选项#xff08;F_OK(文件是否存在#xff09;…access()函数的用法int access(const char *filenpath, int mode)
一、access()函数的作用
access()函数用来判断某个指定路径的文件第一个参数 filenpath是否符合第二个参数选项F_OK(文件是否存在R_OK(是否可读W_OK是否可以写入,X_OK(是否可以运行当参数1满足参数2条件的时候返回0不满足时返回-1 二、使用 1.头文件
#includeunistd.h 2.access()函数
int access(const char *filenpath, int mode) 参数说明 filenpath 文件或文件夹的路径当前目录直接使用文件或文件夹名使用绝对路径 注当该参数为文件的时候access函数能使用mode参数所有的值当该参数为文件夹的时候access函数值能判断文件夹是否存在。
mode 要判断的模式。在头文件unistd.h中的定义如下
#define R_OK 4 /* Test for read permission. */
#define W_OK 2 /* Test for write permission. */
#define X_OK 1 /* Test for execute permission. */
#define F_OK 0 /* Test for existence. *具体的含义为
R_OK 只判断是否有读权限
W_OK 只判断是否有写权限
X_OK 判断是否有执行权限
F_OK 只判断是否存在
//注意R_OK、W_OK、X_OK可进行或|运算比如R_OK|W_OK即同时判断文件是否具有读写权限。2.access()函数用法示例
#include stdio.h
#include unistd.h
int main(void)
{if(access(/tmp/picture1.jpeg,F_OK)0){printf(文件存在\n);}elseprintf(文件不存在\n);if(access(/etc/profile,R_OK)0){printf(文件可读\n);}elseprintf(文件不可读\n);if(access(/etc/profile,W_OK)0){printf(文件可写\n);}elseprintf(文件不可写\n);
}