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

Function open_levelfile

src/files.c:672–716  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

670}
671
672NHFILE *
673open_levelfile(int lev, char errbuf[])
674{
675 const char *fq_lock;
676 NHFILE *nhfp = (NHFILE *) 0;
677
678 if (errbuf)
679 *errbuf = '\0';
680 set_levelfile_name(gl.lock, lev);
681 fq_lock = fqname(gl.lock, LEVELPREFIX, 0);
682 nhfp = new_nhfile();
683 if (nhfp) {
684 nhfp->mode = READING;
685 nhfp->structlevel = TRUE; /* do set this TRUE for levelfiles */
686 nhfp->fieldlevel = FALSE; /* do not set this TRUE for levelfiles */
687 nhfp->addinfo = FALSE;
688 nhfp->style.deflt = FALSE;
689 nhfp->style.binary = TRUE;
690 nhfp->ftype = NHF_LEVELFILE;
691 nhfp->fnidx = historical;
692 nhfp->fd = -1;
693 nhfp->fpdef = (FILE *) 0;
694 }
695 if (nhfp && nhfp->structlevel) {
696#ifdef MACOS9
697 nhfp->fd = macopen(fq_lock, O_RDONLY | O_BINARY, LEVL_TYPE);
698#else
699 nhfp->fd = open(fq_lock, O_RDONLY | O_BINARY, 0);
700#endif
701
702 /* for failure, return an explanation that our caller can use;
703 settle for `lock' instead of `fq_lock' because the latter
704 might end up being too big for nethack's BUFSZ */
705 if (nhfp->fd < 0 && errbuf)
706 Sprintf(errbuf,
707 "Cannot open file \"%s\" for level %d (errno %d).",
708 gl.lock, lev, errno);
709#if defined(MSDOS) || defined(WIN32)
710 if (nhfp->fd >= 0)
711 (void) setmode(nhfp->fd, O_BINARY);
712#endif
713 }
714 nhfp = viable_nhfile(nhfp);
715 return nhfp;
716}
717
718void
719delete_levelfile(int lev)

Callers 4

goto_levelFunction · 0.70
recover_savefileFunction · 0.70
dosave0Function · 0.70
savestateinlockFunction · 0.70

Calls 6

fqnameFunction · 0.85
new_nhfileFunction · 0.85
macopenFunction · 0.85
openFunction · 0.85
viable_nhfileFunction · 0.85
set_levelfile_nameFunction · 0.70

Tested by

no test coverage detected