From: Pavel Charvat Date: Mon, 2 Jun 2014 17:33:10 +0000 (+0200) Subject: Growing buffer: Converted to size_t. X-Git-Tag: v6.0~20 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=c1eecd27d6e51eabc43f4d7eb6e00fef33fad17b;p=libucw.git Growing buffer: Converted to size_t. --- diff --git a/ucw/bbuf.c b/ucw/bbuf.c index 67a95da6..91ec8584 100644 --- a/ucw/bbuf.c +++ b/ucw/bbuf.c @@ -13,7 +13,7 @@ #include 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); diff --git a/ucw/bbuf.h b/ucw/bbuf.h index 9e26436b..0cbccbc2 100644 --- a/ucw/bbuf.h +++ b/ucw/bbuf.h @@ -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 diff --git a/ucw/gbuf.h b/ucw/gbuf.h index 4bcbe27d..1f5e68fa 100644 --- a/ucw/gbuf.h +++ b/ucw/gbuf.h @@ -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 <> * 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 * <>. **/ -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);