Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
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;
}
Ejemplo n.º 3
0
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;
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
0
static ut64 __lseek(struct r_io_t *io, RIODesc *fd, ut64 offset, int whence) {
	switch (whence) {
	case SEEK_SET: return offset;
	case SEEK_CUR: return io->off + offset;
	case SEEK_END: return RIOMALLOC_SZ (fd);
	}
	return offset;
}
Ejemplo n.º 6
0
static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) {
	ut64 r_offset = offset;
	if (!fd || !fd->data)
		return offset;
	switch (whence) {
	case SEEK_SET:
		r_offset = (offset <= RIOMALLOC_SZ (fd)) ? offset : RIOMALLOC_SZ (fd);
		break;
	case SEEK_CUR:
		r_offset = (RIOMALLOC_OFF (fd) + offset <= RIOMALLOC_SZ (fd)) ? RIOMALLOC_OFF (fd) + offset : RIOMALLOC_SZ (fd);
		break;
	case SEEK_END:
		r_offset = RIOMALLOC_SZ (fd);
		break;
	}
	RIOMALLOC_OFF (fd) = r_offset;
	return RIOMALLOC_OFF (fd);
}
Ejemplo n.º 7
0
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;
}
Ejemplo n.º 8
0
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;
}