MCPcopy Index your code
hub / github.com/NetHack/NetHack / mread

Function mread

src/sfstruct.c:548–594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

546/* ===================================================== */
547
548void
549mread(int fd, genericptr_t buf, unsigned len)
550{
551
552#ifdef SFLOGGING
553 if (fd >= 0 && fd < 9) {
554 if (!ifp[fd]) {
555 Snprintf(ifnamebuf, sizeof ifnamebuf, "mread_%02d.log", fd);
556 ifp[fd] = fopen(ifnamebuf, "w");
557 }
558 if (ifp[fd]) {
559 fprintf(ifp[fd], "%08ld, %08ld, %d\n", icnt,
560 ftell(ifp[fd]), (int) len);
561 icnt++;
562 }
563 }
564#endif
565
566#if defined(BSD) || defined(ULTRIX) || defined(WIN32)
567#define readLenType int
568#else /* e.g. SYSV, __TURBOC__ */
569#define readLenType unsigned
570#endif
571 readLenType rlen;
572 /* Not perfect, but we don't have ssize_t available. */
573 rlen = (readLenType) read(fd, buf, (readLenType) len);
574 if ((readLenType) rlen != (readLenType) len) {
575 if ((restoreinfo.mread_flags == 1) /* means "return anyway" */
576 || (program_state.reading_bonesfile == 1)) {
577 restoreinfo.mread_flags = -1;
578 return;
579 } else {
580#ifndef SFCTOOL
581 pline("Read %d instead of %u bytes.", (int) rlen, len);
582 display_nhwindow(WIN_MESSAGE, TRUE); /* flush before error() */
583 if (program_state.restoring) {
584 (void) nhclose(fd);
585 (void) delete_savefile();
586 error("Error restoring old game.");
587 }
588 panic("Error reading level file.");
589#else
590 printf("Read %d instead of %u bytes.\n", (int) rlen, len);
591#endif
592 }
593 }
594}
595
596staticfn void
597sfstruct_read_error(void)

Callers 2

historical_sfi_charFunction · 0.85

Calls 9

fprintfFunction · 0.85
ftellFunction · 0.85
readFunction · 0.85
nhcloseFunction · 0.85
printfFunction · 0.85
plineFunction · 0.70
delete_savefileFunction · 0.70
errorFunction · 0.50
panicFunction · 0.50

Tested by

no test coverage detected