]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/mempool-fmt.c
Mempool: Converted to size_t.
[libucw.git] / ucw / mempool-fmt.c
index 04345687f85e7f597c741b1ca214d6afbb44d91b..91b39cb6306235e973ed5024a67973c5af6e3f47 100644 (file)
@@ -8,15 +8,15 @@
  *     of the GNU Lesser General Public License.
  */
 
  *     of the GNU Lesser General Public License.
  */
 
-#include "ucw/lib.h"
-#include "ucw/mempool.h"
+#include <ucw/lib.h>
+#include <ucw/mempool.h>
 
 #include <alloca.h>
 #include <stdio.h>
 #include <string.h>
 
 static char *
 
 #include <alloca.h>
 #include <stdio.h>
 #include <string.h>
 
 static char *
-mp_vprintf_at(struct mempool *mp, uns ofs, const char *fmt, va_list args)
+mp_vprintf_at(struct mempool *mp, size_t ofs, const char *fmt, va_list args)
 {
   char *ret = mp_grow(mp, ofs + 1) + ofs;
   va_list args2;
 {
   char *ret = mp_grow(mp, ofs + 1) + ofs;
   va_list args2;
@@ -37,7 +37,7 @@ mp_vprintf_at(struct mempool *mp, uns ofs, const char *fmt, va_list args)
     }
   else if ((uns)cnt >= mp_avail(mp) - ofs)
     {
     }
   else if ((uns)cnt >= mp_avail(mp) - ofs)
     {
-      ret = mp_grow(mp, cnt + 1) + ofs;
+      ret = mp_grow(mp, ofs + cnt + 1) + ofs;
       va_copy(args2, args);
       int cnt2 = vsnprintf(ret, cnt + 1, fmt, args2);
       va_end(args2);
       va_copy(args2, args);
       int cnt2 = vsnprintf(ret, cnt + 1, fmt, args2);
       va_end(args2);
@@ -65,15 +65,15 @@ mp_printf(struct mempool *p, const char *fmt, ...)
 }
 
 char *
 }
 
 char *
-mp_vprintf_append(struct mempool *mp, char *ptr, const char *fmt, va_list args)
+mp_append_vprintf(struct mempool *mp, char *ptr, const char *fmt, va_list args)
 {
 {
-  uns ofs = mp_open(mp, ptr);
+  size_t ofs = mp_open(mp, ptr);
   ASSERT(ofs && !ptr[ofs - 1]);
   return mp_vprintf_at(mp, ofs - 1, fmt, args);
 }
 
 char *
   ASSERT(ofs && !ptr[ofs - 1]);
   return mp_vprintf_at(mp, ofs - 1, fmt, args);
 }
 
 char *
-mp_printf_append(struct mempool *mp, char *ptr, const char *fmt, ...)
+mp_append_printf(struct mempool *mp, char *ptr, const char *fmt, ...)
 {
   va_list args;
   va_start(args, fmt);
 {
   va_list args;
   va_start(args, fmt);
@@ -89,7 +89,7 @@ int main(void)
   struct mempool *mp = mp_new(64);
   char *x = mp_printf(mp, "<Hello, %s!>", "World");
   fputs(x, stdout);
   struct mempool *mp = mp_new(64);
   char *x = mp_printf(mp, "<Hello, %s!>", "World");
   fputs(x, stdout);
-  x = mp_printf_append(mp, x, "<Appended>");
+  x = mp_append_printf(mp, x, "<Appended>");
   fputs(x, stdout);
   x = mp_printf(mp, "<Hello, %50s!>\n", "World");
   fputs(x, stdout);
   fputs(x, stdout);
   x = mp_printf(mp, "<Hello, %50s!>\n", "World");
   fputs(x, stdout);