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

Go to the source code of this file.

Classes

struct  RzIONull
 

Functions

static int __write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
static bool __resize (RzIO *io, RzIODesc *fd, ut64 count)
 
static int __read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
static int __close (RzIODesc *fd)
 
static ut64 __lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
static bool __plugin_open (RzIO *io, const char *pathname, bool many)
 
static RzIODesc__open (RzIO *io, const char *pathname, int rw, int mode)
 

Variables

RzIOPlugin rz_io_plugin_null
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ __close()

static int __close ( RzIODesc fd)
static

Definition at line 60 of file io_null.c.

60  {
61  RZ_FREE(fd->data);
62  return 0;
63 }
#define RZ_FREE(x)
Definition: rz_types.h:369
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, and RZ_FREE.

◆ __lseek()

static ut64 __lseek ( RzIO io,
RzIODesc fd,
ut64  offset,
int  whence 
)
static

Definition at line 65 of file io_null.c.

65  {
66  RzIONull *null;
67  if (!fd || !fd->data) {
68  return offset;
69  }
70  null = (RzIONull *)fd->data;
71  switch (whence) {
72  case SEEK_SET:
73  if (offset >= null->size) {
74  return null->offset = null->size - 1;
75  }
76  return null->offset = offset;
77  case SEEK_CUR:
78  if ((null->offset + offset) >= null->size) {
79  return null->offset = null->size - 1;
80  }
81  return null->offset += offset;
82  case SEEK_END:
83  return null->offset = null->size - 1;
84  }
85  return offset;
86 }
voidpf uLong offset
Definition: ioapi.h:144
#define SEEK_SET
Definition: zip.c:88
#define SEEK_CUR
Definition: zip.c:80
#define SEEK_END
Definition: zip.c:84

References fd, SEEK_CUR, SEEK_END, and SEEK_SET.

◆ __open()

static RzIODesc* __open ( RzIO io,
const char *  pathname,
int  rw,
int  mode 
)
static

Definition at line 92 of file io_null.c.

92  {
93  RzIONull *null;
94  if (__plugin_open(io, pathname, 0)) {
95  if (!strncmp(pathname, "null://", 7) && strlen(pathname + 7)) {
96  null = RZ_NEW0(RzIONull);
97  null->size = rz_num_math(NULL, pathname + 7) + 1; //???
98  null->offset = 0LL;
99  return rz_io_desc_new(io, &rz_io_plugin_null, pathname, rw, mode, null);
100  }
101  }
102  return NULL;
103 }
#define NULL
Definition: cris-opc.c:27
RzIOPlugin rz_io_plugin_null
Definition: io_null.c:105
static bool __plugin_open(RzIO *io, const char *pathname, bool many)
Definition: io_null.c:88
const char int mode
Definition: ioapi.h:137
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char pathname
Definition: sflib.h:66
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
Definition: io_desc.c:11
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
#define RZ_NEW0(x)
Definition: rz_types.h:284

References __plugin_open(), NULL, pathname, rz_io_desc_new(), rz_io_plugin_null, RZ_NEW0, and rz_num_math().

◆ __plugin_open()

static bool __plugin_open ( RzIO io,
const char *  pathname,
bool  many 
)
static

Definition at line 88 of file io_null.c.

88  {
89  return (!strncmp(pathname, "null://", 7));
90 }

References pathname.

Referenced by __open().

◆ __read()

static int __read ( RzIO io,
RzIODesc fd,
ut8 buf,
int  count 
)
static

Definition at line 43 of file io_null.c.

43  {
44  RzIONull *null;
45  if (!fd || !fd->data || !buf) {
46  return -1;
47  }
48  null = (RzIONull *)fd->data;
49  if ((null->offset + count) > null->size) {
50  int ret = null->size - null->offset;
51  memset(buf, 0x00, ret);
52  null->offset = null->size;
53  return ret;
54  }
55  memset(buf, 0x00, count);
56  null->offset += count;
57  return count;
58 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References count, fd, if(), and memset().

◆ __resize()

static bool __resize ( RzIO io,
RzIODesc fd,
ut64  count 
)
static

Definition at line 27 of file io_null.c.

27  {
28  if (fd && fd->data) {
29  RzIONull *null = (RzIONull *)fd->data;
30  null->size = count;
31  if (null->offset >= count) {
32  if (count) {
33  null->offset = count - 1;
34  } else {
35  null->offset = 0LL;
36  }
37  }
38  return true;
39  }
40  return false;
41 }

References count, fd, and if().

◆ __write()

static int __write ( RzIO io,
RzIODesc fd,
const ut8 buf,
int  count 
)
static

Definition at line 13 of file io_null.c.

13  {
14  RzIONull *null;
15  if (!fd || !fd->data || !buf) {
16  return -1;
17  }
18  null = (RzIONull *)fd->data;
19  if ((null->offset + count) > null->size) {
20  int ret = null->size - null->offset;
21  return ret;
22  }
23  null->offset += count;
24  return count;
25 }

References count, fd, and if().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_IO,
}
@ RZ_LIB_TYPE_IO
Definition: rz_lib.h:69
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_io.h:117

Definition at line 120 of file io_null.c.

◆ rz_io_plugin_null

RzIOPlugin rz_io_plugin_null
Initial value:
= {
.name = "null",
.desc = "Null plugin",
.license = "LGPL3",
.uris = "null://",
.open = __open,
.close = __close,
.read = __read,
.check = __plugin_open,
.lseek = __lseek,
.write = __write,
.resize = __resize,
}
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_null.c:43
static RzIODesc * __open(RzIO *io, const char *pathname, int rw, int mode)
Definition: io_null.c:92
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_null.c:13
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_null.c:65
static int __close(RzIODesc *fd)
Definition: io_null.c:60
static bool __resize(RzIO *io, RzIODesc *fd, ut64 count)
Definition: io_null.c:27

Definition at line 105 of file io_null.c.

Referenced by __open().