函數名稱:chmod
頭檔:<io.h>
函數原型: int chmod(const char *file,int auth);
功能:用於改變文件存取方式
參數:const char *file 為要修改的檔名, int auth 為要修改的權限,其值為S_IREAD,S_IWRITE或S_IEXEC
傳回值:成功回傳0 ,失敗回傳-1
程式範例:將指定的檔案修改為唯讀模式
#include<stdio.h>#include<io.h>#include<sys/stat.h>voidmake_read_only(char*filename);intmain(void){make_read_only(D:\a.txt);make_read_only(MYFILE. FIL);return0 ;}voidmake_read_only(char*filename){intstat=chmod(filename,S_IREAD);if(stat)printf(Couldn'tmake%sread-onlyn,filename);elseprintf(Made%sread-onlyn,filename); }
運行結果:
Couldn'tmakeD:a.txtread-onlyCouldn'tmakeMYFILE.FILread-only