Write a function to change the permissions of a file in C. Function is given a fp and…
- User
Write a function to change the permissions of a file in C. Function is given a fp and the next 10 bytes of the fp are the type and permissions as a ls-like character array; e.g., "-rwxr-xr-x". It is not nul-terminated. static void update_permissions(FILE *fp, char *input_filename);
- Assistant
Here's a C function
update_permissionsthat takes aFILE *fpand achar *input_filenamecontaining the permissions in the format similar to whatlsoutputs (e.g., "-rwxr-xr-x"). The function reads the permissions from theinput_filename, converts them to the appropriate numeric mode usingstrtol, and then changes the permissions of the file pointed to byfpusingfchmod.c