Browse Source

lib update

master
Olaf Rempel 12 years ago
parent
commit
148b0babda
2 changed files with 16 additions and 5 deletions
  1. +13
    -5
      linebuffer.c
  2. +3
    -0
      linebuffer.h

+ 13
- 5
linebuffer.c 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);
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);


+ 3
- 0
linebuffer.h View File

@@ -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…
Cancel
Save