access(C语言函数名)

来源:互联网 发布:软件测试工具下载 编辑:程序博客网 时间:2024/05/20 04:50

  函数名: access

  头文件:io.h(linux中为)

  功 能: 确定文件的访问权限,检查某个文件的存取方式,比如说是只读方式、只写方式等。如果指定的存取方式有效,则函数返回0,否则函数返回-1。

  用 法: int access(const char *filename, int amode);

  int _access(const char *path,int mode) ;

  access函数,当对文件使用时,判断是否存在指定的文件,以及是否能够按指定的模式进行访问。当对目录使用时,只判断是否存在指定的目录;因为在Windows系统下所有的目录都有读和写的访问权限。

  参数mode可为以下的其中之一:

  00 只存在

  02 写权限

  04 读权限

  06 读和写权限

  返回值:

  如果文件拥有给定的模式则返回0,如果发生错误返回-1。

  可移植性:

  Windows,Unix 及其类似系统都存在此函数。

  请注意,lcc-win32同时支持_access(微软公约)和access。

  程序例:

  #include <stdio.h>

  #include <io.h>

  intfile_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);

  }

出处:http://baike.sogou.com/v64470796.htm

0 0
原创粉丝点击