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

Function open_bonesfile

src/files.c:939–990  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

937}
938
939NHFILE *
940open_bonesfile(d_level *lev, char **bonesid)
941{
942 const char *fq_bones;
943 NHFILE *nhfp = (NHFILE *) 0;
944#if defined(WIN32)
945 errno_t err UNUSED;
946#endif
947
948 *bonesid = set_bonesfile_name(gb.bones, lev);
949 fq_bones = fqname(gb.bones, BONESPREFIX, 0);
950 nh_uncompress(fq_bones); /* no effect if nonexistent */
951
952 nhfp = new_nhfile();
953 if (nhfp) {
954#if defined(WIN32) && defined(DEBUG)
955 if (nhfp->fd >= 0)
956 impossible("bones file NHFILE * has odd fd (%d)", nhfp->fd);
957#endif
958 nhfp->structlevel = TRUE;
959 nhfp->fieldlevel = FALSE;
960 nhfp->ftype = NHF_BONESFILE;
961 nhfp->mode = READING;
962 nhfp->addinfo = TRUE;
963 nhfp->style.deflt = TRUE;
964 nhfp->style.binary = (sysopt.bonesformat[0] != exportascii);
965 nhfp->fnidx = sysopt.bonesformat[0];
966 nhfp->fd = -1;
967 nhfp->fpdef = (FILE *) 0;
968 if (nhfp->fpdef) {
969#ifdef SAVEFILE_DEBUGGING
970 nhfp->fpdebug = fopen("open_bonesfile-debug.log", "a");
971#endif
972 }
973 if (nhfp->structlevel) {
974#if defined(MACOS9)
975 nhfp->fd = macopen(fq_bones, O_RDONLY | O_BINARY, BONE_TYPE);
976#elif defined(WIN32)
977 err = _sopen_s(&nhfp->fd, fq_bones, _O_RDONLY | _O_BINARY,
978 _SH_DENYRW, _S_IREAD | _S_IWRITE);
979#else
980 nhfp->fd = open(fq_bones, O_RDONLY | O_BINARY, 0);
981#endif
982#if defined(MSDOS) || defined(WIN32)
983 if (nhfp->fd >= 0)
984 (void) setmode(nhfp->fd, O_BINARY);
985#endif
986 }
987 }
988 nhfp = viable_nhfile(nhfp);
989 return nhfp;
990}
991
992int
993delete_bonesfile(d_level *lev)

Callers 2

savebonesFunction · 0.85
getbonesFunction · 0.85

Calls 8

set_bonesfile_nameFunction · 0.85
fqnameFunction · 0.85
nh_uncompressFunction · 0.85
new_nhfileFunction · 0.85
macopenFunction · 0.85
openFunction · 0.85
viable_nhfileFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected