_access()函数

 
_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  <io.h>
#include  <stdio.h>
#include  <stdlib.h>

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" );
    }
}
<script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/buttonLite.js#style=-1&uuid=&pophcol=3&lang=zh"></script> <script type=text/javascript charset=utf-8 src="http://static.bshare.cn/b/bshareC0.js"></script>
阅读(184) | 评论(0) | 转发(0) |
0

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

下一篇:#pragma

给主人留下些什么吧!~~
评论热议
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值