Can anybody please help me with the following?
I am creating files and directories through a C program, I want to set the permissions for these files and directories.
I would like to give 'rx' permission to group and others while the owner of the file should have 'rwx' permission.
Please can anybody guide me how I will be able to achieve it.
There are a number of ways you can change file permissions from within your C code. Here are the prototypes for library functions that come to mind:
Check the respective man pages for details on the accepted values for 'mode'.
/* To create a new file, specifying the 'mode' (permissions) */
int creat(const char *pathname, mode_t mode);
/* To modify the permissions of a file by name */
int chmod(const char *path, mode_t mode);
/* To modify the permissions of a file by descriptor */
int fchmod(int fildes, mode_t mode);