static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { if (fd == NULL || fd->data == NULL) return -1; if (io->off+count > RIOMALLOC_SZ (fd)) count -= (io->off+count-(RIOMALLOC_SZ (fd))); if (count>0) memcpy (RIOMALLOC_BUF (fd)+io->off, buf, count); return count; }
static int __resize(RIO *io, RIODesc *fd, ut64 count) { ut8 * new_buf = NULL; if (fd == NULL || fd->data == NULL || count == 0) return -1; if (RIOMALLOC_OFF (fd) > RIOMALLOC_SZ (fd)) return -1; new_buf = malloc (count); if (!new_buf) return -1; memcpy (new_buf, RIOMALLOC_BUF (fd), R_MIN(count, RIOMALLOC_SZ (fd))); if (count > RIOMALLOC_SZ (fd) ) memset (new_buf+RIOMALLOC_SZ (fd), 0, count-RIOMALLOC_SZ (fd)); free (RIOMALLOC_BUF (fd)); RIOMALLOC_BUF (fd) = new_buf; RIOMALLOC_SZ (fd) = count; return count; }
static bool __resize(RIO *io, RIODesc *fd, ut64 count) { ut8 * new_buf = NULL; if (!fd || !fd->data || count == 0) { return false; } if (RIOMALLOC_OFF (fd) > RIOMALLOC_SZ (fd)) { return false; } new_buf = malloc (count); if (!new_buf) return -1; memcpy (new_buf, RIOMALLOC_BUF (fd), R_MIN (count, RIOMALLOC_SZ (fd))); if (count > RIOMALLOC_SZ (fd)) { memset (new_buf + RIOMALLOC_SZ (fd), 0, count - RIOMALLOC_SZ (fd)); } free (RIOMALLOC_BUF (fd)); RIOMALLOC_BUF (fd) = new_buf; RIOMALLOC_SZ (fd) = count; return true; }
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { memset (buf, 0xff, count); if (fd == NULL || fd->data == NULL) return -1; if (io->off>RIOMALLOC_SZ (fd)) return -1; if (io->off+count >= RIOMALLOC_SZ (fd)) count = RIOMALLOC_SZ (fd) - io->off; memcpy (buf, RIOMALLOC_BUF (fd)+io->off, count); return count; }
static int __read(RIO *io, RIODesc *fd, ut8 *buf, int count) { memset (buf, 0xff, count); if (!fd || !fd->data) { return -1; } if (RIOMALLOC_OFF (fd) > RIOMALLOC_SZ (fd)) { return -1; } if (RIOMALLOC_OFF (fd) + count >= RIOMALLOC_SZ (fd)) { count = RIOMALLOC_SZ (fd) - RIOMALLOC_OFF (fd); } memcpy (buf, RIOMALLOC_BUF (fd) + RIOMALLOC_OFF (fd), count); return count; }
static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) { if (!fd || !buf || count<0 || fd->data == NULL) return -1; if (RIOMALLOC_OFF (fd) > RIOMALLOC_SZ (fd)) return -1; if (RIOMALLOC_OFF (fd) + count > RIOMALLOC_SZ (fd)) count -= (RIOMALLOC_OFF (fd) + count-(RIOMALLOC_SZ (fd))); if (count > 0) { memcpy (RIOMALLOC_BUF (fd) + RIOMALLOC_OFF (fd), buf, count); RIOMALLOC_OFF (fd) += count; return count; } return -1; }