Thread: File Permissions

  1. #1
    anumandal
    Guest

    Unhappy File Permissions

    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.

  2. #2
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    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:

    Code:
    /* 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,
    Jason Deckard

  3. #3
    anumandal
    Guest
    Thanks i will try them.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  2. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM