tlim@yetti.UUCP (Terry Lim) (09/06/85)
/* touch.c by Terry Lim York University utzoo!yetti!tlim 26-Aug-1985 For use in the Aztec C environment. If you go into a source file using Edit and quit without making any changes, make will get confused and recompile the undisturbed file. Touch the .o file to prevent this. The program brings a file's "time of last modification" up to date by copying the current system time from RAM into the file header. Multiple files and wildcards are possible, per courtesy of the Aztec C shell. However, no current working directory is assumed so you have to specify entire path names. */ #include <stdio.h> #include <pb.h> #include <osutil.h> main(argc,argv) int argc; char *argv[]; { OSErr err; /*result of touch() call*/ int i; /*step through argv[]*/ if (argc<2) /*no arguments*/ fprintf(stderr,"touch what?\n"); else for (i=1; i<argc; i++) switch(err=touch(argv[i])) { case 0: /*success*/ continue; case -43: /*file not found*/ fprintf(stderr, "touch: '%s' not found.\n", argv[i],err); continue; default: /*other errors*/ fprintf(stderr, "touch: error touching %s (%d).\n", argv[i],err); continue; } } OSErr touch(what) char *what; { struct ParamBlkRec parm,*parmptr; long time; OSErr result; char name[40]; parmptr= &parm; /*get address of allocated block*/ strcpy(name,what); /*copy string or ctop will clobber it*/ parmptr->ioNamePtr=(StringPtr)ctop(name); parmptr->ioVRefNum=0; /*default volume*/ parmptr->u.iop.ioVersNum=0; /*must be zero*/ parmptr->u.fp.ioFDirIndex=0; /*don't use file number*/ if (result=PBGetFInfo(parmptr,FALSE)) return result; GetDateTime(&time); parmptr->u.fp.ioFlMdDat=time; /*reset time of last modification*/ if (result=PBSetFInfo(parmptr,FALSE)) return result; return 0; /*if we got here, all's well*/ }