| 546 | |
| 547 | #ifndef SFCTOOL |
| 548 | staticfn NHFILE * |
| 549 | viable_nhfile(NHFILE *nhfp) |
| 550 | { |
| 551 | /* perform some sanity checks before returning |
| 552 | the pointer to the nethack file descriptor */ |
| 553 | if (nhfp) { |
| 554 | /* check for no open file at all, |
| 555 | * not a structlevel legacy file, |
| 556 | * nor a fieldlevel file. |
| 557 | */ |
| 558 | if (((nhfp->fd == -1) && !nhfp->fpdef) |
| 559 | || (nhfp->structlevel && nhfp->fd < 0) |
| 560 | || (nhfp->fieldlevel && !nhfp->fpdef)) { |
| 561 | /* not viable, start the cleanup */ |
| 562 | if (nhfp->fieldlevel) { |
| 563 | if (nhfp->fpdef) { |
| 564 | (void) fclose(nhfp->fpdef); |
| 565 | nhfp->fpdef = (FILE *) 0; |
| 566 | } |
| 567 | if (nhfp->fplog) { |
| 568 | (void) fprintf(nhfp->fplog, "# closing, not viable\n"); |
| 569 | (void) fclose(nhfp->fplog); |
| 570 | } |
| 571 | if (nhfp->fpdebug) |
| 572 | (void) fclose(nhfp->fpdebug); |
| 573 | } |
| 574 | free_nhfile(nhfp); |
| 575 | nhfp = (NHFILE *) 0; |
| 576 | } |
| 577 | } |
| 578 | return nhfp; |
| 579 | } |
| 580 | #endif /* !SFCTOOL */ |
| 581 | |
| 582 | int |
no test coverage detected