static value getval(struct channel *chan) { value res; if (caml_really_getblock(chan, (char *) &res, sizeof(res)) == 0) caml_raise_end_of_file(); /* Bad, but consistent with caml_getword */ return res; }
CAMLexport unsigned char caml_refill(struct channel *channel) { int n; n = caml_do_read(channel->fd, channel->buff, channel->end - channel->buff); if (n == 0) caml_raise_end_of_file(); channel->offset += n; channel->max = channel->buff + n; channel->curr = channel->buff + 1; return (unsigned char)(channel->buff[0]); }
value mlptrace_pread_kilobyte(value fd_v, value kbad_v) { CAMLparam2(fd_v, kbad_v); CAMLlocal1(res_v); char kilobuf[1024+1]; ssize_t sz; int fd; int kbad; size_t cnt; ssize_t rd; char* p; off_t off; int savederrno = errno; fd = Long_val(fd_v); kbad = Long_val(kbad_v); memset(kilobuf, 0, sizeof(kilobuf)); errno = 0; res_v = Val_unit; #ifndef NO_BLOCKING_SECTION caml_enter_blocking_section(); #endif p = kilobuf; cnt = (size_t)1024; off = (off_t)kbad << 10; while (cnt>0) { rd = pread(fd, p, cnt, off); if (rd<0 && errno == EINTR) continue; else if (rd<0) break; p += rd; cnt -= rd; off += rd; }; #ifndef NO_BLOCKING_SECTION caml_leave_blocking_section (); #endif if (p>kilobuf) { int l = p - kilobuf; res_v = caml_alloc_string(l); memcpy(String_val(res_v), kilobuf, l); } else if (errno) uerror ("Ptrace.pread_kilobyte", Nothing); else //got eof caml_raise_end_of_file(); if (savederrno) errno = savederrno; CAMLreturn(res_v); }