00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #pragma once
00024 #ifndef STRBUF_H
00025 #define STRBUF_H
00026
00027 #include <stddef.h>
00028 #include <unistd.h>
00029 #include <stdio.h>
00030
00031 #ifdef __cplusplus
00032 extern "C" {
00033 #endif
00034
00035 struct strblk {
00036 struct strblk *next;
00037 size_t size;
00038 char data[];
00039 };
00040
00041 typedef struct {
00042 struct strblk *beg;
00043 struct strblk *lbo;
00044 size_t blkmax;
00045 size_t blkoff;
00046 size_t size;
00047 } strbuf_t;
00048
00049 strbuf_t *strbuf_new (size_t max);
00050 void strbuf_free (strbuf_t *buf);
00051
00052 int strbuf_add (strbuf_t *buf, const char *str, size_t len);
00053 int strbuf_addf (strbuf_t *buf, char *str, size_t len);
00054 int strbuf_add0 (strbuf_t *buf, const char *str);
00055 int strbuf_add0f (strbuf_t *buf, char *str);
00056 int strbuf_addc (strbuf_t *buf, char ch);
00057
00058 size_t strbuf_size (strbuf_t *buf);
00059 int strbuf_trunc (strbuf_t *buf, size_t len);
00060 size_t strbuf_length (strbuf_t *buf);
00061
00062 char *strbuf_cstr (strbuf_t *buf);
00063 char *strbuf_cstr_r (strbuf_t *buf, char *str, size_t len);
00064 char *strbuf_copy (strbuf_t *buf, void *dst, size_t len);
00065
00066 size_t strbuf_fwrite (FILE *fp, strbuf_t *buf);
00067 ssize_t strbuf_write (strbuf_t *buf, int fd);
00068
00069 #ifdef __cplusplus
00070 }
00071 #endif
00072
00073 #endif