_access, _waccess 确定文件的访问权限

原创 2006年05月30日 18:16:00
 

_access, _waccess

Determine file-access permission.

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

int _waccess( const wchar_t *path, int mode );

Routine Required Header Optional Headers Compatibility
_access <io.h> <errno.h> Win 95, Win NT
_waccess <wchar.h> or <io.h> <errno.h> Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

Return Value

Each of these functions returns 0 if the file has the given mode. The function returns –1 if the named file does not exist or is not accessible in the given mode; in this case, errno is set as follows:

EACCES

Access denied: file’s permission setting does not allow specified access.

ENOENT

Filename or path not found.

Parameters

path

File or directory path

mode

Permission setting

Remarks

When used with files, the _access function determines whether the specified file exists and can be accessed as specified by the value of mode. When used with directories, _access determines only whether the specified directory exists; in Windows NT, all directories have read and write access.

mode Value Checks File For
00 Existence only
02 Write permission
04 Read permission
06 Read and write permission

_waccess is a wide-character version of _access; the path argument to _waccess is a wide-character string. _waccess and _access behave identically otherwise.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_taccess _access _access _waccess

Example

/* ACCESS.C: This example uses _access to check the
 * file named "ACCESS.C" to see if it exists and if
 * writing is allowed.
 */

#include  <io.h>
#include  <stdio.h>
#include  <stdlib.h>

void main( void )
{
   /* Check for existence */
   if( (_access( "ACCESS.C", 0 )) != -1 )
   {
      printf( "File ACCESS.C exists/n" );
      /* Check for write permission */
      if( (_access( "ACCESS.C", 2 )) != -1 )
         printf( "File ACCESS.C has write permission/n" );
   }
}

Output

File ACCESS.C exists
File ACCESS.C has write permission

File Handling Routines

See Also _chmod, _fstat, _open, _stat

Android文件访问权限(第一个)

  • 2014年07月16日 16:58
  • 2.73MB
  • 下载

Swift 3 Access Levels 访问权限的学习

Swift 3 Access Levels 访问权限的学习 在Swift 3中访问权限发生了一些改变,选择有5种访问权限分别是:open、public、internal、fileprivate、pri...

07_文件访问权限

  • 2017年07月27日 10:39
  • 1.13MB
  • 下载

asp.net项目中通过Web.config配置文件及文件夹的访问权限!

描述:在开发中我们通常会碰到这样的问题,例如:在项目的根目录下面有一个文件或者文件夹需要用户登陆后才能访问。如果用户在没有登录的情况下访问该文件或者该文件夹下面的文件时,直接拦截重定向到对应的登陆页面...

win8 右键获取文件访问权限

  • 2013年02月24日 19:43
  • 961B
  • 下载

Linux下C代码中修改文件访问权限

转自:http://blog.chinaunix.net/uid-25940216-id-3207480.html 【Yasi注】:注意,不能想当然的认为,调用chmod("/opt/*",...
  • yasi_xi
  • yasi_xi
  • 2013年01月29日 20:31
  • 8404

09文件访问权限

  • 2015年10月12日 16:14
  • 882KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:_access, _waccess 确定文件的访问权限
举报原因:
原因补充:

(最多只允许输入30个字)