【转】C中的access函数

http://blog.chinaunix.net/uid-22785134-id-360282.html

int   access(const   char   *filename,   int   amode);
amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。
这个函数还可以检查其它文件属性:
06     检查读写权限
04     检查读权限
02     检查写权限
01     检查执行权限
00     检查文件的存在性
而这个就算这个文件没有读权限,也可以判断这个文件存在于否
存在返回0,不存在返回-1

C函数
  函数名: access
  功 能: 确定文件的访问权限
  用 法: int access(const char *filename, int amode);

#include <stdio.h>
#include <io.h>
int file_exists(char *filename);
int main(void)
{
    printf("Does NOTEXIST.FIL exist: %s\n",
    file_exists("NOTEXISTS.FIL") ? "YES" : "NO");
    return 0;
}
int file_exists(char *filename)
{
    return (access(filename, 0) == 0);
}

【转】C中的access函数

时间: 2024-08-01 07:38:17

【转】C中的access函数的相关文章

【转载】 C中的access函数

分类: C/C++ int   access(const   char   *filename,   int   amode); amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1. 这个函数还可以检查其它文件属性: 06     检查读写权限 04     检查读权限 02     检查写权限 01     检查执行权限 00     检查文件的存在性而这个就算这个文件没有读权限,也可以判断这个文件存在于否存在返回0,不存在返回-1 C函数 函数名: access

[C++]在构造函数及析构函数中调用虚函数

(ISO/IEC 14882:2011 section 12.7.4): Member functions, including virtual functions (10.3), can be called during construction or destruction (12.6.2).When a virtual function is called directly or indirectly from a constructor or from a destructor, inc

linux编程中接收主函数返回值以及错误码提示

程序A创建子进程,并调用进程B,根据不调用的不同情况,最后显示结果不同. #include <stdio.h> #include <unistd.h> #include <sys/wait.h> #include <sys/types.h> #include <errno.h> int main() { pid_t pid, rpid; int stat; if ((pid = fork()) < 0) { perror("for

linux C之access函数

linux C之access函数 access():判断是否具有存取文件的权限 相关函数    stat,open,chmod,chown,setuid,setgid表头文件    #include<unistd.h>定义函数    int access(const char * pathname, int mode);函数说明    access()会检查是否可以读/写某一已存在的文件.参数mode有几种情况组合, R_OK,W_OK,X_OK 和F_OK.R_OK,W_OK与X_OK用来检

access函数

access函数是按照实际用户ID和实际组ID进行访问测试的.函数的定义如下: [cpp] view plaincopy #include <unistd.h> int access(const char* pathname, int mode); //若成功返回0,若出错则返回-1. 其中mode是下面所列常量的按位或. 实践: [java] view plaincopy #include <unistd.h> #include <stdio.h> #include 

SQL中的ISNULL函数详解及用途

SQL中有多种多样的函数,下面将为您介绍SQL中的ISNULL函数,包括其语法.注释.返回类型等,供您参考,希望对您学习SQL能够有所帮助 ISNULL 使用指定的替换值替换 NULL. 语法 ISNULL ( check_expression , replacement_value ) 参数 check_expression 将被检查是否为 NULL的表达式.check_expression 可以是任何类型的. replacement_value 在 check_expression 为 NU

4.2 access函数实例

int access(const char *filenpath, int mode); 功 能: 确定文件或文件夹的访问权限. 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

文件和目录详解(三)---access函数详解

当在进程中使用open打开一个文件的时候,内核在测试权限的时候是基于进程的有效用户ID 来测试的,但是如果我们想要测试进程的实际用户 ID 对文件的权限的时候该怎么办?Linux提供了access函数来实现此功能.当没有设置set-user-id位的时候,实际用户和有效用户是一致的.设置了set-user-id位后,实际用户和有效用户才有可能不一样. ======================================================= 函数原型: 函数参数: pathn

linux C之access函数 (20

http://blog.sina.com.cn/s/blog_6a1837e90100uh5d.html linux C之access函数 (20access():判断是否具有存取文件的权限 相关函数    stat,open,chmod,chown,setuid,setgid 表头文件    #include<unistd.h>定义函数     int access(const char * pathname, int mode);函数说明    access()会检查是否可以读/写某一已存