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

Function validate_prefix_locations

src/files.c:393–439  ·  view source on GitHub ↗

reasonbuf must be at least BUFSZ, supplied by caller */

Source from the content-addressed store, hash-verified

391#ifndef SFCTOOL
392/* reasonbuf must be at least BUFSZ, supplied by caller */
393int
394validate_prefix_locations(char *reasonbuf)
395{
396#if defined(NOCWD_ASSUMPTIONS)
397 FILE *fp;
398 const char *filename;
399 int prefcnt, failcount = 0;
400 char panicbuf1[BUFSZ], panicbuf2[BUFSZ];
401 const char *details;
402#endif
403
404 if (reasonbuf)
405 reasonbuf[0] = '\0';
406#if defined(NOCWD_ASSUMPTIONS)
407 for (prefcnt = 1; prefcnt < PREFIX_COUNT; prefcnt++) {
408 /* don't test writing to configdir or datadir; they're readonly */
409 if (prefcnt == SYSCONFPREFIX || prefcnt == CONFIGPREFIX
410 || prefcnt == DATAPREFIX)
411 continue;
412 filename = fqname("validate", prefcnt, 3);
413 if ((fp = fopen(filename, "w"))) {
414 fclose(fp);
415 (void) unlink(filename);
416 } else {
417 if (reasonbuf) {
418 if (failcount)
419 Strcat(reasonbuf, ", ");
420 Strcat(reasonbuf, fqn_prefix_names[prefcnt]);
421 }
422 /* the paniclog entry gets the value of errno as well */
423 Sprintf(panicbuf1, "Invalid %s", fqn_prefix_names[prefcnt]);
424#if defined(NHSTDC) && !defined(NOTSTDC)
425 if (!(details = strerror(errno)))
426#endif
427 details = "";
428 Sprintf(panicbuf2, "\"%s\", (%d) %s",
429 gf.fqn_prefix[prefcnt], errno, details);
430 paniclog(panicbuf1, panicbuf2);
431 failcount++;
432 }
433 }
434 if (failcount)
435 return 0;
436 else
437#endif
438 return 1;
439}
440
441/* fopen a file, with OS-dependent bells and whistles */
442/* NOTE: a simpler version of this routine also exists in util/dlb_main.c */

Callers 2

MAINFunction · 0.85
pcmainFunction · 0.85

Calls 4

fqnameFunction · 0.85
fcloseFunction · 0.85
unlinkFunction · 0.85
paniclogFunction · 0.85

Tested by

no test coverage detected