lib update

This commit is contained in:
Olaf Rempel 2007-07-14 15:43:35 +02:00
parent df6048aff1
commit 148b0babda
2 changed files with 16 additions and 5 deletions

View File

@ -60,6 +60,7 @@ int linebuffer_put(struct linebuffer *buf, const char *src, unsigned int size)
{ {
int len = MIN(buf->size - buf->pos, size); int len = MIN(buf->size - buf->pos, size);
memcpy(buf->data + buf->pos, src, len); memcpy(buf->data + buf->pos, src, len);
buf->pos += len;
return len; return len;
} }
@ -108,13 +109,9 @@ int linebuffer_writefd(struct linebuffer *buf, int fd)
return len; return len;
} }
int linebuffer_printf(struct linebuffer *buf, const char *fmt, ...) int linebuffer_vprintf(struct linebuffer *buf, const char *fmt, va_list az)
{ {
va_list az;
va_start(az, fmt);
int len = vsnprintf(buf->data + buf->pos, buf->size - buf->pos, fmt, az); int len = vsnprintf(buf->data + buf->pos, buf->size - buf->pos, fmt, az);
va_end(az);
if (len < 0 || len >= (buf->size - buf->pos)) if (len < 0 || len >= (buf->size - buf->pos))
return -1; return -1;
@ -122,6 +119,17 @@ int linebuffer_printf(struct linebuffer *buf, const char *fmt, ...)
return len; return len;
} }
int linebuffer_printf(struct linebuffer *buf, const char *fmt, ...)
{
va_list az;
va_start(az, fmt);
int ret = linebuffer_vprintf(buf, fmt, az);
va_end(az);
return ret;
}
char * linebuffer_getline(struct linebuffer *buf, int *len) char * linebuffer_getline(struct linebuffer *buf, int *len)
{ {
buf->newline = memchr(buf->data, '\n', buf->pos); buf->newline = memchr(buf->data, '\n', buf->pos);

View File

@ -1,6 +1,8 @@
#ifndef _LINEBUFFER_H_ #ifndef _LINEBUFFER_H_
#define _LINEBUFFER_H_ #define _LINEBUFFER_H_
#include <stdarg.h>
struct linebuffer { struct linebuffer {
unsigned int size; unsigned int size;
unsigned int pos; unsigned int pos;
@ -19,6 +21,7 @@ int linebuffer_parsefd(struct linebuffer *buf, int fd);
int linebuffer_writefd(struct linebuffer *buf, int fd); int linebuffer_writefd(struct linebuffer *buf, int fd);
int linebuffer_put(struct linebuffer *buf, const char *src, unsigned int size); int linebuffer_put(struct linebuffer *buf, const char *src, unsigned int size);
int linebuffer_vprintf(struct linebuffer *buf, const char *fmt, va_list ap);
int linebuffer_printf(struct linebuffer *buf, const char *fmt, ...); int linebuffer_printf(struct linebuffer *buf, const char *fmt, ...);
char * linebuffer_getline(struct linebuffer *buf, int *len); char * linebuffer_getline(struct linebuffer *buf, int *len);