Skip to content

Commit

Permalink
use R_IO_SEEK instead of SEEK
Browse files Browse the repository at this point in the history
  • Loading branch information
condret committed Nov 6, 2024
1 parent d2a03c5 commit 7cb9ee0
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 36 deletions.
12 changes: 6 additions & 6 deletions libr/io/p/io_dsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_gprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_gzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions libr/io/p/io_mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_r2pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions libr/io/p/io_self.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions libr/io/p/io_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 5 additions & 4 deletions libr/io/p/io_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7cb9ee0

Please sign in to comment.