_chmod, _wchmod 更改文件访问权限
2006-05-30 18:17
281 查看
_chmod, _wchmod
Change the file-permission settings.int _chmod( const char *filename, int pmode );
int _wchmod( const wchar_t *filename, int pmode );
Routine | Required Header | Optional Headers | Compatibility |
_chmod | <io.h> | <sys/types.h>, <sys/stat.h>, <errno.h> | Win 95, Win NT |
_wchmod | <io.h> or <wchar.h> | <sys/types.h>, <sys/stat.h>, <errno.h> | Win NT |
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 |
Each of these functions returns 0 if the permission setting is successfully changed. A return value of –1 indicates that the specified file could not be found, in which case errno is set to ENOENT.
Parameters
filename
Name of existing file
pmode
Permission setting for file
Remarks
The _chmod function changes the permission setting of the file specified by filename. The permission setting controls read and write access to the file. The integer expression pmode contains one or both of the following manifest constants, defined in SYS/STAT.H:
_S_IWRITE
Writing permitted
_S_IREAD
Reading permitted
_S_IREAD | _S_IWRITE
Reading and writing permitted
Any other values for pmode are ignored. When both constants are given, they are joined with the bitwise-OR operator ( | ). If write permission is not given, the file is read-only. Note that all files are always readable; it is not possible to give write-only permission. Thus the modes _S_IWRITE and _S_IREAD | _S_IWRITE are equivalent.
_wchmod is a wide-character version of _chmod; the filename argument to _wchmod is a wide-character string. _wchmod and _chmod behave identically otherwise.
Generic-Text Routine Mappings
TCHAR.H Routine | _UNICODE & _MBCS Not Defined | _MBCS Defined | _UNICODE Defined |
_tchmod | _chmod | _chmod | _wchmod |
/* CHMOD.C: This program uses _chmod to * change the mode of a file to read-only. * It then attempts to modify the file. */ #include <sys/types.h> #include <sys/stat.h> #include <io.h> #include <stdio.h> #include <stdlib.h> void main( void ) { /* Make file read-only: */ if( _chmod( "CHMOD.C", _S_IREAD ) == -1 ) perror( "File not found/n" ); else printf( "Mode changed to read-only/n" ); system( "echo /* End of file */ >> CHMOD.C" ); /* Change back to read/write: */ if( _chmod( "CHMOD.C", _S_IWRITE ) == -1 ) perror( "File not found/n" ); else printf( "Mode changed to read/write/n" ); system( "echo /* End of file */ >> CHMOD.C" ); }
Output
Mode changed to read-only Access is denied Mode changed to read/write
File Handling Routines
See Also _access, _creat, _fstat, _open, _stat
相关文章推荐
- 命令umask,文件或目录权限chmod,更改所有者所属组chown,隐藏权限chattr—lsattr
- 文件或目录权限chmod、更改所有者和所属组chown、umask、隐藏权限lsattr_chattr
- Linux下更改目录及其下的子目录和文件的访问权限
- [Linux] 更改文件权限 chmod
- chmod命令(改变文件或目录的访问权限)
- 重温python之OS模块的简单使用4:os.chmod() 更改文件或目录的权限
- 文件或目录权限chmod 、更改所有者和所属组chow、umask、隐藏权限lsattr/chattr
- 更改目录及其下的子目录和文件的访问权限
- UNIX环境编程学习笔记(9)——文件I/O之文件访问权限的屏蔽和更改
- Linux下更改目录及其下的子目录和文件的访问权限
- Linux: chmod 更改文件的权限
- 无法保存对hosts权限所作的更改 拒绝访问(权限,防止Windows主机文件、进程、注册表项进行操作和更改)
- 如何使用命令行更改文件以及文件夹的访问控制权限,从而达到最高权限控制文件的目的
- Linux下更改目录及其下的子目录和文件的访问权限
- ubuntu 更改目录及其下的子目录和文件的访问权限
- 文件或目录权限chmod,更改所有者所属组chown
- 二周第三次课 2017.10.25 文件和目录权限chmod、更改所有者和所属组chown、umask、隐藏权限lsattr/chattr
- 2周第3次课 文件或目录权限chmod 更改文件所有者和所属组chown umask掩码 文件特殊属性chattr_lsattr
- Linux下更改目录及其下的子目录和文件的访问权限
- C#更改文件访问权限所有者(适用于各个Windows版本)