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 #ifdef _WIN32
29 #include <io.h>
30 #else
31 #include <unistd.h>
32 #endif
33 #include <stdio.h>
34 #include <sys/types.h>
35 #include "oscap_export.h"
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define SEAP_STRBUF_MAX 8192
42 
43 struct strblk {
44  struct strblk *next;
45  size_t size;
46  char data[];
47 };
48 
49 typedef struct {
50  struct strblk *beg;
51  struct strblk *lbo;
52  size_t blkmax;
53  size_t blkoff;
54  size_t size;
55 } strbuf_t;
56 
57 strbuf_t *strbuf_new(size_t max);
58 void strbuf_free(strbuf_t *buf);
59 
60 int strbuf_add(strbuf_t *buf, const char *str, size_t len);
61 int strbuf_addf(strbuf_t *buf, char *str, size_t len);
62 int strbuf_addc(strbuf_t *buf, char ch);
63 
64 size_t strbuf_size(strbuf_t *buf);
65 int strbuf_trunc(strbuf_t *buf, size_t len);
66 size_t strbuf_length(strbuf_t *buf);
67 
68 char *strbuf_cstr(strbuf_t *buf);
69 char *strbuf_cstr_r(strbuf_t *buf, char *str, size_t len);
70 char *strbuf_copy(strbuf_t *buf, void *dst, size_t len);
71 
72 size_t strbuf_fwrite(FILE *fp, strbuf_t *buf);
73 ssize_t strbuf_write(strbuf_t *buf, int fd);
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* STRBUF_H */
Definition: strbuf.h:49
Definition: strbuf.h:43