Watcom C Library Reference : chdir, chmod, chsize

 

 

 

 

chdir

 

Synopsis : #include <sys\types.h> 

              #include <direct.h>

              int chdir( const char *path );



Description : The chdir function changes the current working directory to the specified path. The path
can be either relative to the current working directory or it can be an absolute path name.

 

 

Returns : The chdir function returns zero if successful. Otherwise, -1 is returned. errno is set to indicate the error, and the current working directory remains unchanged.

 

 

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

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

 


See Also : getcwd, mkdir, rmdir

Example :

#include <stdio.h> 

#include <stdlib.h> 

#include <direct.h>


void main( int argc, char *argv[ ] ) 

{
    if( argc != 2 ) {
        fprintf( stderr, "Use: cd <directory>\n" );

        exit ( 1 );

    }


    if( chdir( argv[1] ) == 0 ) {
        printf( "Directory changed to %s\n", argv[1] );
        exit(0);

    } else {
        perror( argv[1] );

        exit ( 1 );

    }

}

 

Classification : POSIX 1003.1

Systems : All

 

 

 

 

chmod

 

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.

 Permission   Meaning
 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.

 Permission  Meaning
 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.

 Permission  Meaning
 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.

 Permission  Meaning
 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.  

 Permission  Meaning
 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 does not match the effective group ID or one of the supplementary group IDs, all 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.

 Constant  Meaning
 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

 

 

 

 

chsize

 

Synopsis : #include <io.h> 

              int chsize( int handle, long size );

Description : The chsize function changes the size of the file associated with handle by extending or truncating the file to the length specified by size. If the file needs to be extended, the file is padded with NULL ('\0') characters.

 


Returns : The chsize function returns zero if successful. A return value of -1 indicates an error, ar 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.

 Constant  Meaning
 EBADF  Invalid file handle.
 ENOSPC  Not enough space left on the device to extend the file.

 


See Also : close, creat, open

Example :

#include <stdio.h> 

#include <io.h> 

#include <fcntl.h> 

#include <sys\stat.h>


void main( )

{
    int handle;

 

    handle = open( "file", O_RDWR | O_CREAT,  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );

    if( handle != -1 ) {

        if( chsize ( handle, 32 * 1024L ) != 0 ) {
            printf( "Error extending file\n" );

        }
        close( handle );

    }

}

 

Classification : WATCOM
Systems : All

 

 

 

 

 

 

This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).

 

WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)

 

 

 

728x90
반응형
Posted by 전화카드
,