OSDN Git Service

import nethack-3.6.0
[jnethack/source.git] / sys / mac / macunix.c
1 /* NetHack 3.6  macunix.c       $NHDT-Date: 1432512797 2015/05/25 00:13:17 $  $NHDT-Branch: master $:$NHDT-Revision: 1.10 $ */
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed.  See license for details. */
4
5 /* This file collects some Unix dependencies */
6
7 #include "hack.h"
8
9 void
10 regularize(char *s)
11 {
12     register char *lp;
13
14     for (lp = s; *lp; lp++) {
15         if (*lp == '.' || *lp == ':')
16             *lp = '_';
17     }
18 }
19
20 void
21 getlock(void)
22 {
23     int fd;
24     int pid = getpid(); /* Process ID */
25
26     Sprintf(lock, "%d%s", getuid(), plname);
27     set_levelfile_name(lock, 0);
28
29     if ((fd = open(lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) {
30         raw_printf("Could not lock the game %s.", lock);
31         panic("Another game in progress?");
32     }
33
34     if (write(fd, (char *) &pid, sizeof(pid)) != sizeof(pid)) {
35         raw_printf("Could not lock the game %s.", lock);
36         panic("Disk locked?");
37     }
38     close(fd);
39 }