dsf@allegra.UUCP (David Fox) (04/13/87)
I am sure I saw something about this somewhere, but I can't find it now. The question is, how can I set the modification date on a file? I need this in order to copy directories from floppy to vd0: and not have make think everything is messed up, and so I only have to copy the files that changed back onto the floppies. I plan to add the -p (preserve date) flag to the copy command in the shell. David Fox allegra!dsf
phillip@cbmvax.UUCP (04/13/87)
in article <6597@allegra.UUCP>, dsf@allegra.UUCP (David Fox) says: > > I am sure I saw something about this somewhere, but I can't find it > now. The question is, how can I set the modification date on a file? >....... > David Fox > allegra!dsf This was posted on BIX a while back...I don't know if it made it here...anyway here it is... -phil (Phillip Lindsay) ----------------------cut here--------------------------------- /* touch.c by Phil Lindsay and Andy Finkel */ /* (c) 1986 Commodore-Amiga, Inc. */ /* Permission to use in any way granted, as long as */ /* the copyright notice stays intact */ #include "exec/types.h" #include "exec/ports.h" #include "exec/io.h" #include "exec/memory.h" #include "libraries/dos.h" #include "libraries/dosextens.h" extern LONG sendpkt(); extern int strcpy(); extern int strlen(); #define ACTION_SET_DATE 34 #define DOSTRUE -1 main(argc,argv) int argc; char *argv[]; { struct MsgPort *task; LONG arg[4]; LONG rc; ULONG dateStamp[3]; ULONG lock; ULONG plock; UBYTE *pointer; if(argc!=2) { puts("Bad argument\n"); cleanup(20); } if( !(pointer= (UBYTE *)AllocMem(64,MEMF_PUBLIC)))cleanup(pointer,20); if(!(task=(struct MsgPort *)DeviceProc(argv[1])))cleanup(pointer,20); if(!(lock = (ULONG) Lock(argv[1],SHARED_LOCK)))cleanup(pointer,20); plock = (ULONG) ParentDir(lock); UnLock(lock); strcpy((pointer + 1),argv[1]); *pointer = strlen(argv[1]); arg[0]= NULL; arg[1]= plock; arg[2]= (ULONG) &pointer[0] >> 2; /* BSTR of filename */ arg[3]= (ULONG) DateStamp(dateStamp); /* DateStamp */ rc = sendpkt(task,ACTION_SET_DATE,arg,4); UnLock(plock); if(!rc) cleanup(pointer,20); cleanup(pointer,0); } cleanup(pointer,code) UBYTE *pointer; LONG code; { if(pointer)FreeMem(pointer,64); exit(code); } LONG sendpkt(id,type,args,nargs) struct MsgPort *id; /* process indentifier ... (handlers message port ) */ LONG type, /* packet type ... (what you want handler to do ) */ args[], /* a pointer to a argument list */ nargs; /* number of arguments in list */ { struct MsgPort *replyport; struct StandardPacket *packet; LONG count, *pargs, res1=NULL; if(!(replyport = (struct MsgPort *) CreatePort(NULL,NULL)))return(NULL); packet=(struct StandardPacket *) AllocMem((LONG)sizeof(*packet),MEMF_PUBLIC|MEMF_CLEAR); if(packet) { packet->sp_Msg.mn_Node.ln_Name = &(packet->sp_Pkt); /*link packet */ packet->sp_Pkt.dp_Link = &(packet->sp_Msg); /* to message */ packet->sp_Pkt.dp_Port = replyport; /* set-up reply port */ packet->sp_Pkt.dp_Type = type; /* what to do... */ /* move all the arguments to the packet */ pargs = &(packet->sp_Pkt.dp_Arg1); /* address of first argument */ for(count=0; (count < nargs) && (count < 7); count++)pargs[count]=args[count]; PutMsg(id,packet); /* send packet */ WaitPort(replyport); /* wait for packet to come back */ GetMsg(replyport); /* pull message */ res1 = packet->sp_Pkt.dp_Res1; /* get result */ FreeMem(packet,(LONG)sizeof(*packet)); } DeletePort(replyport); return(res1); } int strcpy( to, from ) register char *to, *from; { do { *to++ = *from; } while( *from++ ); } int strlen( s ) register char *s; { register i = 0; while( *s++ ) i++; return( i ); } /* eof */
hadeishi@husc7.HARVARD.EDU (Mitsuharu Hadeishi) (04/13/87)
In <6597@allegra.UUCP> dsf@allegra.UUCP (David Fox) writes: >I am sure I saw something about this somewhere, but I can't find it >now. The question is, how can I set the modification date on a file? >I need this in order to copy directories from floppy to vd0: and >not have make think everything is messed up, and so I only have to copy >the files that changed back onto the floppies. I plan to add the >-p (preserve date) flag to the copy command in the shell. A few ways of doing it: the easiest is to use the SetFileDate action, a new AmigaDOS packet action. It's documented in the 1.2 AmigaDOS autodocs, I think. At least it's in the 1.2 changes section of the 1.2 Gamma 1 documentation. But a quick and dirty way to do this, assuming your files are up to date to start with, is to do a copy df1:source/Makefile vd0:source copy df1:source/#?.(c|h) vd0:source copy df1:source/#?.o vd0:source This is what I usually do (since I almost always terminate a programming session by recompiling my code to make sure it at least compiles properly, since I don't like to take off from the middle of an editing session.) And, of course, in the Makefile, after each compile, I have a copy sourcefile.h vd0:source copy sourcefile.c vd0:source copy sourcefile.o vd0:source to automagically keep my floppy record updated. (I typically have a header file for most of my source files for exported variables.) -Mitsu