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

Function create_levelfile

src/files.c:620–670  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

618}
619
620NHFILE *
621create_levelfile(int lev, char errbuf[])
622{
623 const char *fq_lock;
624 NHFILE *nhfp = (NHFILE *) 0;
625
626 if (errbuf)
627 *errbuf = '\0';
628 set_levelfile_name(gl.lock, lev);
629 fq_lock = fqname(gl.lock, LEVELPREFIX, 0);
630
631 nhfp = new_nhfile();
632 if (nhfp) {
633 nhfp->ftype = NHF_LEVELFILE;
634 nhfp->mode = WRITING;
635 nhfp->structlevel = TRUE; /* do set this TRUE for levelfiles */
636 nhfp->fieldlevel = FALSE; /* don't set this TRUE for levelfiles */
637 nhfp->addinfo = FALSE;
638 nhfp->style.deflt = FALSE;
639 nhfp->style.binary = TRUE;
640 nhfp->fnidx = historical;
641 nhfp->fd = -1;
642 nhfp->fpdef = (FILE *) 0;
643#if defined(MICRO) || defined(WIN32)
644 /* Use O_TRUNC to force the file to be shortened if it already
645 * exists and is currently longer.
646 */
647 nhfp->fd = open(fq_lock, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
648 FCMASK);
649#else
650#ifdef MACOS9
651 nhfp->fd = maccreat(fq_lock, LEVL_TYPE);
652#else
653 nhfp->fd = creat(fq_lock, FCMASK);
654#endif
655#endif /* MICRO || WIN32 */
656
657 if (nhfp->fd >= 0)
658 svl.level_info[lev].flags |= LFILE_EXISTS;
659 else if (errbuf) /* failure explanation */
660 Sprintf(errbuf,
661 "Cannot create file \"%s\" for level %d (errno %d).",
662 gl.lock, lev, errno);
663#if defined(MSDOS) || defined(WIN32)
664 if (nhfp->fd >= 0)
665 (void) setmode(nhfp->fd, O_BINARY);
666#endif
667 }
668 nhfp = viable_nhfile(nhfp);
669 return nhfp;
670}
671
672NHFILE *
673open_levelfile(int lev, char errbuf[])

Callers 5

MAINFunction · 0.85
pcmainFunction · 0.85
currentlevel_rewriteFunction · 0.85
restlevelfileFunction · 0.85
savestateinlockFunction · 0.85

Calls 7

fqnameFunction · 0.85
new_nhfileFunction · 0.85
openFunction · 0.85
maccreatFunction · 0.85
creatFunction · 0.85
viable_nhfileFunction · 0.85
set_levelfile_nameFunction · 0.70

Tested by

no test coverage detected