access/_access函数

简介: access/_access函数

Linux下


1,头文件:


#include <unistd.h>


2,函数的声明:


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


3,函数的作用:


access函数用来判断指定的文件或目录是否存在(F_OK),已存在的文件或目录是否有可读(R_OK)、可写(W_OK)、可执行(X_OK)权限。F_OK、R_OK、W_OK、X_OK这四种方式通过access函数中的第二个参数mode指定


4,函数的返回值:

如果指定的方式有效,则此函数返回0,否则返回-1。


5,事例:

判断是否允许读取/etc/passwd


#include <unistd.h>
int main()
{
    if(access("/etc/passwd", R_OK) == 0)
    printf("/etc/passwd can be read\n");
}


结果如下:


cda18c1bd66e470e9707d79ea3a6ba9f.png

相关文章
|
8月前
|
JavaScript 前端开发
has been blocked by CORS policy: The ‘Access-Control-Allow-Origin‘ header contains multiple values ‘
has been blocked by CORS policy: The ‘Access-Control-Allow-Origin‘ header contains multiple values ‘
191 0
|
API
【已解决】No ‘Access-Control-Allow-Origin‘ header is present on the requested resource
No ‘Access-Control-Allow-Origin‘ header is present on the requested resource
433 0
【已解决】No ‘Access-Control-Allow-Origin‘ header is present on the requested resource
|
安全 JavaScript 前端开发
No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
|
JavaScript 应用服务中间件 nginx
Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight respo
Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight respo
Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight respo
|
Linux
解决checkPermissions Missing write access to
解决checkPermissions Missing write access to
320 0
|
SQL 数据库 关系型数据库
|
网络协议 网络安全 iOS开发