访问功能检查文件是否存在? [英] does access function check the existence of file?

查看:44
本文介绍了访问功能检查文件是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

访问功能检查是否可以通过how参数指定的方式访问文件.how参数可以是标志R_OK,W_OK,X_OK或存在性测试F_OK的按位或.

The access function checks to see whether the file can be accessed in the way specified by the how argument. The how argument either can be the bitwise OR of the flags R_OK, W_OK, X_OK, or the existence test F_OK.

如果允许访问,则返回值为0,否则为-1.

The return value is 0 if the access is permitted, and -1 otherwise.

如果文件不存在,访问是否也会返回-1?

if the file does not exist, Does the access return -1 too?

我希望开发一种功能,通过该功能可以检查文件是否存在.如果执行了以下访问函数,那么根据标准我必须输入哪种参数?

I wan to develop a function in which I check the existence of a file. If the following access function did it, what kind of arguments I have to put according to the standard?

if (access("file_example", R_OK | W_OK | X_OK) != -1)

顺便说一句:我要检查是否通过同一应用程序创建了 access()函数所存在的文件.因此它是由同一用户创建的

BTW: the file I want to check if exisits by access() function is created by the same application. so it's created by the same user

推荐答案

那些标志将检查该文件是否可执行,可读写以及是否可被进程读取,而很多文件则不会.您要查找的标志是F_OK.F_OK测试文件是否存在,什么都没有.

Those flags would check if the file is executable, writeable and readable by the process, lots of files won't be. The flag you're looking for is F_OK. F_OK tests for the existence of the file and nothing else.

我建议阅读手册页进行访问.应该在那里记录下来.

I suggest reading the man page for access. It should be documented there.

这篇关于访问功能检查文件是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆