| 2462 | /* ---------- BEGIN WIZKIT FILE HANDLING ----------- */ |
| 2463 | |
| 2464 | staticfn FILE * |
| 2465 | fopen_wizkit_file(void) |
| 2466 | { |
| 2467 | FILE *fp; |
| 2468 | #if defined(VMS) || defined(UNIX) |
| 2469 | char tmp_wizkit[BUFSZ]; |
| 2470 | #endif |
| 2471 | char *envp; |
| 2472 | |
| 2473 | envp = nh_getenv("WIZKIT"); |
| 2474 | if (envp && *envp) |
| 2475 | (void) strncpy(gw.wizkit, envp, WIZKIT_MAX - 1); |
| 2476 | if (!gw.wizkit[0]) |
| 2477 | return (FILE *) 0; |
| 2478 | |
| 2479 | #ifdef UNIX |
| 2480 | if (access(gw.wizkit, 4) == -1) { |
| 2481 | /* 4 is R_OK on newer systems */ |
| 2482 | /* nasty sneaky attempt to read file through |
| 2483 | * NetHack's setuid permissions -- this is a |
| 2484 | * place a file name may be wholly under the player's |
| 2485 | * control |
| 2486 | */ |
| 2487 | raw_printf("Access to %s denied (%d).", gw.wizkit, errno); |
| 2488 | wait_synch(); |
| 2489 | /* fall through to standard names */ |
| 2490 | } else |
| 2491 | #endif |
| 2492 | if ((fp = fopen(gw.wizkit, "r")) != (FILE *) 0) { |
| 2493 | return fp; |
| 2494 | #if defined(UNIX) || defined(VMS) |
| 2495 | } else { |
| 2496 | /* access() above probably caught most problems for UNIX */ |
| 2497 | raw_printf("Couldn't open requested wizkit file %s (%d).", gw.wizkit, |
| 2498 | errno); |
| 2499 | wait_synch(); |
| 2500 | #endif |
| 2501 | } |
| 2502 | |
| 2503 | #if defined(MICRO) || defined(MACOS9) || defined(__BEOS__) || defined(WIN32) |
| 2504 | if ((fp = fopen(fqname(gw.wizkit, CONFIGPREFIX, 0), "r")) != (FILE *) 0) |
| 2505 | return fp; |
| 2506 | #else |
| 2507 | #ifdef VMS |
| 2508 | envp = nh_getenv("HOME"); |
| 2509 | if (envp) |
| 2510 | Sprintf(tmp_wizkit, "%s%s", envp, gw.wizkit); |
| 2511 | else |
| 2512 | Sprintf(tmp_wizkit, "%s%s", "sys$login:", gw.wizkit); |
| 2513 | if ((fp = fopen(tmp_wizkit, "r")) != (FILE *) 0) |
| 2514 | return fp; |
| 2515 | #else /* should be only UNIX left */ |
| 2516 | envp = nh_getenv("HOME"); |
| 2517 | if (envp) |
| 2518 | Sprintf(tmp_wizkit, "%s/%s", envp, gw.wizkit); |
| 2519 | else |
| 2520 | Strcpy(tmp_wizkit, gw.wizkit); |
| 2521 | if ((fp = fopen(tmp_wizkit, "r")) != (FILE *) 0) |
no test coverage detected