MCPcopy Create free account
hub / github.com/NetHack/NetHack / getlock

Function getlock

sys/vms/vmsunix.c:98–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98void
99getlock(void)
100{
101 int i = 0, fd;
102
103 /* idea from rpick%ucqais@uccba.uc.edu
104 * prevent automated rerolling of characters
105 * test input (fd0) so that tee'ing output to get a screen dump still
106 * works
107 * also incidentally prevents development of any hack-o-matic programs
108 */
109 if (isatty(0) <= 0)
110 error("You must play from a terminal.");
111
112 /* we ignore QUIT and INT at this point */
113 if (!lock_file(HLOCK, LOCKPREFIX, 10)) {
114 wait_synch();
115 error("Quitting.");
116 }
117
118 /* default value of gl.lock[] is "1lock" where '1' gets changed to
119 'a','b',&c below; override the default and use <uid><charname>
120 if we aren't restricting the number of simultaneous games */
121 if (!gl.locknum)
122 Sprintf(gl.lock, "_%u%s", (unsigned) getuid(), svp.plname);
123
124 regularize(gl.lock);
125 set_levelfile_name(gl.lock, 0);
126 if (gl.locknum > 25)
127 gl.locknum = 25;
128
129 do {
130 if (gl.locknum)
131 gl.lock[0] = 'a' + i++;
132
133 if ((fd = open(gl.lock, 0, 0)) == -1) {
134 if (errno == ENOENT)
135 goto gotlock; /* no such file */
136 perror(gl.lock);
137 unlock_file(HLOCK);
138 error("Cannot open %s", gl.lock);
139 }
140
141 if (veryold(fd)) /* if true, this closes fd and unlinks lock */
142 goto gotlock;
143 (void) close(fd);
144 } while (i < gl.locknum);
145
146 unlock_file(HLOCK);
147 error(gl.locknum ? "Too many hacks running now."
148 : "There is a game in progress under your name.");
149
150 gotlock:
151 fd = creat(gl.lock, FCMASK);
152 unlock_file(HLOCK);
153 if (fd == -1) {
154 error("cannot creat lock file.");
155 } else {

Callers 2

mainFunction · 0.70
libnhmain.cFile · 0.50

Calls 12

isattyFunction · 0.85
wait_synchFunction · 0.85
getuidFunction · 0.85
openFunction · 0.85
unlock_fileFunction · 0.85
closeFunction · 0.85
creatFunction · 0.85
writeFunction · 0.85
regularizeFunction · 0.70
veryoldFunction · 0.70
errorFunction · 0.50
set_levelfile_nameFunction · 0.50

Tested by

no test coverage detected