lib update
This commit is contained in:
parent
df6048aff1
commit
148b0babda
18
linebuffer.c
18
linebuffer.c
@ -60,6 +60,7 @@ int linebuffer_put(struct linebuffer *buf, const char *src, unsigned int size)
|
||||
{
|
||||
int len = MIN(buf->size - buf->pos, size);
|
||||
memcpy(buf->data + buf->pos, src, len);
|
||||
buf->pos += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
@ -108,13 +109,9 @@ int linebuffer_writefd(struct linebuffer *buf, int fd)
|
||||
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);
|
||||
va_end(az);
|
||||
|
||||
if (len < 0 || len >= (buf->size - buf->pos))
|
||||
return -1;
|
||||
|
||||
@ -122,6 +119,17 @@ int linebuffer_printf(struct linebuffer *buf, const char *fmt, ...)
|
||||
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)
|
||||
{
|
||||
buf->newline = memchr(buf->data, '\n', buf->pos);
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef _LINEBUFFER_H_
|
||||
#define _LINEBUFFER_H_
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
struct linebuffer {
|
||||
unsigned int size;
|
||||
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_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, ...);
|
||||
|
||||
char * linebuffer_getline(struct linebuffer *buf, int *len);
|
||||
|
Loading…
Reference in New Issue
Block a user