Pristine Ack-5.5
[Ack-5.5.git] / modules / src / system / lock.c
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5 /* $Id: lock.c,v 1.5 1994/06/24 11:24:28 ceriel Exp $ */
6
7 #include <system.h>
8
9 int
10 sys_lock(path)
11         char *path;
12 {
13         char buf[1024];
14         char *tmpf = ".lockXXXXXX";
15         char *strrindex(), *strcpy(), *mktemp();
16         char *p;
17         int ok, fd;
18
19         strcpy(buf, path);
20         if (p = strrindex(buf, '/')) {
21                 ++p;
22                 strcpy(p, tmpf);
23         }
24         else
25                 strcpy(buf, tmpf);
26         mktemp(buf);
27         if ((fd = creat(buf, 0)) < 0)
28                 return 0;
29         close(fd);
30         ok = (link(buf, path) == 0);
31         unlink(buf);
32         return ok;
33 }