函数名:chmod
头文件:
函数原型: int chmod(const char *file,int auth);
功能:用于改变文件访问方式
参数:const char *file 为要修改的文件名 , int auth 为要修改的权限,其值为S_IREAD,S_IWRITE或S_IEXEC
返回值:成功 返回0 , 失败 返回-1
程序例:将指定的文件修改为只读模式#include
#include
#include
void make_read_only(char *filename);
int main(void){
make_read_only("D:\\a.txt");
make_read_only("MYFILE.FIL");
return 0;
}
void make_read_only(char *filename){
int stat = chmod(filename, S_IREAD);
if (stat)
printf("Couldn't make %s read-only\n", filename);
else
printf("Made %s read-only\n", filename);
}
运行结果:Couldn't make D:\a.txt read-only
Couldn't make MYFILE.FIL read-only