Use C program to do this one I know what chmod is and what i
Use C program to do this one.
I know what chmod is and what it does in Linix terminal but I don\'t know how to program this in C program
Any tips? Thanks
Solution
-> Here a new command \"cm FILE rw\" .
-> In the compilation of c code , save object code with the name cm as shown below
=> gcc -o cm cprogram.c
-> then compilation code executed by using \"cm\" in the terminal as new command.
-> Before writing code , here need of two arguments one is file name and other is permissions .
-> take these two as arguments in the code to implement c progrm to set permissions of a file as given in the arguments.
-> next in c code implementation, take number of arguments for different options entered as arguments .forexample if no arguments then the output should show synopsis for the command.
->sample c code here
#include <sys/types.h>
#include <sys/stat.h>
#include<string.h>
#include<stdio.h>
int chmod(const char *path, mode_t mode);
int fchmod(int fildes, mode_t mode);
int main(int argn,char *args[])
{
char *perm=\"r\";
printf(\"file name is :%s\ \",args[1]);
printf(\"permissios entered by user \ %s\ \",args[2]);
if(strcmp(args[2],perm)==0)
{
printf(\"read permission given to owner\");
}
return 0;
}
