MCPcopy Index your code
hub / github.com/NetHack/NetHack / getlock

Function getlock

sys/unix/unixunix.c:102–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void
103getlock(void)
104{
105#ifndef SELF_RECOVER
106 static const char destroy_old_game_prompt[] =
107 "There is already a game in progress under your name. Destroy old game?";
108#endif
109 int i = 0, fd, c, too_old;
110 const char *fq_lock;
111
112#ifdef TTY_GRAPHICS
113 /* idea from rpick%ucqais@uccba.uc.edu
114 * prevent automated rerolling of characters
115 * test input (fd0) so that tee'ing output to get a screen dump still
116 * works
117 * also incidentally prevents development of any hack-o-matic programs
118 */
119 /* added check for window-system type -dlc */
120 if (!strcmp(windowprocs.name, "tty"))
121 if (!isatty(0))
122 error("You must play from a terminal.");
123#endif
124
125 /* we ignore QUIT and INT at this point */
126 if (!lock_file(HLOCK, LOCKPREFIX, 10)) {
127 wait_synch();
128 error("%s", "");
129 }
130
131 /* default value of gl.lock[] is "1lock" where '1' gets changed to
132 'a','b',&c below; override the default and use <uid><charname>
133 if we aren't restricting the number of simultaneous games */
134 if (!gl.locknum)
135 Sprintf(gl.lock, "%u%s", (unsigned) getuid(), svp.plname);
136
137 regularize(gl.lock);
138 set_levelfile_name(gl.lock, 0);
139
140 if (gl.locknum) {
141 if (gl.locknum > 25)
142 gl.locknum = 25;
143
144 do {
145 gl.lock[0] = 'a' + i++;
146 fq_lock = fqname(gl.lock, LEVELPREFIX, 0);
147
148 if ((fd = open(fq_lock, 0)) == -1) {
149 if (errno == ENOENT)
150 goto gotlock; /* no such file */
151 perror(fq_lock);
152 unlock_file(HLOCK);
153 error("Cannot open %s", fq_lock);
154 }
155
156 /* veryold() no longer conditionally closes fd */
157 too_old = veryold(fd);
158 (void) close(fd);
159 if (too_old && eraseoldlocks())

Callers 1

mainFunction · 0.70

Calls 15

isattyFunction · 0.85
wait_synchFunction · 0.85
getuidFunction · 0.85
fqnameFunction · 0.85
openFunction · 0.85
unlock_fileFunction · 0.85
closeFunction · 0.85
yn_functionFunction · 0.85
fflushFunction · 0.85
recover_savefileFunction · 0.85
creatFunction · 0.85
writeFunction · 0.85

Tested by

no test coverage detected