Utilities 3 (Disk 38) (Mar 1987) : c / touch.c

/* 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 			*/

/* From: 3585.comp-sys-amiga */

#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 */