Open SCAP Library

strbuf.h
1 /*
2 * Copyright 2009 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors:
20 * "Daniel Kopecek" <dkopecek@redhat.com>
21 */
22
23 #pragma once
24 #ifndef STRBUF_H
25 #define STRBUF_H
26
27 #include <stddef.h>
28 #include <unistd.h>
29 #include <stdio.h>
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #define SEAP_STRBUF_MAX 8192
36
37 struct strblk {
38 struct strblk *next;
39 size_t size;
40 char data[];
41 };
42
43 typedef struct {
44 struct strblk *beg;
45 struct strblk *lbo;
46 size_t blkmax;
47 size_t blkoff;
48 size_t size;
49 } strbuf_t;
50
51 strbuf_t *strbuf_new (size_t max);
52 void strbuf_free (strbuf_t *buf);
53
54 int strbuf_add (strbuf_t *buf, const char *str, size_t len);
55 int strbuf_addf (strbuf_t *buf, char *str, size_t len);
56 int strbuf_add0 (strbuf_t *buf, const char *str);
57 int strbuf_add0f (strbuf_t *buf, char *str);
58 int strbuf_addc (strbuf_t *buf, char ch);
59
60 size_t strbuf_size (strbuf_t *buf);
61 int strbuf_trunc (strbuf_t *buf, size_t len);
62 size_t strbuf_length (strbuf_t *buf);
63
64 char *strbuf_cstr (strbuf_t *buf);
65 char *strbuf_cstr_r (strbuf_t *buf, char *str, size_t len);
66 char *strbuf_copy (strbuf_t *buf, void *dst, size_t len);
67
68 size_t strbuf_fwrite (FILE *fp, strbuf_t *buf);
69 ssize_t strbuf_write (strbuf_t *buf, int fd);
70
71 #ifdef __cplusplus
72 }
73 #endif
74
75 #endif /* STRBUF_H */
strbuf_t
Definition: strbuf.h:43
strblk
Definition: strbuf.h:37