Rizin
unix-like reverse engineering framework and cli tools
buf_io_fd.c File Reference
#include <rz_util.h>
#include <rz_io.h>

Go to the source code of this file.

Classes

struct  buf_io_fd_user
 
struct  buf_io_fd_priv
 

Functions

static struct buf_io_fd_privget_priv_io (RzBuffer *b)
 
static bool buf_io_fd_init (RzBuffer *b, const void *user)
 
static bool buf_io_fd_fini (RzBuffer *b)
 
static st64 buf_io_fd_seek (RzBuffer *b, st64 addr, int whence)
 
static ut64 buf_io_fd_get_size (RzBuffer *b)
 
static bool buf_io_fd_resize (RzBuffer *b, ut64 newsize)
 
static st64 buf_io_fd_read (RzBuffer *b, ut8 *buf, ut64 len)
 
static st64 buf_io_fd_write (RzBuffer *b, const ut8 *buf, ut64 len)
 
static ut8buf_io_fd_get_whole_buf (RzBuffer *b, ut64 *size)
 

Variables

static const RzBufferMethods buffer_io_fd_methods
 

Function Documentation

◆ buf_io_fd_fini()

static bool buf_io_fd_fini ( RzBuffer b)
static

Definition at line 36 of file buf_io_fd.c.

36  {
37  // struct buf_io_fd_priv *priv = get_priv_io (b);
38  RZ_FREE(b->priv);
39  return true;
40 }
#define RZ_FREE(x)
Definition: rz_types.h:369
#define b(i)
Definition: sha256.c:42

References b, and RZ_FREE.

◆ buf_io_fd_get_size()

static ut64 buf_io_fd_get_size ( RzBuffer b)
static

Definition at line 63 of file buf_io_fd.c.

63  {
64  struct buf_io_fd_priv *priv = get_priv_io(b);
65  return priv->iob->fd_size(priv->iob->io, priv->fd);
66 }
static struct buf_io_fd_priv * get_priv_io(RzBuffer *b)
Definition: buf_io_fd.c:17
RzIOBind * iob
Definition: buf_io_fd.c:13
RzIO * io
Definition: rz_io.h:232
RzIOFdSize fd_size
Definition: rz_io.h:246

References b, buf_io_fd_priv::fd, rz_io_bind_t::fd_size, get_priv_io(), rz_io_bind_t::io, and buf_io_fd_priv::iob.

◆ buf_io_fd_get_whole_buf()

static ut8* buf_io_fd_get_whole_buf ( RzBuffer b,
ut64 size 
)
static

Definition at line 83 of file buf_io_fd.c.

83  {
84  struct buf_io_fd_priv *priv = get_priv_io(b);
85  return priv->iob->fd_getbuf(priv->iob->io, priv->fd, size);
86 }
voidpf void uLong size
Definition: ioapi.h:138
RzIOFdGetBuf fd_getbuf
Definition: rz_io.h:256

References b, buf_io_fd_priv::fd, rz_io_bind_t::fd_getbuf, get_priv_io(), rz_io_bind_t::io, and buf_io_fd_priv::iob.

◆ buf_io_fd_init()

static bool buf_io_fd_init ( RzBuffer b,
const void *  user 
)
static

Definition at line 23 of file buf_io_fd.c.

23  {
24  const struct buf_io_fd_user *u = (const struct buf_io_fd_user *)user;
25  struct buf_io_fd_priv *priv = RZ_NEW0(struct buf_io_fd_priv);
26  if (!priv) {
27  return false;
28  }
29  priv->iob = u->iob;
30  priv->fd = u->fd;
31  b->priv = priv;
32  b->fd = priv->fd;
33  return true;
34 }
#define RZ_NEW0(x)
Definition: rz_types.h:284
RzIOBind * iob
Definition: buf_io_fd.c:8

References b, buf_io_fd_user::fd, buf_io_fd_priv::fd, buf_io_fd_user::iob, buf_io_fd_priv::iob, and RZ_NEW0.

◆ buf_io_fd_read()

static st64 buf_io_fd_read ( RzBuffer b,
ut8 buf,
ut64  len 
)
static

Definition at line 73 of file buf_io_fd.c.

73  {
74  struct buf_io_fd_priv *priv = get_priv_io(b);
75  return priv->iob->fd_read(priv->iob->io, priv->fd, buf, len);
76 }
size_t len
Definition: 6502dis.c:15
voidpf void * buf
Definition: ioapi.h:138
RzIOFdRead fd_read
Definition: rz_io.h:248

References b, buf_io_fd_priv::fd, rz_io_bind_t::fd_read, get_priv_io(), rz_io_bind_t::io, buf_io_fd_priv::iob, and len.

◆ buf_io_fd_resize()

static bool buf_io_fd_resize ( RzBuffer b,
ut64  newsize 
)
static

Definition at line 68 of file buf_io_fd.c.

68  {
69  struct buf_io_fd_priv *priv = get_priv_io(b);
70  return priv->iob->fd_resize(priv->iob->io, priv->fd, newsize);
71 }
RzIOFdResize fd_resize
Definition: rz_io.h:247

References b, buf_io_fd_priv::fd, rz_io_bind_t::fd_resize, get_priv_io(), rz_io_bind_t::io, and buf_io_fd_priv::iob.

◆ buf_io_fd_seek()

static st64 buf_io_fd_seek ( RzBuffer b,
st64  addr,
int  whence 
)
static

Definition at line 42 of file buf_io_fd.c.

42  {
43  struct buf_io_fd_priv *priv = get_priv_io(b);
44  int io_whence;
45 
46  switch (whence) {
47  default:
49  // fallthrough
50  case RZ_BUF_SET:
51  io_whence = RZ_IO_SEEK_SET;
52  break;
53  case RZ_BUF_END:
54  io_whence = RZ_IO_SEEK_END;
55  break;
56  case RZ_BUF_CUR:
57  io_whence = RZ_IO_SEEK_CUR;
58  break;
59  }
60  return priv->iob->fd_seek(priv->iob->io, priv->fd, addr, io_whence);
61 }
#define rz_warn_if_reached()
Definition: rz_assert.h:29
#define RZ_BUF_CUR
Definition: rz_buf.h:15
#define RZ_BUF_END
Definition: rz_buf.h:16
#define RZ_BUF_SET
Definition: rz_buf.h:14
#define RZ_IO_SEEK_CUR
Definition: rz_io.h:16
#define RZ_IO_SEEK_SET
Definition: rz_io.h:15
#define RZ_IO_SEEK_END
Definition: rz_io.h:17
RzIOFdSeek fd_seek
Definition: rz_io.h:245
static int addr
Definition: z80asm.c:58

References addr, b, buf_io_fd_priv::fd, rz_io_bind_t::fd_seek, get_priv_io(), rz_io_bind_t::io, buf_io_fd_priv::iob, RZ_BUF_CUR, RZ_BUF_END, RZ_BUF_SET, RZ_IO_SEEK_CUR, RZ_IO_SEEK_END, RZ_IO_SEEK_SET, and rz_warn_if_reached.

◆ buf_io_fd_write()

static st64 buf_io_fd_write ( RzBuffer b,
const ut8 buf,
ut64  len 
)
static

Definition at line 78 of file buf_io_fd.c.

78  {
79  struct buf_io_fd_priv *priv = get_priv_io(b);
80  return priv->iob->fd_write(priv->iob->io, priv->fd, buf, len);
81 }
RzIOFdWrite fd_write
Definition: rz_io.h:249

References b, buf_io_fd_priv::fd, rz_io_bind_t::fd_write, get_priv_io(), rz_io_bind_t::io, buf_io_fd_priv::iob, and len.

◆ get_priv_io()

static struct buf_io_fd_priv* get_priv_io ( RzBuffer b)
inlinestatic

Definition at line 17 of file buf_io_fd.c.

17  {
18  struct buf_io_fd_priv *priv = (struct buf_io_fd_priv *)b->priv;
19  rz_warn_if_fail(priv);
20  return priv;
21 }
#define rz_warn_if_fail(expr)
Definition: rz_assert.h:35

References b, and rz_warn_if_fail.

Referenced by buf_io_fd_get_size(), buf_io_fd_get_whole_buf(), buf_io_fd_read(), buf_io_fd_resize(), buf_io_fd_seek(), and buf_io_fd_write().

Variable Documentation

◆ buffer_io_fd_methods

const RzBufferMethods buffer_io_fd_methods
static
Initial value:
= {
.init = buf_io_fd_init,
.fini = buf_io_fd_fini,
.read = buf_io_fd_read,
.write = buf_io_fd_write,
.get_size = buf_io_fd_get_size,
.resize = buf_io_fd_resize,
.seek = buf_io_fd_seek,
.get_whole_buf = buf_io_fd_get_whole_buf
}
static ut64 buf_io_fd_get_size(RzBuffer *b)
Definition: buf_io_fd.c:63
static st64 buf_io_fd_seek(RzBuffer *b, st64 addr, int whence)
Definition: buf_io_fd.c:42
static bool buf_io_fd_init(RzBuffer *b, const void *user)
Definition: buf_io_fd.c:23
static st64 buf_io_fd_write(RzBuffer *b, const ut8 *buf, ut64 len)
Definition: buf_io_fd.c:78
static st64 buf_io_fd_read(RzBuffer *b, ut8 *buf, ut64 len)
Definition: buf_io_fd.c:73
static ut8 * buf_io_fd_get_whole_buf(RzBuffer *b, ut64 *size)
Definition: buf_io_fd.c:83
static bool buf_io_fd_resize(RzBuffer *b, ut64 newsize)
Definition: buf_io_fd.c:68
static bool buf_io_fd_fini(RzBuffer *b)
Definition: buf_io_fd.c:36

Definition at line 88 of file buf_io_fd.c.

Referenced by new_buffer().