Rizin
unix-like reverse engineering framework and cli tools
buffer.c File Reference
#include "buffer.h"

Go to the source code of this file.

Functions

void buffer_init (buffer *s, BufferOp op, int fd, char *buf, ut32 len)
 
static int allwrite (BufferOp op, int fd, const char *buf, ut32 len)
 
int buffer_flush (buffer *s)
 
int buffer_putalign (buffer *s, const char *buf, ut32 len)
 
int buffer_putflush (buffer *s, const char *buf, ut32 len)
 

Function Documentation

◆ allwrite()

static int allwrite ( BufferOp  op,
int  fd,
const char *  buf,
ut32  len 
)
static

Definition at line 14 of file buffer.c.

14  {
15  ut32 w;
16  while (len > 0) {
17  w = op(fd, buf, len);
18  if (w != len) {
19  return 0;
20  }
21  buf += w;
22  len -= w;
23  }
24  return 1;
25 }
size_t len
Definition: 6502dis.c:15
ut8 op
Definition: 6502dis.c:13
#define w
Definition: crypto_rc6.c:13
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, len, op, and w.

Referenced by buffer_flush(), and buffer_putflush().

◆ 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
void * p
Definition: libc.cpp:67
static RzSocket * s
Definition: rtr.c:28

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

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

◆ buffer_init()

void buffer_init ( buffer s,
BufferOp  op,
int  fd,
char *  buf,
ut32  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 }

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

Referenced by cdb_make_start().

◆ buffer_putalign()

int buffer_putalign ( buffer s,
const char *  buf,
ut32  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
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int n
Definition: mipsasm.c:19

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,
ut32  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().