summaryrefslogtreecommitdiffstats
path: root/include/str.h
blob: 23a302eda228aae58b4c66330184b1e2d20dc845 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once

#include "allocator.h"

#ifdef LIBSTR_ASSERT_ARGS
#include "stdlib.h"
#define LIBSTR_ABORT_ON_ARGS(cond) do { if (cond) abort(); } while (0)
#else
#define LIBSTR_ABORT_ON_ARGS(cond)
#endif

#ifdef LIBSTR_ASSERT_ALLOC
#include "stdlib.h"
#define LIBSTR_ABORT_ON_ALLOC(cond) do { if (cond) abort(); } while (0)
#else
#define LIBSTR_ABORT_ON_ALLOC(cond)
#endif

char * __attribute__((format(printf, 3, 4)))
str_fmt(const struct allocator *allocator, int *rc,
	const char *fmstr, ...);
char * __attribute__((format(printf, 4, 5)))
str_fmt_realloc(const struct allocator *allocator, int *rc,
	void *alloc, const char *fmtstr, ...);

char *str_dup(const struct allocator *allocator, int *rc,
	const char *str);
char *str_dup_realloc(const struct allocator *allocator, int *rc,
	void *alloc, const char *str);

char *str_ndup(const struct allocator *allocator, int *rc,
	const char *str, size_t n);
char *str_ndup_realloc(const struct allocator *allocator, int *rc,
	void *alloc, const char *str, size_t n);

char *str_app(const struct allocator *allocator, int *rc,
	char *str, const char *app);