From ebaa557d2a2f2910e199510d7a0e1767b881778b Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 14 Sep 2024 15:51:41 +0900 Subject: [PATCH] [dstring] Rename reserve to open I've decided that I want reserve to mean only allocate backing memory, not modify the size of the string, but I didn't want to rework much code in the process. I might eventually get right of the open functions, but I wouldn't be surprised if that's another decade or two in the future. --- include/QF/dstring.h | 4 ++-- libs/util/dstring.c | 4 ++-- libs/util/plist.c | 10 +++++----- libs/util/test/test-ringbuffer.c | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/QF/dstring.h b/include/QF/dstring.h index b3aa32c0a..92dfeaec9 100644 --- a/include/QF/dstring.h +++ b/include/QF/dstring.h @@ -72,7 +72,7 @@ void dstring_adjust (dstring_t *dstr); \param len the size of the hole to open. \return pointer to the beginning of the opened hole. */ -char *dstring_reserve (dstring_t *dstr, size_t len); +char *dstring_open (dstring_t *dstr, size_t len); /** Copy len bytes from data into the dstring, replacing any existing data. */ void dstring_copy (dstring_t *dstr, const char *data, size_t len); @@ -123,7 +123,7 @@ dstring_t *dstring_strdup (const char *str); \return pointer to the current null terminator or beginning of the opened hole if there was no terminator. */ -char *dstring_reservestr (dstring_t *dstr, size_t len); +char *dstring_openstr (dstring_t *dstr, size_t len); /** Copy the null terminated string into the dstring. Replaces any existing data. The dstring does not have to be null terminated but will become so. diff --git a/libs/util/dstring.c b/libs/util/dstring.c index c2b6ae6f7..167fc644f 100644 --- a/libs/util/dstring.c +++ b/libs/util/dstring.c @@ -104,7 +104,7 @@ dstring_adjust (dstring_t *dstr) } VISIBLE char * -dstring_reserve (dstring_t *dstr, size_t len) +dstring_open (dstring_t *dstr, size_t len) { dstr->size += len; dstring_adjust (dstr); @@ -225,7 +225,7 @@ dstring_strdup (const char *str) } VISIBLE char * -dstring_reservestr (dstring_t *dstr, size_t len) +dstring_openstr (dstring_t *dstr, size_t len) { int pos = dstr->size; if (pos && !dstr->str[pos - 1]) diff --git a/libs/util/plist.c b/libs/util/plist.c index db3c607ed..a79131038 100644 --- a/libs/util/plist.c +++ b/libs/util/plist.c @@ -1111,7 +1111,7 @@ PL_GetArray (const char *string, hashctx_t **hashctx) static void write_tabs (dstring_t *dstr, int num) { - char *tabs = dstring_reservestr (dstr, num); + char *tabs = dstring_openstr (dstr, num); memset (tabs, '\t', num); tabs[num] = 0; @@ -1120,7 +1120,7 @@ write_tabs (dstring_t *dstr, int num) static void write_string_len (dstring_t *dstr, const char *str, int len) { - char *dst = dstring_reservestr (dstr, len); + char *dst = dstring_openstr (dstr, len); memcpy (dst, str, len); dst[len] = 0; } @@ -1138,7 +1138,7 @@ static void write_binary (dstring_t *dstr, byte *binary, int len) { int i; - char *dst = dstring_reservestr (dstr, len * 2); + char *dst = dstring_openstr (dstr, len * 2); for (i = 0; i < len; i++) { *dst++ = to_hex (binary[i] >> 4); *dst++ = to_hex (binary[i]); @@ -1159,12 +1159,12 @@ write_string (dstring_t *dstr, const char *str) len++; } if (!quoted) { - dst = dstring_reservestr (dstr, len); + dst = dstring_openstr (dstr, len); strcpy (dst, str); return; } // assume worst case of all octal chars plus two quotes. - dst = dstring_reservestr (dstr, len * 4 + 2); + dst = dstring_openstr (dstr, len * 4 + 2); *dst++= '\"'; while (*str) { if (*str && isascii ((byte) *str) && isprint ((byte) *str) diff --git a/libs/util/test/test-ringbuffer.c b/libs/util/test/test-ringbuffer.c index ece04c992..a9ee2f900 100644 --- a/libs/util/test/test-ringbuffer.c +++ b/libs/util/test/test-ringbuffer.c @@ -127,7 +127,7 @@ locked_reader (void *data) cnd_wait (&rb_read_cnd, &rb_mtx); } unsigned len = RB_DATA_AVAILABLE (ringbuffer_char); - RB_READ_DATA (ringbuffer_char, dstring_reserve (out_text, len), len); + RB_READ_DATA (ringbuffer_char, dstring_open (out_text, len), len); cnd_signal (&rb_write_cnd); mtx_unlock (&rb_mtx); } while (out_text->str[out_text->size - 1]); @@ -193,7 +193,7 @@ free_reader (void *data) while (RB_DATA_AVAILABLE (ringbuffer_atomic) < 1) { } unsigned len = RB_DATA_AVAILABLE (ringbuffer_atomic); - RB_READ_DATA (ringbuffer_atomic, dstring_reserve (out_text, len), len); + RB_READ_DATA (ringbuffer_atomic, dstring_open (out_text, len), len); } while (out_text->str[out_text->size - 1]); return 0;