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

Function viable_nhfile

src/files.c:548–579  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

546
547#ifndef SFCTOOL
548staticfn NHFILE *
549viable_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
582int

Callers 6

create_levelfileFunction · 0.85
open_levelfileFunction · 0.85
create_bonesfileFunction · 0.85
open_bonesfileFunction · 0.85
create_savefileFunction · 0.85
open_savefileFunction · 0.85

Calls 3

fcloseFunction · 0.85
fprintfFunction · 0.85
free_nhfileFunction · 0.85

Tested by

no test coverage detected