diff th_datastruct.c @ 735:31bc1ed07cf5

Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Dec 2022 12:14:39 +0200
parents 79d06eb6d39f
children ca837a4417f5
line wrap: on
line diff
--- a/th_datastruct.c	Wed Dec 07 11:58:54 2022 +0200
+++ b/th_datastruct.c	Wed Dec 07 12:14:39 2022 +0200
@@ -318,7 +318,7 @@
         return res;
     }
 
-    (*buf)->is_allocated = TRUE;
+    (*buf)->is_allocated = true;
 
     return THERR_OK;
 }
@@ -391,7 +391,7 @@
         return NULL;
 
     th_growbuf_init(buf, mingrow);
-    buf->is_allocated = TRUE;
+    buf->is_allocated = true;
 
     return buf;
 }
@@ -406,131 +406,131 @@
 }
 
 
-BOOL th_growbuf_grow(th_growbuf_t *buf, const size_t amount)
+bool th_growbuf_grow(th_growbuf_t *buf, const size_t amount)
 {
     if (buf == NULL)
-        return FALSE;
+        return false;
 
     if (buf->data == NULL || buf->len + amount >= buf->size)
     {
         buf->size += amount + (buf->mingrow > 0 ? buf->mingrow : TH_BUFGROW);
         if ((buf->data = th_realloc(buf->data, buf->size)) == NULL)
-            return FALSE;
+            return false;
     }
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_puts(th_growbuf_t *buf, const char *str, BOOL eos)
+bool th_growbuf_puts(th_growbuf_t *buf, const char *str, bool eos)
 {
     size_t slen;
     if (str == NULL)
-        return FALSE;
+        return false;
 
     slen = strlen(str);
     if (!th_growbuf_grow(buf, slen + 1))
-        return FALSE;
+        return false;
 
     memcpy(buf->data + buf->len, str, slen + 1);
     buf->len += eos ? (slen + 1) : slen;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_putch(th_growbuf_t *buf, const char ch)
+bool th_growbuf_putch(th_growbuf_t *buf, const char ch)
 {
     if (!th_growbuf_grow(buf, sizeof(char)))
-        return FALSE;
+        return false;
 
     buf->data[buf->len++] = (uint8_t) ch;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_put_str(th_growbuf_t *buf, const void *str, const size_t len)
+bool th_growbuf_put_str(th_growbuf_t *buf, const void *str, const size_t len)
 {
     if (str == NULL)
-        return FALSE;
+        return false;
 
     if (!th_growbuf_grow(buf, len + 1))
-        return FALSE;
+        return false;
 
     memcpy(buf->data + buf->len, str, len + 1);
     buf->len += len;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_put_u8(th_growbuf_t *buf, const uint8_t val)
+bool th_growbuf_put_u8(th_growbuf_t *buf, const uint8_t val)
 {
     if (!th_growbuf_grow(buf, sizeof(uint8_t)))
-        return FALSE;
+        return false;
 
     buf->data[buf->len++] = val;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_put_u16_be(th_growbuf_t *buf, const uint16_t val)
+bool th_growbuf_put_u16_be(th_growbuf_t *buf, const uint16_t val)
 {
     if (!th_growbuf_grow(buf, sizeof(uint16_t)))
-        return FALSE;
+        return false;
 
     buf->data[buf->len++] = (val >> 8) & 0xff;
     buf->data[buf->len++] = val & 0xff;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_put_u16_le(th_growbuf_t *buf, const uint16_t val)
+bool th_growbuf_put_u16_le(th_growbuf_t *buf, const uint16_t val)
 {
     if (!th_growbuf_grow(buf, sizeof(uint16_t)))
-        return FALSE;
+        return false;
 
     buf->data[buf->len++] = val & 0xff;
     buf->data[buf->len++] = (val >> 8) & 0xff;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_put_u32_be(th_growbuf_t *buf, const uint32_t val)
+bool th_growbuf_put_u32_be(th_growbuf_t *buf, const uint32_t val)
 {
     if (!th_growbuf_grow(buf, sizeof(uint32_t)))
-        return FALSE;
+        return false;
 
     buf->data[buf->len++] = (val >> 24) & 0xff;
     buf->data[buf->len++] = (val >> 16) & 0xff;
     buf->data[buf->len++] = (val >> 8) & 0xff;
     buf->data[buf->len++] = val & 0xff;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_growbuf_put_u32_le(th_growbuf_t *buf, const uint32_t val)
+bool th_growbuf_put_u32_le(th_growbuf_t *buf, const uint32_t val)
 {
     if (!th_growbuf_grow(buf, sizeof(uint32_t)))
-        return FALSE;
+        return false;
 
     buf->data[buf->len++] = val & 0xff;
     buf->data[buf->len++] = (val >> 8) & 0xff;
     buf->data[buf->len++] = (val >> 16) & 0xff;
     buf->data[buf->len++] = (val >> 24) & 0xff;
 
-    return TRUE;
+    return true;
 }
 
 
 /*
  * Simple legacy string growing buffer
  */
-BOOL th_strbuf_grow(char **buf, size_t *bufsize, size_t *len, size_t grow)
+bool th_strbuf_grow(char **buf, size_t *bufsize, size_t *len, size_t grow)
 {
     if (*buf == NULL)
         *bufsize = *len = 0;
@@ -540,52 +540,52 @@
         *bufsize += grow + TH_BUFGROW;
         *buf = th_realloc(*buf, *bufsize);
         if (*buf == NULL)
-            return FALSE;
+            return false;
     }
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_strbuf_putch(char **buf, size_t *bufsize, size_t *len, const uint8_t ch)
+bool th_strbuf_putch(char **buf, size_t *bufsize, size_t *len, const uint8_t ch)
 {
     if (!th_strbuf_grow(buf, bufsize, len, 1))
-        return FALSE;
+        return false;
 
     (*buf)[*len] = ch;
     (*len)++;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_strbuf_putsn(char **buf, size_t *bufsize, size_t *len, const char *str, const size_t slen)
+bool th_strbuf_putsn(char **buf, size_t *bufsize, size_t *len, const char *str, const size_t slen)
 {
     if (str == NULL)
-        return FALSE;
+        return false;
 
     if (!th_strbuf_grow(buf, bufsize, len, slen + 1))
-        return FALSE;
+        return false;
 
     memcpy(*buf + *len, str, slen);
     (*len) += slen;
     *(buf + *len + slen) = 0;
 
-    return TRUE;
+    return true;
 }
 
 
-BOOL th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str)
+bool th_strbuf_puts(char **buf, size_t *bufsize, size_t *len, const char *str)
 {
     size_t slen;
     if (str == NULL)
-        return FALSE;
+        return false;
 
     slen = strlen(str);
     if (!th_strbuf_grow(buf, bufsize, len, slen + 1))
-        return FALSE;
+        return false;
 
     memcpy(*buf + *len, str, slen + 1);
     (*len) += slen;
 
-    return TRUE;
+    return true;
 }