C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
CHMOD1.C
◄Up► ◄Contents► ◄Index► ◄Back►
─────Run-Time Library───────────────────────────────────────────────────────
/* CHMOD1.C illustrates reading and changing file attribute and time
* using functions:
* _access _chmod _utime
*
* See CHMOD2.C for a more powerful variation of this program using
* _dos_ functions.
*/
#include <io.h>
#include <sys\types.h>
#include <sys\stat.h>
#include <sys\utime.h>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
enum FILEATTRIB { EXIST, WRITE = 2, READ = 4, READWRITE = 6 };
/* Macro uses access */
#define EXIST( name ) !_access( name, EXIST )
void main( int argc, char *argv[] )
{
if( !EXIST( argv[1] ) )
{
printf( "Syntax: CHMOD1 <filename>" );
exit( 1 );
}
if( !_access( argv[1], WRITE ) )
{
printf( "File %s is read/write. Change to read only? ", argv[1] );
/* NOTE: Use stdlib.h for function definition of toupper rather
* than macro version in ctype.h. Macro side effects would cause
* macro version to read two keys.
*/
if( toupper( _getche() ) == 'Y' )
_chmod( argv[1], _S_IREAD );
}
else
{
printf( "File %s is read only. Change to read/write? ", argv[1] );
if( toupper( _getch() ) == 'Y' )
_chmod( argv[1], _S_IREAD | _S_IWRITE );
}
printf( "\nUpdate file time to current time? " );
if( toupper( _getche() ) == 'Y' )
_utime( argv[1], NULL );
exit( 0 );
}
-♦-