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

Function bwrite

src/sfstruct.c:493–544  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491}
492
493void
494bwrite(int fd, const genericptr_t loc, unsigned num)
495{
496 boolean failed;
497 int idx = getidx(fd, NOFLG);
498
499#ifdef SFLOGGING
500 if (fd >= 0 && fd < SIZE(ofp)) {
501 if (!ofp[fd]) {
502 Snprintf(ofnamebuf, sizeof ofnamebuf, "bwrite_%02d.log", fd);
503 ofp[fd] = fopen(ofnamebuf, "w");
504 }
505 if (ofp[fd]) {
506 fprintf(ofp[fd], "%08ld, %08ld, %d\n", ocnt,
507 ftell(ofp[fd]), num);
508 ocnt++;
509 }
510 }
511#endif
512
513 if (idx >= 0) {
514 if (num == 0) {
515 /* nothing to do; we need a special case to exit early
516 because glibc fwrite doesn't give reliable
517 success/failure indication when writing 0 bytes */
518 return;
519 }
520
521#ifdef USE_BUFFERING
522 if (bw_buffered[idx] && bw_FILE[idx]) {
523 failed = (fwrite(loc, (int) num, 1, bw_FILE[idx]) != 1);
524 } else
525#endif /* UNIX */
526 {
527 /* lint wants 3rd arg of write to be an int; lint -p an unsigned */
528#if defined(BSD) || defined(ULTRIX) || defined(WIN32) || defined(_MSC_VER)
529 failed = ((long) write(fd, loc, (int) num) != (long) num);
530#else /* e.g. SYSV, __TURBOC__ */
531 failed = ((long) write(fd, loc, num) != (long) num);
532#endif
533 }
534 if (failed) {
535#if defined(HANGUPHANDLING)
536 if (program_state.done_hup)
537 nh_terminate(EXIT_FAILURE);
538 else
539#endif
540 panic("cannot write %u bytes to file #%d", num, fd);
541 }
542 } else
543 impossible("fd not in list (%d)?", fd);
544}
545
546/* ===================================================== */
547

Callers 2

historical_sfo_charFunction · 0.85

Calls 8

getidxFunction · 0.85
fprintfFunction · 0.85
ftellFunction · 0.85
fwriteFunction · 0.85
writeFunction · 0.85
nh_terminateFunction · 0.70
impossibleFunction · 0.70
panicFunction · 0.50

Tested by

no test coverage detected