File: macunix.c

package info (click to toggle)
nethack 3.4.3-10.6
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 13,644 kB
  • ctags: 16,957
  • sloc: ansic: 196,792; cpp: 7,083; sh: 6,887; yacc: 2,005; lex: 377; makefile: 112; awk: 89; sed: 11
file content (38 lines) | stat: -rw-r--r-- 803 bytes parent folder | download | duplicates (23)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*	SCCS Id: @(#)macunix.c	3.1	94/11/07	*/
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
/* NetHack may be freely redistributed.  See license for details. */

/* This file collects some Unix dependencies */

#include "hack.h"

void
regularize(char *s)
{
	register char *lp;

	for (lp = s; *lp; lp++) {
		if (*lp == '.' || *lp == ':')
			*lp = '_';
	}
}

void
getlock(void)
{
	int fd;
	int pid = getpid(); /* Process ID */
	
	set_levelfile_name (lock, 0);

	if ((fd = open (lock, O_RDWR | O_EXCL | O_CREAT, LEVL_TYPE)) == -1) {
		raw_printf ("Could not lock the game %s.", lock);
		panic ("Another game in progress?");
	}

	if (write (fd, (char *)&pid, sizeof (pid)) != sizeof (pid))  {
		raw_printf ("Could not lock the game %s.", lock);
		panic("Disk locked?");
	}
	close (fd);
}