mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-26 22:50:48 +00:00
Use R_IO_SEEK instead of SEEK ##io
This commit is contained in:
parent
33152ac296
commit
06ae25c56e
@ -112,13 +112,13 @@ static ut64 r_io_ar_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||
RArFp *arf = (RArFp *) fd->data;
|
||||
ut64 size = arf->end - arf->start;
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
io->off = R_MIN (size, offset);
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
case R_IO_SEEK_CUR:
|
||||
io->off = R_MIN (size, io->off + offset);
|
||||
break;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
io->off = size;
|
||||
break;
|
||||
default:
|
||||
|
@ -976,14 +976,14 @@ static ut64 r_io_dsc_object_seek(RIO *io, RIODscObject *dsc, ut64 offset, int wh
|
||||
ut64 off_global;
|
||||
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
off_global = offset;
|
||||
case R_IO_SEEK_SET:
|
||||
off_global = offset; //XXX
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
off_global = io->off + offset;
|
||||
case R_IO_SEEK_CUR:
|
||||
off_global = io->off + offset; //XXX
|
||||
break;
|
||||
case SEEK_END:
|
||||
off_global = dsc->total_size + offset;
|
||||
case R_IO_SEEK_END:
|
||||
off_global = dsc->total_size + offset; //XXX
|
||||
break;
|
||||
default:
|
||||
return UT64_MAX;
|
||||
|
@ -1388,17 +1388,17 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||
}
|
||||
gprobe = (RIOGprobe *)fd->data;
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
if (offset >= GPROBE_SIZE) {
|
||||
return gprobe->offset = GPROBE_SIZE - 1;
|
||||
}
|
||||
return gprobe->offset = offset;
|
||||
case SEEK_CUR:
|
||||
case R_IO_SEEK_CUR:
|
||||
if ((gprobe->offset + offset) >= GPROBE_SIZE) {
|
||||
return gprobe->offset = GPROBE_SIZE - 1;
|
||||
}
|
||||
return gprobe->offset += offset;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
return gprobe->offset = GPROBE_SIZE - 1;
|
||||
}
|
||||
return offset;
|
||||
|
@ -139,13 +139,13 @@ static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) {
|
||||
}
|
||||
ut32 mallocsz = _io_malloc_sz (fd);
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
r_offset = (offset <= mallocsz) ? offset : mallocsz;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
case R_IO_SEEK_CUR:
|
||||
r_offset = (_io_malloc_off (fd) + offset <= mallocsz ) ? _io_malloc_off (fd) + offset : mallocsz;
|
||||
break;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
r_offset = _io_malloc_sz (fd);
|
||||
break;
|
||||
}
|
||||
|
@ -18,15 +18,16 @@ typedef struct r_io_mmo_t {
|
||||
static ut64 r_io_mmap_seek(RIO *io, RIOMMapFileObj *mmo, ut64 offset, int whence) {
|
||||
ut64 seek_val = r_buf_tell (mmo->buf);
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
seek_val = (r_buf_size (mmo->buf) < offset)? r_buf_size (mmo->buf): offset;
|
||||
r_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET);
|
||||
return seek_val;
|
||||
case SEEK_CUR:
|
||||
seek_val = (r_buf_size (mmo->buf) < (offset + r_buf_tell (mmo->buf)))? r_buf_size (mmo->buf): offset + r_buf_tell (mmo->buf);
|
||||
case R_IO_SEEK_CUR:
|
||||
seek_val = (r_buf_size (mmo->buf) < (offset + r_buf_tell (mmo->buf)))? r_buf_size (mmo->buf):
|
||||
offset + r_buf_tell (mmo->buf);
|
||||
r_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET);
|
||||
return seek_val;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
seek_val = r_buf_size (mmo->buf);
|
||||
r_buf_seek (mmo->buf, io->off = seek_val, R_BUF_SET);
|
||||
return seek_val;
|
||||
|
@ -126,9 +126,9 @@ static bool __close(RIODesc *fd) {
|
||||
|
||||
static ut64 __lseek(RIO *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 UT64_MAX - 1;
|
||||
case R_IO_SEEK_SET: return offset;
|
||||
case R_IO_SEEK_CUR: return io->off + offset;
|
||||
case R_IO_SEEK_END: return UT64_MAX - 1;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
@ -73,15 +73,15 @@ static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||
}
|
||||
const int size = arena->size;
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
if (offset >= size) {
|
||||
return size;
|
||||
} else {
|
||||
return offset;
|
||||
}
|
||||
case SEEK_CUR:
|
||||
case R_IO_SEEK_CUR:
|
||||
return io->off + offset;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
return size;
|
||||
}
|
||||
return io->off;
|
||||
|
@ -413,13 +413,13 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int len) {
|
||||
|
||||
static ut64 __lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
io->off = offset;
|
||||
return offset;
|
||||
case SEEK_CUR:
|
||||
case R_IO_SEEK_CUR:
|
||||
io->off += offset;
|
||||
return io->off;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
if (sizeof (void*) == 8) {
|
||||
io->off = UT64_MAX;
|
||||
} else {
|
||||
|
@ -69,22 +69,22 @@ static ut64 shm__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||
R_RETURN_VAL_IF_FAIL (fd && fd->data, -1);
|
||||
RIOShm *shm = fd->data;
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
io->off = offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
case R_IO_SEEK_CUR:
|
||||
if (io->off + offset > shm->size) {
|
||||
io->off = shm->size;
|
||||
io->off = shm->size; //XXX
|
||||
} else {
|
||||
io->off += offset;
|
||||
io->off += offset; //XXX
|
||||
}
|
||||
break;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
if ((int)shm->size > 0) {
|
||||
io->off = shm->size + (int)offset;
|
||||
io->off = shm->size + (int)offset; //XXX
|
||||
} else {
|
||||
// UT64_MAX means error
|
||||
io->off = UT64_MAX - 1;
|
||||
io->off = UT64_MAX - 1; //XXX
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -514,15 +514,16 @@ static ut64 r_io_zip_lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
|
||||
seek_val = r_buf_tell (zfo->b);
|
||||
|
||||
switch (whence) {
|
||||
case SEEK_SET:
|
||||
case R_IO_SEEK_SET:
|
||||
seek_val = (r_buf_size (zfo->b) < offset)? r_buf_size (zfo->b): offset;
|
||||
r_buf_seek (zfo->b, seek_val, R_BUF_SET);
|
||||
return seek_val;
|
||||
case SEEK_CUR:
|
||||
seek_val = (r_buf_size (zfo->b) < (offset + r_buf_tell (zfo->b)))? r_buf_size (zfo->b): offset + r_buf_tell (zfo->b);
|
||||
case R_IO_SEEK_CUR:
|
||||
seek_val = (r_buf_size (zfo->b) < (offset + r_buf_tell (zfo->b)))?
|
||||
r_buf_size (zfo->b): offset + r_buf_tell (zfo->b);
|
||||
r_buf_seek (zfo->b, seek_val, R_BUF_SET);
|
||||
return seek_val;
|
||||
case SEEK_END:
|
||||
case R_IO_SEEK_END:
|
||||
seek_val = r_buf_size (zfo->b);
|
||||
r_buf_seek (zfo->b, seek_val, R_BUF_SET);
|
||||
return seek_val;
|
||||
|
Loading…
Reference in New Issue
Block a user