60 char padding[
sizeof(size_t) - 1];
64 char store[
sizeof(
char *) +
sizeof(
size_t) * 3 -
73 "corrupted agxbuf type");
105 return sizeof(xb->
u.
store);
138 nsize = size == 0 ? BUFSIZ : (2 * size);
139 if (size + ssz > nsize)
146 nbuf = (
char *)
gv_calloc(nsize,
sizeof(
char));
171 rc = vsnprintf(
NULL, 0, fmt, ap2);
177 size = (size_t)rc + 1;
181 bool use_stage =
false;
186 if (unused_space < size) {
187 size_t extra = size - unused_space;
202 char stage[
sizeof(xb->
u.
store) + 1] = {0};
203 assert(!use_stage || size <=
sizeof(stage));
206 char *dst = use_stage ? stage :
agxbnext(xb);
207 result = vsnprintf(dst, size, fmt, ap);
208 assert(result == (
int)(size - 1) || result < 0);
211 assert(result <= (
int)UCHAR_MAX);
213 memcpy(
agxbnext(xb), stage, (
size_t)result);
215 xb->
u.
s.
located += (
unsigned char)result;
216 assert(
agxblen(xb) <=
sizeof(xb->
u.
store) &&
"agxbuf corruption");
219 xb->
u.
s.
size += (size_t)result;
228#define PRINTF_LIKE(index, first) __attribute__((format(printf, index, first)))
230#define PRINTF_LIKE(index, first)
259 assert(ssz <= UCHAR_MAX);
261 assert(
agxblen(xb) <=
sizeof(xb->
u.
store) &&
"agxbuf corruption");
271 size_t ssz = strlen(
s);
285 assert(
agxblen(xb) <=
sizeof(xb->
u.
store) &&
"agxbuf corruption");
342 memset(xb, 0,
sizeof(*xb));
369 for (period =
agxblen(xb) - 1;; --period) {
374 if (start[period] ==
'.') {
380 for (
size_t follower =
agxblen(xb) - 1;; --follower) {
381 if (follower == period || start[follower] ==
'0') {
389 if (follower == period) {
399 if (
len < 2 || start[
len - 2] !=
'-' || start[
len - 1] !=
'0') {
404 start[
len - 2] =
'0';
static int agxbpop(agxbuf *xb)
removes last character added, if any
static size_t agxbsizeof(const agxbuf *xb)
static void agxbuf_trim_zeros(agxbuf *xb)
static void agxbfree(agxbuf *xb)
free any malloced resources
static size_t agxbput(agxbuf *xb, const char *s)
append string s into xb
static size_t agxbput_n(agxbuf *xb, const char *s, size_t ssz)
append string s of length ssz into xb
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
static char * agxbnext(agxbuf *xb)
next position for writing
static void agxbclear(agxbuf *xb)
resets pointer to data
static int vagxbprint(agxbuf *xb, const char *fmt, va_list ap)
vprintf-style output to an agxbuf
static WUR char * agxbuse(agxbuf *xb)
static void agxbmore(agxbuf *xb, size_t ssz)
expand buffer to hold at least ssz more bytes
static size_t agxblen(const agxbuf *xb)
return number of characters currently stored
static char * agxbstart(agxbuf *xb)
return pointer to beginning of buffer
static bool agxbuf_is_inline(const agxbuf *xb)
#define PRINTF_LIKE(index, first)
static int agxbputc(agxbuf *xb, char c)
add character to buffer
static char * agxbdisown(agxbuf *xb)
agxbuf_loc_t
a description of where a buffer is located
Memory allocation wrappers that exit on failure.
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
static void * gv_calloc(size_t nmemb, size_t size)
static char * gv_strndup(const char *original, size_t length)
static double len(glCompPoint p)
static int cnt(Dict_t *d, Dtlink_t **set)
static int store(segment_t *seg, int first, pointf *pts)
char store[sizeof(char *)+sizeof(size_t) *3 - 1]
char * buf
start of buffer
size_t size
number of characters in the buffer
struct agxbuf::@121::@122 s
unsigned char located
where does the backing memory for this buffer live?
size_t capacity
available bytes in the buffer
abstraction for squashing compiler warnings for unused symbols