static int do_write(int fd, char *p, int n) { int retcode; again: caml_enter_blocking_section(); // Changed!!! if ((fd == 1/*stdout*/ || fd == 2/*stderr*/) && custom_ocaml_stdout_func) { (*custom_ocaml_stdout_func)(fd, p, n); retcode = n; } else retcode = write(fd, p, n); caml_leave_blocking_section(); if (retcode == -1) { if (errno == EINTR) goto again; if ((errno == EAGAIN || errno == EWOULDBLOCK) && n > 1) { /* We couldn't do a partial write here, probably because n <= PIPE_BUF and POSIX says that writes of less than PIPE_BUF characters must be atomic. We first try again with a partial write of 1 character. If that fails too, we'll raise Sys_blocked_io below. */ n = 1; goto again; } } if (retcode == -1) caml_sys_io_error(NO_ARG); return retcode; }
int caml_read_fd(int fd, int flags, void * buf, int n) { int retcode; do { caml_enter_blocking_section(); retcode = read(fd, buf, n); caml_leave_blocking_section(); } while (retcode == -1 && errno == EINTR); if (retcode == -1) caml_sys_io_error(NO_ARG); return retcode; }
/* caml_do_read is exported for Cash */ CAMLexport int caml_do_read(int fd, char *p, unsigned int n) { int retcode; do { caml_enter_blocking_section(); retcode = read(fd, p, n); caml_leave_blocking_section(); } while (retcode == -1 && errno == EINTR); if (retcode == -1) caml_sys_io_error(NO_ARG); return retcode; }
/* caml_do_read is exported for Cash */ CAMLexport int caml_do_read(int fd, char *p, unsigned int n) { int retcode; do { caml_enter_blocking_section(); retcode = read(fd, p, n); #if defined(_WIN32) if (retcode == -1 && errno == ENOMEM && n > 16384){ retcode = read(fd, p, 16384); } #endif caml_leave_blocking_section(); } while (retcode == -1 && errno == EINTR); if (retcode == -1) caml_sys_io_error(NO_ARG); return retcode; }
int caml_write_fd(int fd, int flags, void * buf, int n) { int retcode; again: caml_enter_blocking_section(); retcode = write(fd, buf, n); caml_leave_blocking_section(); if (retcode == -1) { if (errno == EINTR) goto again; if ((errno == EAGAIN || errno == EWOULDBLOCK) && n > 1) { /* We couldn't do a partial write here, probably because n <= PIPE_BUF and POSIX says that writes of less than PIPE_BUF characters must be atomic. We first try again with a partial write of 1 character. If that fails too, we'll return an error code. */ n = 1; goto again; } } if (retcode == -1) caml_sys_io_error(NO_ARG); CAMLassert (retcode > 0); return retcode; }
CAMLprim void caml_sys_open(value path, value vflags, value vperm) { CAMLparam3(path, vflags, vperm); caml_sys_io_error(NO_ARG); CAMLnoreturn; }