Reorganize headers again

This commit is contained in:
Nils O. Selåsdal
2012-11-15 18:26:31 +01:00
parent 4dca24953f
commit 90bbad4346
77 changed files with 99 additions and 2399 deletions
+44 -3
View File
@@ -1,6 +1,8 @@
#include <stdlib.h>
#include <string.h>
#include "ucore_buffer.h"
#include <stdio.h>
#include <stdarg.h>
#include <ucore/ucore_buffer.h>
GBuf*
uc_new_gbuf(size_t initsz)
@@ -43,7 +45,6 @@ uc_gbuf_unref(GBuf *buf)
int
uc_gbuf_append(GBuf *buf,void *data,size_t len)
{
unsigned char *d = data;
unsigned char *gbuf;
if(buf->len - buf->used < len)
@@ -51,12 +52,52 @@ uc_gbuf_append(GBuf *buf,void *data,size_t len)
return -1;
gbuf = buf->buf;
memcpy(gbuf + buf->used,d,len);
memcpy(gbuf + buf->used, data, len);
buf->used += len;
return 0;
}
int uc_gbuf_printf(GBuf *buf, const char *fmt, ...)
{
va_list ap;
va_list apc;
int rc = 0;
int remaining;
va_start(ap, fmt);
//increment buffer if snprintf indicates the results were truncated
do {
va_copy(apc, ap);
char *gbuf;
remaining = uc_gbuf_remaining(buf);
if(rc >= remaining) {
if(uc_gbuf_grow(buf, buf->len + (rc - remaining) + 1)) {
rc = -1;
va_end(apc);
break;
}
remaining = uc_gbuf_remaining(buf);
}
gbuf = buf->buf;
rc = vsnprintf(gbuf + buf->used, remaining, fmt, apc);
va_end(apc);
} while(rc >= remaining);
if(rc > 0)
buf->used += rc;
va_end(ap);
return rc;
}
int
uc_gbuf_grow(GBuf *buf, size_t addlen)
{