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 #define SEAP_STRBUF_MAX 8192
00036
00037 struct strblk {
00038 struct strblk *next;
00039 size_t size;
00040 char data[];
00041 };
00042
00043 typedef struct {
00044 struct strblk *beg;
00045 struct strblk *lbo;
00046 size_t blkmax;
00047 size_t blkoff;
00048 size_t size;
00049 } strbuf_t;
00050
00051 strbuf_t *strbuf_new (size_t max);
00052 void strbuf_free (strbuf_t *buf);
00053
00054 int strbuf_add (strbuf_t *buf, const char *str, size_t len);
00055 int strbuf_addf (strbuf_t *buf, char *str, size_t len);
00056 int strbuf_add0 (strbuf_t *buf, const char *str);
00057 int strbuf_add0f (strbuf_t *buf, char *str);
00058 int strbuf_addc (strbuf_t *buf, char ch);
00059
00060 size_t strbuf_size (strbuf_t *buf);
00061 int strbuf_trunc (strbuf_t *buf, size_t len);
00062 size_t strbuf_length (strbuf_t *buf);
00063
00064 char *strbuf_cstr (strbuf_t *buf);
00065 char *strbuf_cstr_r (strbuf_t *buf, char *str, size_t len);
00066 char *strbuf_copy (strbuf_t *buf, void *dst, size_t len);
00067
00068 size_t strbuf_fwrite (FILE *fp, strbuf_t *buf);
00069 ssize_t strbuf_write (strbuf_t *buf, int fd);
00070
00071 #ifdef __cplusplus
00072 }
00073 #endif
00074
00075 #endif