Imported Upstream version 2.4.3
[platform/upstream/audit.git] / auparse / data_buf.h
1 /* data_buf.h --
2  * Copyright 2007 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  *      John Dennis <jdennis@redhat.com>
21  */
22
23 #ifndef DATA_BUF_HEADER
24 #define DATA_BUF_HEADER
25
26 /*****************************************************************************/
27 /******************************* Include Files *******************************/
28 /*****************************************************************************/
29 #include "config.h"
30 #include "private.h"
31
32 /*****************************************************************************/
33 /*********************************** Defines *********************************/
34 /*****************************************************************************/
35
36 #define DATABUF_FLAG_PRESERVE_HEAD (1 << 0)
37 #define DATABUF_FLAG_STRING        (2 << 0)
38
39
40 /*****************************************************************************/
41 /******************************* Type Definitions ****************************/
42 /*****************************************************************************/
43
44 typedef struct Databuf {
45     unsigned flags;
46     size_t alloc_size;
47     char *alloc_ptr;
48     size_t offset;
49     size_t len;
50     size_t max_len;
51 } DataBuf;
52
53 /*****************************************************************************/
54 /*************************  External Global Variables  ***********************/
55 /*****************************************************************************/
56
57 /*****************************************************************************/
58 /*****************************  Inline Functions  ****************************/
59 /*****************************************************************************/
60
61 static inline char *databuf_beg(DataBuf *db)
62 {return (db->alloc_ptr == NULL) ? NULL : db->alloc_ptr+db->offset;}
63
64 /*****************************************************************************/
65 /****************************  Exported Functions  ***************************/
66 /*****************************************************************************/
67
68 void databuf_print(DataBuf *db, int print_data, char *fmt, ...) hidden
69 #ifdef __GNUC__
70         __attribute__ ((format (printf, 3, 4)));
71 #else
72         ;
73 #endif
74 int databuf_init(DataBuf *db, size_t size, unsigned flags) hidden;
75 void databuf_free(DataBuf *db) hidden;
76 int databuf_append(DataBuf *db, const char *src, size_t src_size) hidden;
77 int databuf_advance(DataBuf *db, size_t advance) hidden;
78 int databuf_reset(DataBuf *db) hidden;
79
80 #endif