Chinaunix首页 | 论坛 | 博客
  • 博客访问: 256219
  • 博文数量: 71
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 920
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-16 13:07
个人简介

我喜欢蓝天,也喜欢雨天。

文章分类

全部博文(71)

文章存档

2014年(14)

2013年(57)

分类: C/C++

2013-09-05 15:16:23

 
_access() 检验文件的模式
返回值:0表示允许访问,-1表示禁止访问。
函数原型:
int _access( 
   const char *path, 
   int mode 
);
另外有宽字符的:
int _waccess( 
   const wchar_t *path, 
   int mode 
);
mode value Checks file for

00

Existence only

02

Write-only

04

Read-only

06

Read and write

这个函数只检查文件和目录是否是只读的,它不检查文件系统安全设置。

返回值 文件具有给定的模式返回0,如果文件不存在或没有给定的模式,返回-1

 

EACCESS(拒绝访问:文件的权限设置不允许指定的访问),

ENOENT(文件名或路径未找到),

EINVAL(无效的参数).

 

例子:

// crt_access.c
// compile with: /W1
// This example uses _access to check the file named
// crt_ACCESS.C to see if it exists and if writing is allowed.

#include  
#include  
#include  

int main( void )
{
    // Check for existence.
    if( (_access( "crt_ACCESS.C", 0 )) != -1 )
    {
        printf_s( "File crt_ACCESS.C exists.\n" );

        // Check for write permission.
        // Assume file is read-only.
        if( (_access( "crt_ACCESS.C", 2 )) == -1 )
            printf_s( "File crt_ACCESS.C does not have write permission.\n" );
    }
}
阅读(3690) | 评论(0) | 转发(0) |
0

上一篇:vs2010 创建动态链接库DLL

下一篇:#pragma

给主人留下些什么吧!~~