| 2422 | } |
| 2423 | |
| 2424 | void |
| 2425 | tty_display_file( |
| 2426 | const char *fname, /* name of file to display */ |
| 2427 | boolean complain) /* whether to report problem if file can't be opened */ |
| 2428 | { |
| 2429 | #ifdef DEF_PAGER /* this implies that UNIX is defined */ |
| 2430 | /* FIXME: this won't work if fname is inside a dlb container */ |
| 2431 | { |
| 2432 | /* use external pager; this may give security problems */ |
| 2433 | int fd = open(fname, O_RDONLY); |
| 2434 | |
| 2435 | if (fd < 0) { |
| 2436 | if (complain) |
| 2437 | pline("Cannot open %s.", fname); |
| 2438 | else /* [is this refresh actually necessary?] */ |
| 2439 | docrt(); |
| 2440 | return; |
| 2441 | } |
| 2442 | if (child(1)) { |
| 2443 | /* Now that child() does a setuid(getuid()) and a chdir(), |
| 2444 | we may not be able to open file fname anymore, so make |
| 2445 | it stdin. */ |
| 2446 | (void) close(0); |
| 2447 | if (dup(fd)) { |
| 2448 | if (complain) |
| 2449 | raw_printf("Cannot open %s as stdin.", fname); |
| 2450 | } else { |
| 2451 | (void) execlp(gc.catmore, "page", (char *) 0); |
| 2452 | if (complain) |
| 2453 | raw_printf("Cannot exec %s.", gc.catmore); |
| 2454 | } |
| 2455 | if (complain) |
| 2456 | sleep(10); /* want to wait_synch() but stdin is gone */ |
| 2457 | nh_terminate(EXIT_FAILURE); |
| 2458 | } |
| 2459 | (void) close(fd); |
| 2460 | } |
| 2461 | #else /* DEF_PAGER */ |
| 2462 | { |
| 2463 | dlb *f; |
| 2464 | char buf[BUFSZ]; |
| 2465 | char *cr; |
| 2466 | |
| 2467 | tty_clear_nhwindow(WIN_MESSAGE); |
| 2468 | f = dlb_fopen(fname, "r"); |
| 2469 | if (!f) { |
| 2470 | if (complain) { |
| 2471 | home(); |
| 2472 | tty_mark_synch(); |
| 2473 | tty_raw_print(""); |
| 2474 | perror(fname); |
| 2475 | tty_wait_synch(); /* "Hit <space> to continue: " */ |
| 2476 | if (u.ux) /* if hero is on map, refresh the screen */ |
| 2477 | docrt(); |
| 2478 | pline("Cannot open \"%s\".", fname); |
| 2479 | } |
| 2480 | } else { |
| 2481 | winid datawin = tty_create_nhwindow(NHW_TEXT); |
nothing calls this directly
no test coverage detected