Function name : chmod
Header file : <io.h>
Function prototype : int chmod(const char *file,int auth);
Function : Used to change the file access method
Parameters : const char *file is the file name to be modified, int auth is the permission to be modified, its value is S_IREAD, S_IWRITE or S_IEXEC
Return value : 0 on success, -1 on failure
Program example : Modify the specified file to read-only mode
#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); }
Running results:
Couldn'tmakeD:a.txtread-onlyCouldn'tmakeMYFILE.FILread-only