/* ;=======================================================================; ; ; ; ... ... ... ..... ... ... ... ; ; ............. ....... ... ... ... _______________________ ; ; .... ... ... ... ... ... ... ... ; ; ... ... ... ... ... ... ... MORRIS CODE WORKS ; ; ... ... ... ... ... ... ... ; ; ... ... ... ... ... ... ... SYSTEM SOFTWARE FILE ; ; ... ... ... ... ... ... ... ... _______________________ ; ; ... ... ... ....... ........... ; ; ... ... ... ..... .. .. ; ; ; ; ; ;=======================================================================; ; Copyright (c) 1985 by Morris Code Works ; ;=======================================================================; ; ; ; File: touch.c ; ; ; ; Description: UNIX like 'touch' command ; ; ; ; Create Date: 20 Aug 85 ; ; ; ;=======================================================================; ; ; ; Revision History ; ; ; ; When Who Description ; ; --------- --- ---------------------------------------------- ; ; 20 Aug 85 TGM Module created ; ; ; ;=======================================================================; */ #include #include /* * touch - change update time of a file... or * create a null file... * */ main ( argc, argv ) int argc; char *argv[]; { register int fd; /* file descriptor */ char c; /* character read */ /* verify input */ if ( argc < 2 ) { bdos( 9, "usage: touch file ...\r\n$" ); exit ( 1 ); } /* return bdos errors */ bdos( 45, 255 ); /* try to update each filename entered */ while ( --argc ) { /* process each file in turn */ if ( (fd = open ( *++argv, O_RDWR|O_CREAT )) != -1 ) { /* get a single input character... if possible */ if ( read( fd, &c, 1 ) > 0 ) { /* reposition the file to same spot */ (void) lseek ( fd, 0l, 0 ); /* write the character back into the file */ if( write( fd, &c, 1 ) != 1 ) { rpterr( "write", *argv ); continue; } } else { /* NULL file... close and recreate it */ (void) close ( fd ); if( unlink( *argv ) != 0 ) { rpterr( "delete", *argv ); continue; } else fd = open( *argv, O_TRUNC ); } /* close THIS file... */ (void) close ( fd ); } else rpterr( "create", *argv ); } /* restore bdos error mode */ bdos( 45, 0 ); } rpterr( errmsg, name ) /* mention some error about this file */ char *errmsg; /* the specific error type */ char *name; /* the filename causing the error */ { while( *errmsg ) bdos( 2, *errmsg++ ); bdos( 9, " permission denied... file: $" ); while( *name ) bdos( 2, *name++ ); bdos( 9, "\r\n$" ); }