lock.c 574 B

123456789101112131415161718192021222324252627282930313233
  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$ */
  6. #include "system.h"
  7. int
  8. sys_lock(path)
  9. char *path;
  10. {
  11. char buf[1024];
  12. char *tmpf = ".lockXXXXXX";
  13. char *strrchr(), *strcpy(), *mktemp();
  14. char *p;
  15. int ok, fd;
  16. strcpy(buf, path);
  17. if (p = strrchr(buf, '/')) {
  18. ++p;
  19. strcpy(p, tmpf);
  20. }
  21. else
  22. strcpy(buf, tmpf);
  23. mktemp(buf);
  24. if ((fd = creat(buf, 0)) < 0)
  25. return 0;
  26. close(fd);
  27. ok = (link(buf, path) == 0);
  28. unlink(buf);
  29. return ok;
  30. }