/*
 * sbuf.h
 *
 * A string buffer library.
 *
 * Header file.
 *
 * History:
 *      21/01/2014 Creation.
 *      27/01/2014 Finish initial API.
 *      13/03/2014 removed the low-level API, as it is redundant with
 *                 _staticinit()/_staticfree().
 *
 * Author: Dario Rodriguez dario@softhome.net
 * This library is licensed on the terms of the GNU LGPL v2+
 */

#ifndef SBUF_H
#define SBUF_H

typedef struct {
        long used;
        long got;
        long size;
        char *buf
} sbuf;

/* sbuf, high level api */
sbuf *sbuf_init(long bufsize);
sbuf *sbuf_staticinit(sbuf *uninitsbuf, long bufsize, char *buf);
void sbuf_free(sbuf *buf);
void sbuf_staticfree(sbuf *buf);

int sbuf_fill(sbuf *buf, int fd, long numbytes);
char *sbuf_getline(sbuf *buf);
void sbuf_discard(sbuf *buf);
void sbuf_wipe(sbuf *buf);

/* sbuf, additional functionality */
char *sbuf_getbytes(sbuf *buf, long numbytes);
long sbuf_count(sbuf *buf);
char *sbuf_ptr(sbuf *buf);
long sbuf_add(sbuf *buf, char *data, long datasize);
long sbuf_addstr(sbuf *buf, char *str);
long sbuf_unused(sbuf *buf);
char *sbuf_ptrunused(sbuf *buf);
long sbuf_addfromunused(sbuf *buf, long numbytes);
long sbuf_send(sbuf *buf, int fd, long numbytes);

#endif