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

Function fopenp

sys/share/pcsys.c:191–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189#endif
190
191FILE *
192fopenp(const char *name, const char *mode)
193{
194 char buf[BUFSIZ], *bp, *pp, lastch = 0;
195 FILE *fp;
196
197 /* Try the default directory first. Then look along PATH.
198 */
199 (void) strncpy(buf, name, BUFSIZ - 1);
200 buf[BUFSIZ - 1] = '\0';
201 if ((fp = fopen(buf, mode)))
202 return fp;
203 else {
204 int ccnt = 0;
205 pp = getenv("PATH");
206 while (pp && *pp) {
207 bp = buf;
208 while (*pp && *pp != PATHSEP) {
209 lastch = *bp++ = *pp++;
210 ccnt++;
211 }
212 if (lastch != '\\' && lastch != '/') {
213 *bp++ = '\\';
214 ccnt++;
215 }
216 (void) strncpy(bp, name, (BUFSIZ - ccnt) - 2);
217 bp[BUFSIZ - ccnt - 1] = '\0';
218 if ((fp = fopen(buf, mode)))
219 return fp;
220 if (*pp)
221 pp++;
222 }
223 }
224#ifdef OS2_CODEVIEW /* one more try for hackdir */
225 (void) strncpy(buf, hackdir, BUFSZ);
226 buf[BUFSZ - 1] = '\0';
227 if ((strlen(name) + 1 + strlen(buf)) < BUFSZ - 1) {
228 append_slash(buf);
229 Strcat(buf, name);
230 } else
231 impossible("fopenp() buffer too small for complete filename!");
232 if (fp = fopen(buf, mode))
233 return fp;
234#endif
235 return (FILE *) 0;
236}
237
238#if defined(MICRO) || defined(OS2)
239void

Callers

nothing calls this directly

Calls 2

append_slashFunction · 0.70
impossibleFunction · 0.50

Tested by

no test coverage detected