]> mj.ucw.cz Git - libucw.git/commitdiff
Growing buffer: Converted to size_t.
authorPavel Charvat <pchar@ucw.cz>
Mon, 2 Jun 2014 17:33:10 +0000 (19:33 +0200)
committerPavel Charvat <pchar@ucw.cz>
Mon, 2 Jun 2014 17:33:10 +0000 (19:33 +0200)
ucw/bbuf.c
ucw/bbuf.h
ucw/gbuf.h

index 67a95da66395cdbe0366620e5192bce3b1fbb8d1..91ec858468e6733fb261c1310cc3c685780088cf 100644 (file)
@@ -13,7 +13,7 @@
 #include <stdio.h>
 
 char *
-bb_vprintf_at(bb_t *bb, uns ofs, const char *fmt, va_list args)
+bb_vprintf_at(bb_t *bb, size_t ofs, const char *fmt, va_list args)
 {
   bb_grow(bb, ofs + 1);
   va_list args2;
@@ -44,7 +44,7 @@ bb_vprintf_at(bb_t *bb, uns ofs, const char *fmt, va_list args)
 }
 
 char *
-bb_printf_at(bb_t *bb, uns ofs, const char *fmt, ...)
+bb_printf_at(bb_t *bb, size_t ofs, const char *fmt, ...)
 {
   va_list args;
   va_start(args, fmt);
index 9e26436b58d99cb7bc804c6406668d8995b8f191..0cbccbc2874a26527e9c35006d2278bea7b1a517 100644 (file)
@@ -29,6 +29,7 @@
  * See @bb_printf().
  **/
 char *bb_vprintf(bb_t *bb, const char *fmt, va_list args);
+
 /**
  * printf() into a growing buffer.
  * Generates a `'\0'`-terminated string at the beginning of the buffer
@@ -37,6 +38,7 @@ char *bb_vprintf(bb_t *bb, const char *fmt, va_list args);
  * See @bb_vprintf().
  **/
 char *bb_printf(bb_t *bb, const char *fmt, ...);
+
 /**
  * Like @bb_vprintf(), but it does not start at the beginning of the
  * buffer, but @ofs bytes further.
@@ -44,10 +46,11 @@ char *bb_printf(bb_t *bb, const char *fmt, ...);
  * Returns pointer to the new string (eg. @ofs bytes after the
  * beginning of buffer).
  **/
-char *bb_vprintf_at(bb_t *bb, uns ofs, const char *fmt, va_list args);
+char *bb_vprintf_at(bb_t *bb, size_t ofs, const char *fmt, va_list args);
+
 /**
  * Like @bb_vprintf_at(), but it takes individual arguments.
  **/
-char *bb_printf_at(bb_t *bb, uns ofs, const char *fmt, ...);
+char *bb_printf_at(bb_t *bb, size_t ofs, const char *fmt, ...);
 
 #endif
index 4bcbe27dc6edcf24f46e8235a42ea5711ffbb849..1f5e68fa1f83abed3a4ea4c0776a2c9d6e60f650 100644 (file)
@@ -27,7 +27,7 @@
  * length of available memory.
  **/
 typedef struct BUF_T {
-  uns len;
+  size_t len;
   GBUF_TYPE *ptr;
 } BUF_T;
 
@@ -60,16 +60,16 @@ static void UNUSED GBUF_PREFIX(done)(BUF_T *b)
  * Use <<fun__GENERIC_LINK_|GBUF_PREFIX|grow|,`GBUF_PREFIX(grow)()`>>
  * for growing.
  **/
-static void UNUSED GBUF_PREFIX(set_size)(BUF_T *b, uns len)
+static void UNUSED GBUF_PREFIX(set_size)(BUF_T *b, size_t len)
 {
   b->len = len;
   b->ptr = xrealloc(b->ptr, len * sizeof(GBUF_TYPE));
 #ifdef GBUF_TRACE
-  GBUF_TRACE(STRINGIFY_EXPANDED(BUF_T) " growing to %u items", len);
+  GBUF_TRACE(STRINGIFY_EXPANDED(BUF_T) " growing to %zu items", len);
 #endif
 }
 
-static void UNUSED GBUF_PREFIX(do_grow)(BUF_T *b, uns len)
+static void UNUSED GBUF_PREFIX(do_grow)(BUF_T *b, size_t len)
 {
   if (len < 2*b->len)                  // to ensure logarithmic cost
     len = 2*b->len;
@@ -85,7 +85,7 @@ static void UNUSED GBUF_PREFIX(do_grow)(BUF_T *b, uns len)
  * any more) by
  * <<fun__GENERIC_LINK_|GBUF_PREFIX|set_size|,`GBUF_PREFIX(set_size)()`>>.
  **/
-static inline GBUF_TYPE *GBUF_PREFIX(grow)(BUF_T *b, uns len)
+static inline GBUF_TYPE *GBUF_PREFIX(grow)(BUF_T *b, size_t len)
 {
   if (unlikely(len > b->len))
     GBUF_PREFIX(do_grow)(b, len);