Rizin
unix-like reverse engineering framework and cli tools
buffer.h File Reference
#include <rz_types.h>

Go to the source code of this file.

Classes

struct  buffer
 

Macros

#define BUFFER_INIT(op, fd, buf, len)    { (buf), 0, (len), (fd), (op) }
 
#define BUFFER_INSIZE   8192
 
#define BUFFER_OUTSIZE   8192
 
#define buffer_PUTC(s, c)
 
#define buffer_PEEK(s)   ((s)->x + (s)->n)
 
#define buffer_SEEK(s, len)   (((s)->p -= (len)), ((s)->n += (len)))
 
#define buffer_GETC(s, c)
 

Typedefs

typedef int(* BufferOp) (int, const char *, int)
 
typedef struct buffer buffer
 

Functions

void buffer_init (buffer *, BufferOp, int, char *, unsigned int)
 
int buffer_flush (buffer *)
 
int buffer_put (buffer *, const char *, unsigned int)
 
int buffer_putalign (buffer *, const char *, unsigned int)
 
int buffer_putflush (buffer *, const char *, unsigned int)
 
int buffer_get (buffer *, char *, unsigned int)
 
int buffer_bget (buffer *, char *, unsigned int)
 
int buffer_feed (buffer *)
 
char * buffer_peek (buffer *)
 
void buffer_seek (buffer *, unsigned int)
 
int buffer_copy (buffer *, buffer *)
 

Variables

bufferbuffer_0
 
bufferbuffer_0small
 
bufferbuffer_1
 
bufferbuffer_1small
 
bufferbuffer_2
 

Macro Definition Documentation

◆ buffer_GETC

#define buffer_GETC (   s,
  c 
)
Value:
(((s)->p > 0) \
? (*(c) = (s)->x[(s)->n], buffer_SEEK((s), 1), 1) \
: buffer_get((s), (c), 1))
int buffer_get(buffer *, char *, unsigned int)
#define buffer_SEEK(s, len)
Definition: buffer.h:48
void * p
Definition: libc.cpp:67
int n
Definition: mipsasm.c:19
static RzSocket * s
Definition: rtr.c:28
#define c(i)
Definition: sha256.c:43

Definition at line 50 of file buffer.h.

◆ BUFFER_INIT

#define BUFFER_INIT (   op,
  fd,
  buf,
  len 
)     { (buf), 0, (len), (fd), (op) }

Definition at line 23 of file buffer.h.

◆ BUFFER_INSIZE

#define BUFFER_INSIZE   8192

Definition at line 25 of file buffer.h.

◆ BUFFER_OUTSIZE

#define BUFFER_OUTSIZE   8192

Definition at line 26 of file buffer.h.

◆ buffer_PEEK

#define buffer_PEEK (   s)    ((s)->x + (s)->n)

Definition at line 47 of file buffer.h.

◆ buffer_PUTC

#define buffer_PUTC (   s,
  c 
)
Value:
(((s)->n != (s)->p) \
? ((s)->x[(s)->p++] = (c), 0) \
: buffer_put((s), &(c), 1))
int buffer_put(buffer *, const char *, unsigned int)

Definition at line 35 of file buffer.h.

◆ buffer_SEEK

#define buffer_SEEK (   s,
  len 
)    (((s)->p -= (len)), ((s)->n += (len)))

Definition at line 48 of file buffer.h.

Typedef Documentation

◆ buffer

typedef struct buffer buffer

◆ BufferOp

typedef int(* BufferOp) (int, const char *, int)

Definition at line 13 of file buffer.h.

Function Documentation

◆ buffer_bget()

int buffer_bget ( buffer ,
char *  ,
unsigned int   
)

◆ buffer_copy()

int buffer_copy ( buffer ,
buffer  
)

◆ buffer_feed()

int buffer_feed ( buffer )

◆ buffer_flush()

int buffer_flush ( buffer s)

Definition at line 27 of file buffer.c.

27  {
28  int p = s->p;
29  if (!p) {
30  return 1;
31  }
32  s->p = 0;
33  return allwrite(s->op, s->fd, s->x, p);
34 }
static int allwrite(BufferOp op, int fd, const char *buf, ut32 len)
Definition: buffer.c:14

References allwrite(), rz_socket_t::fd, p, and s.

Referenced by buffer_putalign(), buffer_putflush(), and cdb_make_finish().

◆ buffer_get()

int buffer_get ( buffer ,
char *  ,
unsigned int   
)

◆ buffer_init()

void buffer_init ( buffer s,
BufferOp  op,
int  fd,
char *  buf,
unsigned int  len 
)

Definition at line 6 of file buffer.c.

6  {
7  s->x = buf;
8  s->fd = fd;
9  s->op = op;
10  s->p = 0;
11  s->n = len;
12 }
size_t len
Definition: 6502dis.c:15
ut8 op
Definition: 6502dis.c:13
voidpf void * buf
Definition: ioapi.h:138
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, rz_socket_t::fd, len, op, and s.

Referenced by cdb_make_start().

◆ buffer_peek()

char* buffer_peek ( buffer )

◆ buffer_put()

int buffer_put ( buffer ,
const char *  ,
unsigned int   
)

◆ buffer_putalign()

int buffer_putalign ( buffer s,
const char *  buf,
unsigned int  len 
)

Definition at line 36 of file buffer.c.

36  {
37  ut32 n;
38  if (!s || !s->x || !buf) {
39  return 0;
40  }
41  while (len > (n = s->n - s->p)) {
42  memcpy(s->x + s->p, buf, n);
43  s->p += n;
44  buf += n;
45  len -= n;
46  if (!buffer_flush(s)) {
47  return 0;
48  }
49  }
50  /* now len <= s->n - s->p */
51  memcpy(s->x + s->p, buf, len);
52  s->p += len;
53  return 1;
54 }
int buffer_flush(buffer *s)
Definition: buffer.c:27
uint32_t ut32
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))

References buffer_flush(), len, memcpy(), n, and s.

Referenced by cdb_make_add(), cdb_make_addbegin(), and cdb_make_finish().

◆ buffer_putflush()

int buffer_putflush ( buffer s,
const char *  buf,
unsigned int  len 
)

Definition at line 56 of file buffer.c.

56  {
57  if (!buffer_flush(s)) {
58  return 0;
59  }
60  return allwrite(s->op, s->fd, buf, len);
61 }

References allwrite(), buffer_flush(), rz_socket_t::fd, len, and s.

Referenced by cdb_make_finish().

◆ buffer_seek()

void buffer_seek ( buffer ,
unsigned int   
)

Variable Documentation

◆ buffer_0

buffer* buffer_0
extern

◆ buffer_0small

buffer* buffer_0small
extern

◆ buffer_1

buffer* buffer_1
extern

◆ buffer_1small

buffer* buffer_1small
extern

◆ buffer_2

buffer* buffer_2
extern