/// Reads at most \p n bytes into \p p, stopping when it feels like it. off_t fstream::readsome (void* p, off_t n) { ssize_t brn; do { brn = ::read (m_fd, p, n); } while ((brn < 0) & (errno == EINTR)); if (brn > 0) return (brn); else if ((brn < 0) & (errno != EAGAIN)) set_and_throw (failbit, "read"); else if (!brn && ios_base::set_and_throw (eofbit | failbit)) throw stream_bounds_exception ("read", name(), pos(), n, 0); return (0); }
/// Reads at most \p n bytes into \p p, stopping when it feels like it. off_t fstream::readsome (void* p, off_t n) { ssize_t brn; do { brn = ::read (m_fd, p, n); } while (brn < 0 && errno == EINTR); if (brn > 0) return (brn); if (brn < 0 && errno != EAGAIN) set_and_throw (failbit, "read"); if (!brn && ios_base::set_and_throw (eofbit | failbit)) #if PLATFORM_ANDROID printf("stream_bounds_exception\n"); #else /* !PLATFORM_ANDROID */ throw stream_bounds_exception ("read", name(), pos(), n, 0); #endif return (0); }
/// Writes \p n bytes from \p p. off_t fstream::write (const void* p, off_t n) { off_t btw (n); while (btw) { const off_t bw (n - btw); ssize_t bwn = ::write (m_fd, advance(p,bw), btw); if (bwn > 0) btw -= bwn; else if (!bwn) { if (ios_base::set_and_throw (eofbit | failbit)) throw stream_bounds_exception ("write", name(), pos() - bw, n, bw); break; } else if (errno != EINTR) { if (errno != EAGAIN) set_and_throw (failbit, "write"); break; } } return (n - btw); }
/// Checks that \p n bytes are available in the stream, or else throws. void ios_base::overrun (const char* op, const char* type, uint32_t n, uint32_t pos, uint32_t rem) { if (set_and_throw (rem ? failbit : (failbit | eofbit))) USTL_THROW(stream_bounds_exception (op, type, pos, n, rem)); }