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