| 546 | /* ===================================================== */ |
| 547 | |
| 548 | void |
| 549 | mread(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 | |
| 596 | staticfn void |
| 597 | sfstruct_read_error(void) |