Rizin
unix-like reverse engineering framework and cli tools
rz_strbuf.h
Go to the documentation of this file.
1 #ifndef RZ_STRBUF_H
2 #define RZ_STRBUF_H
3 
4 #include <rz_types.h>
5 
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 
10 typedef struct {
11  char buf[32];
12  size_t len; // string length in chars or binary buffer size
13  char *ptr; // ptr replacing buf in case strlen > sizeof(buf)
14  size_t ptrlen; // string length + 1 or binary buffer size
15  bool weakref; // ptr is not owned
16 } RzStrBuf;
17 
18 #define RZ_STRBUF_SAFEGET(sb) (rz_strbuf_get(sb) ? rz_strbuf_get(sb) : "")
19 RZ_API RzStrBuf *rz_strbuf_new(const char *s);
20 RZ_API const char *rz_strbuf_set(RzStrBuf *sb, const char *s); // return = the string or NULL on fail
21 RZ_API bool rz_strbuf_slice(RZ_NONNULL RzStrBuf *sb, size_t from, size_t len);
22 RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len);
24 RZ_API const char *rz_strbuf_setf(RzStrBuf *sb, const char *fmt, ...) RZ_PRINTF_CHECK(2, 3); // return = the string or NULL on fail
25 RZ_API const char *rz_strbuf_vsetf(RzStrBuf *sb, const char *fmt, va_list ap); // return = the string or NULL on fail
27 RZ_API bool rz_strbuf_append_n(RzStrBuf *sb, const char *s, size_t l);
30 RZ_API bool rz_strbuf_vappendf(RzStrBuf *sb, const char *fmt, va_list ap);
38 RZ_API const char *rz_strbuf_initf(RzStrBuf *sb, const char *fmt, ...); // same as init + setf for convenience
41 RZ_API bool rz_strbuf_reserve(RzStrBuf *sb, size_t len);
43 RZ_API bool rz_strbuf_setptr(RzStrBuf *sb, char *p, int l);
44 
45 #ifdef __cplusplus
46 }
47 #endif
48 
49 #endif // RZ_STRBUF_H
size_t len
Definition: 6502dis.c:15
lzma_index * src
Definition: index.h:567
static SblHeader sb
Definition: bin_mbn.c:26
#define RZ_API
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
#define const
Definition: ansidecl.h:240
char * dst
Definition: lz4.h:724
static RzSocket * s
Definition: rtr.c:28
RZ_API RZ_OWN char * rz_strbuf_drain(RzStrBuf *sb)
Definition: strbuf.c:342
RZ_API const char RZ_API const char * rz_strbuf_vsetf(RzStrBuf *sb, const char *fmt, va_list ap)
Definition: strbuf.c:177
RZ_API RZ_OWN char * rz_strbuf_drain_nofree(RzStrBuf *sb)
Definition: strbuf.c:349
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API bool rz_strbuf_prepend(RzStrBuf *sb, const char *s)
Definition: strbuf.c:201
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
RZ_API bool rz_strbuf_copy(RzStrBuf *dst, RzStrBuf *src)
Definition: strbuf.c:48
RZ_API bool rz_strbuf_reserve(RzStrBuf *sb, size_t len)
Definition: strbuf.c:67
RZ_API bool rz_strbuf_slice(RZ_NONNULL RzStrBuf *sb, size_t from, size_t len)
Cuts the current string into a substring.
Definition: strbuf.c:122
RZ_API bool rz_strbuf_append(RzStrBuf *sb, const char *s)
Definition: strbuf.c:222
RZ_API const char * rz_strbuf_initf(RzStrBuf *sb, const char *fmt,...)
Definition: strbuf.c:38
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API bool RZ_API bool rz_strbuf_vappendf(RzStrBuf *sb, const char *fmt, va_list ap)
Definition: strbuf.c:290
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RZ_API bool rz_strbuf_equals(RzStrBuf *sa, RzStrBuf *sb)
Definition: strbuf.c:16
RZ_API ut8 * rz_strbuf_getbin(RzStrBuf *sb, int *len)
Definition: strbuf.c:326
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API bool rz_strbuf_setbin(RzStrBuf *sb, const ut8 *s, size_t len)
Definition: strbuf.c:85
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
RZ_API bool rz_strbuf_setptr(RzStrBuf *sb, char *p, int l)
Definition: strbuf.c:139
RZ_API bool rz_strbuf_is_empty(RzStrBuf *sb)
Definition: strbuf.c:24
RZ_API int rz_strbuf_length(RzStrBuf *sb)
Definition: strbuf.c:28
RZ_API bool rz_strbuf_append_n(RzStrBuf *sb, const char *s, size_t l)
Definition: strbuf.c:229
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_PRINTF_CHECK(fmt, dots)
Definition: rz_types.h:192
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
size_t len
Definition: rz_strbuf.h:12
char * ptr
Definition: rz_strbuf.h:13
size_t ptrlen
Definition: rz_strbuf.h:14
bool weakref
Definition: rz_strbuf.h:15