Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <sys\types.h>
    #include <sys\stat.h>
    #include <io.h>
    int chmod( const char *path, int permission );

Description:
    The chmod function changes the permissions for a file specified by path
    to be the settings in the mode given by permission.  The access
    permissions for the file or directory are specified as a combination of
    bits (defined in the <sys\stat.h> header file).

    The following bits define permissions for the owner.

    S_IRWXU
        Read, write, execute/search

    S_IRUSR
        Read permission

    S_IWUSR
        Write permission

    S_IXUSR
        Execute/search permission

    The following bits define permissions for the group.

    S_IRWXG
        Read, write, execute/search

    S_IRGRP
        Read permission

    S_IWGRP
        Write permission

    S_IXGRP
        Execute/search permission

    The following bits define permissions for others.

    S_IRWXO
        Read, write, execute/search

    S_IROTH
        Read permission

    S_IWOTH
        Write permission

    S_IXOTH
        Execute/search permission

    The following bits define miscellaneous permissions used by other
    implementations.

    S_IREAD
        is equivalent to S_IRUSR (read permission)

    S_IWRITE
        is equivalent to S_IWUSR (write permission)

    S_IEXEC
        is equivalent to S_IXUSR (execute/search permission)

    The following bits may also be specified in permission.

    S_ISUID
        set user id on execution

    S_ISGID
        set group id on execution

    If the calling process does not have appropriate privileges, and if the
    group ID of the file does not match the effective group ID or one of the
    supplementary group IDs, and if the file is a regular file, bit S_ISGID
    (set group ID on execution) in the file's mode shall be cleared upon
    successful return from the chmod function.

    Upon successful completion, the chmod function will mark for update the
    st_ctime field of the file.

Returns:
    The chmod returns zero if the new settings are successfully made;
    otherwise, -1 is returned and  errno is set to indicate the error.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    EACCES
        Search permission is denied for a component of path.

    ENOENT
        The specified path does not exist or path is an empty string.


See Also:
    fstat, open, sopen, stat

Example:
    /*
     * change the permissions of a list of files
     * to be read/write by the owner only
     */

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys\types.h>
    #include <sys\stat.h>
    #include <io.h>

    void main( int argc, char *argv[] )
      {
        int i;
        int ecode = 0;

        for( i = 1; i < argc; i++ ) {
          if( chmod( argv[i], S_IRUSR | S_IWUSR ) == -1 ) {
            perror( argv[i] );
            ecode++;
          }
        }
        exit( ecode );
      }

Classification:
    POSIX 1003.1

Systems:
    All

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson