Rizin
unix-like reverse engineering framework and cli tools
buffer.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: unknown
2 // SPDX-License-Identifier: CC-PDDC
3 
4 #ifndef BUFFER_H
5 #define BUFFER_H
6 
7 #include <rz_types.h>
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 typedef int (*BufferOp)(int, const char *, int);
14 
15 typedef struct buffer {
16  char *x;
17  unsigned int p;
18  unsigned int n;
19  int fd;
22 
23 #define BUFFER_INIT(op, fd, buf, len) \
24  { (buf), 0, (len), (fd), (op) }
25 #define BUFFER_INSIZE 8192
26 #define BUFFER_OUTSIZE 8192
27 
28 extern void buffer_init(buffer *, BufferOp, int, char *, unsigned int);
29 
30 extern int buffer_flush(buffer *);
31 extern int buffer_put(buffer *, const char *, unsigned int);
32 extern int buffer_putalign(buffer *, const char *, unsigned int);
33 extern int buffer_putflush(buffer *, const char *, unsigned int);
34 
35 #define buffer_PUTC(s, c) \
36  (((s)->n != (s)->p) \
37  ? ((s)->x[(s)->p++] = (c), 0) \
38  : buffer_put((s), &(c), 1))
39 
40 extern int buffer_get(buffer *, char *, unsigned int);
41 extern int buffer_bget(buffer *, char *, unsigned int);
42 extern int buffer_feed(buffer *);
43 
44 extern char *buffer_peek(buffer *);
45 extern void buffer_seek(buffer *, unsigned int);
46 
47 #define buffer_PEEK(s) ((s)->x + (s)->n)
48 #define buffer_SEEK(s, len) (((s)->p -= (len)), ((s)->n += (len)))
49 
50 #define buffer_GETC(s, c) \
51  (((s)->p > 0) \
52  ? (*(c) = (s)->x[(s)->n], buffer_SEEK((s), 1), 1) \
53  : buffer_get((s), (c), 1))
54 
55 extern int buffer_copy(buffer *, buffer *);
56 
57 extern buffer *buffer_0;
58 extern buffer *buffer_0small;
59 extern buffer *buffer_1;
60 extern buffer *buffer_1small;
61 extern buffer *buffer_2;
62 
63 #ifdef __cplusplus
64 }
65 #endif
66 
67 #endif
buffer * buffer_1small
buffer * buffer_1
void buffer_init(buffer *, BufferOp, int, char *, unsigned int)
Definition: buffer.c:6
buffer * buffer_2
buffer * buffer_0small
int buffer_get(buffer *, char *, unsigned int)
int buffer_putalign(buffer *, const char *, unsigned int)
Definition: buffer.c:36
char * buffer_peek(buffer *)
int buffer_put(buffer *, const char *, unsigned int)
void buffer_seek(buffer *, unsigned int)
int buffer_copy(buffer *, buffer *)
int buffer_putflush(buffer *, const char *, unsigned int)
Definition: buffer.c:56
int buffer_feed(buffer *)
int(* BufferOp)(int, const char *, int)
Definition: buffer.h:13
int buffer_bget(buffer *, char *, unsigned int)
int buffer_flush(buffer *)
Definition: buffer.c:27
struct buffer buffer
buffer * buffer_0
static int
Definition: sfsocketcall.h:114
Definition: buffer.h:15
int fd
Definition: buffer.h:19
char * x
Definition: buffer.h:16
unsigned int p
Definition: buffer.h:17
BufferOp op
Definition: buffer.h:20
unsigned int n
Definition: buffer.h:18