_chmod

王朝百科·作者佚名  2012-05-07
窄屏简体版  字體: |||超大  

函数简介函数原型:

int _chmod(

const char *filename,

int pmode

);

函数功能:改变文件的读写许可设置,如果改变成功返回0,否则返回-1

所属库:io.h

相关函数:_tchmod 、_wchmod

程序示例#include <sys/types.h>

#include <sys/stat.h>

#include <io.h>

#include <stdio.h>

#include <stdlib.h>

#include <errno.h>

// Change the mode and report error or success

void set_mode_and_report(char * filename, int mask)

{

// Check for failure

if( _chmod( filename, mask ) == -1 )

{

// Determine cause of failure and report.

switch (errno)

{

case EINVAL:

fprintf( stderr, "Invalid parameter to chmod.

");

break;

case ENOENT:

fprintf( stderr, "File %s not found

", filename );

break;

default:

// Should never be reached

fprintf( stderr, "Unexpected error in chmod.

" );

}

}

else

{

if (mask == _S_IREAD)

printf( "Mode set to read-only

" );

else if (mask & _S_IWRITE)

printf( "Mode set to read/write

" );

}

fflush(stderr);

}

int main( void )

{

// Create or append to a file.

system( "echo /* End of file */ >> crt_chmod.c_input" );

// Set file mode to read-only:

set_mode_and_report("crt_chmod.c_input ", _S_IREAD );

system( "echo /* End of file */ >> crt_chmod.c_input " );

// Change back to read/write:

set_mode_and_report("crt_chmod.c_input ", _S_IWRITE );

system( "echo /* End of file */ >> crt_chmod.c_input " );

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航