/* * bauble: a tiny room-based messaging system * * lock: person/system/tty locking. */ #include #if OS2|MSDOS #define S_IREAD 0444 #define S_IWRITE 0222 #endif #include "news.h" extern char *basename(); /* * mklock() constructs a lockname */ static char * mklock(thing) char *thing; { static char lockname[128]; makepath(lockname, SPOOL, "@%s.lck", thing); #if GEMDOS|MSDOS|OS2 { register char *s; for (s=lockname+strlen(SPOOL); *s; s++) if (*s == ':') *s = '!'; } #endif return lockname; } /* mklock */ /* * lock() puts a lock on someone */ lock(thing) char *thing; { register char *lock = mklock(thing); register fd; if ((fd=open(lock, O_RDWR|O_EXCL|O_CREAT, S_IREAD|S_IWRITE)) >= 0) { close(fd); return 1; } return 0; } /* * unlock() lifts the lock on someone */ unlock(thing) char *thing; { unlink(mklock(thing)); }