8 #include <rpm/rpmstring.h>
9 #include "build/rpmbuild_misc.h"
12 #define BUF_CHUNK 1024
16 char *tail; /* Points to first "free" char */
21 StringBuf newStringBuf(void)
23 StringBuf sb = xmalloc(sizeof(*sb));
25 sb->free = sb->allocated = BUF_CHUNK;
26 sb->buf = xcalloc(sb->allocated, sizeof(*sb->buf));
33 StringBuf freeStringBuf(StringBuf sb)
36 sb->buf = _free(sb->buf);
42 void stripTrailingBlanksStringBuf(StringBuf sb)
44 while (sb->free != sb->allocated) {
45 if (! risspace(*(sb->tail - 1)))
53 const char * getStringBuf(StringBuf sb)
55 return (sb != NULL) ? sb->buf : NULL;
58 void appendStringBufAux(StringBuf sb, const char *s, int nl)
63 /* If free == l there is no room for NULL terminator! */
64 while ((l + nl + 1) > sb->free) {
65 sb->allocated += BUF_CHUNK;
66 sb->free += BUF_CHUNK;
67 sb->buf = xrealloc(sb->buf, sb->allocated);
68 sb->tail = sb->buf + (sb->allocated - sb->free);
83 uint32_t parseUnsignedNum(const char * line, uint32_t * res)
89 if (line == NULL) return 1;
91 while (isspace(*line)) line++;
92 if (!isdigit(*line)) return 1;
94 rc = strtoul(line, &s1, 10);
96 if (*s1 || s1 == line || rc == ULONG_MAX || rc > UINT_MAX)
99 result = (uint32_t)rc;
100 if (res) *res = result;