16 #define LOCKDIR "/tmp/" /* or /usr/tmp/ as the case may be */
18 #define NAPTIME (unsigned int)5
20 PRIVATE
_PROTOTYPE( char *lockpath
, (char *name
));
21 _PROTOTYPE( void syserr
, (char *errstring
));
22 _PROTOTYPE( BOOLEAN lock
, (char *name
));
23 _PROTOTYPE( void unlock
, (char *name
));
29 fprintf(stderr
,"couldn't %s\n", errstring
);
33 BOOLEAN
lock(name
) /* acquire lock */
39 path
= lockpath(name
);
41 while ((fd
= creat(path
, 0)) == -1 && errno
== EACCES
) {
42 if (++tries
>= MAXTRIES
) return(False
);
45 if (fd
== -1 || close(fd
) == -1) syserr("lock");
49 void unlock(name
) /* free lock */
52 if (unlink(lockpath(name
)) == -1) syserr("unlock");
55 PRIVATE
char *lockpath(name
) /* generate lock file path */
58 PRIVATE
char path
[20];
60 strcpy(path
, LOCKDIR
);
61 return(strcat(path
, name
));