mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-12 15:38:09 +00:00
Minor cleanup in IO
This commit is contained in:
parent
71197eb148
commit
e3bfbe2ee7
@ -173,7 +173,7 @@ R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) {
|
||||
}
|
||||
|
||||
R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
int l, covered = 0;
|
||||
bool covered = false;
|
||||
RListIter *iter;
|
||||
RIOCache *c;
|
||||
RInterval range = (RInterval){ addr, len };
|
||||
@ -181,27 +181,14 @@ R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
if (r_itv_overlap (c->itv, range)) {
|
||||
const ut64 begin = r_itv_begin (c->itv);
|
||||
if (addr < begin) {
|
||||
l = R_MIN (addr + len - begin, r_itv_size (c->itv));
|
||||
int l = R_MIN (addr + len - begin, r_itv_size (c->itv));
|
||||
memcpy (buf + begin - addr, c->data, l);
|
||||
} else {
|
||||
l = R_MIN (r_itv_end (c->itv) - addr, len);
|
||||
int l = R_MIN (r_itv_end (c->itv) - addr, len);
|
||||
memcpy (buf, c->data + addr - begin, l);
|
||||
}
|
||||
covered += l;
|
||||
covered = true;
|
||||
}
|
||||
}
|
||||
return (covered == 0) ? false: true;
|
||||
return covered;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#if 0
|
||||
R_API bool r_io_cache_ll_read(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
// UnownedRList *list = r
|
||||
}
|
||||
|
||||
R_API bool r_io_cache_ll_write(RIO *io, ut64 addr, ut8 *buf, int len) {
|
||||
}
|
||||
|
||||
R_API bool r_io_cache_ll_invalidate(RIO *io, ut64 addr, int len) {
|
||||
}
|
||||
#endif
|
||||
|
@ -39,9 +39,7 @@ R_API bool r_io_is_valid_offset(RIO* io, ut64 offset, int hasperm) {
|
||||
// this is wrong, there is more than big and little endian
|
||||
R_API bool r_io_read_i(RIO* io, ut64 addr, ut64 *val, int size, bool endian) {
|
||||
ut8 buf[8];
|
||||
if (!val) {
|
||||
return false;
|
||||
}
|
||||
r_return_val_if_fail (io && val, false);
|
||||
size = R_DIM (size, 1, 8);
|
||||
if (!r_io_read_at (io, addr, buf, size)) {
|
||||
return false;
|
||||
@ -54,9 +52,7 @@ R_API bool r_io_read_i(RIO* io, ut64 addr, ut64 *val, int size, bool endian) {
|
||||
|
||||
R_API bool r_io_write_i(RIO* io, ut64 addr, ut64 *val, int size, bool endian) {
|
||||
ut8 buf[8];
|
||||
if (!val) {
|
||||
return false;
|
||||
}
|
||||
r_return_val_if_fail (io && val, false);
|
||||
size = R_DIM (size, 1, 8);
|
||||
//size says the number of bytes to read transform to bits for r_read_ble
|
||||
r_write_ble (buf, *val, endian, size * 8);
|
||||
|
@ -56,7 +56,6 @@ static ut64 r_io_def_mmap_seek(RIO *io, RIOMMapFileObj *mmo, ut64 offset, int wh
|
||||
if (!mmo->buf) {
|
||||
return UT64_MAX;
|
||||
}
|
||||
|
||||
io->off = r_buf_seek (mmo->buf, offset, whence);
|
||||
return io->off;
|
||||
}
|
||||
@ -164,10 +163,7 @@ static bool r_io_def_mmap_check_default (const char *filename) {
|
||||
}
|
||||
const char * peekaboo = (!strncmp (filename, "nocache://", 10))
|
||||
? NULL : strstr (filename, "://");
|
||||
if (!peekaboo || (peekaboo - filename) > 10) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return (!peekaboo || (peekaboo - filename) > 10);
|
||||
}
|
||||
|
||||
static int r_io_def_mmap_read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
|
||||
@ -318,9 +314,8 @@ static RIODesc *r_io_def_mmap_open(RIO *io, const char *file, int perm, int mode
|
||||
}
|
||||
|
||||
static ut64 r_io_def_mmap_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||
return (fd && fd->data)
|
||||
? r_io_def_mmap_seek (io, (RIOMMapFileObj *)fd->data, offset, whence)
|
||||
: UT64_MAX;
|
||||
r_return_val_if_fail (fd && fd->data, UT64_MAX);
|
||||
return r_io_def_mmap_seek (io, (RIOMMapFileObj *)fd->data, offset, whence);
|
||||
}
|
||||
|
||||
static int r_io_def_mmap_truncate(RIOMMapFileObj *mmo, ut64 size) {
|
||||
@ -383,10 +378,6 @@ static bool __is_blockdevice (RIODesc *desc) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static char *__system(RIO *io, RIODesc *desc, const char *cmd) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RIOPlugin r_io_plugin_default = {
|
||||
.name = "default",
|
||||
.desc = "Open local files",
|
||||
@ -399,7 +390,6 @@ RIOPlugin r_io_plugin_default = {
|
||||
.lseek = __lseek,
|
||||
.write = __write,
|
||||
.resize = __resize,
|
||||
.system = __system,
|
||||
#if __UNIX__
|
||||
.is_blockdevice = __is_blockdevice,
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user