File Permissions [Archive] - C Board

PDA

View Full Version : File Permissions


anumandal
03-20-2002, 03:54 AM
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.

Deckard
03-20-2002, 06:36 AM
Hi,

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:


/* 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);
Check the respective man pages for details on the accepted values for 'mode'.

Cheers,

anumandal
03-21-2002, 01:52 AM
Thanks i will try them.