virbuffer.h 3.3 KB
Newer Older
D
Daniel Veillard 已提交
1
/*
2
 * virbuffer.h: buffers for libvirt
D
Daniel Veillard 已提交
3
 *
4
 * Copyright (C) 2005-2008, 2011-2013 Red Hat, Inc.
D
Daniel Veillard 已提交
5
 *
O
Osier Yang 已提交
6 7 8 9 10 11 12 13 14 15 16
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
D
Daniel Veillard 已提交
19 20 21 22
 *
 * Daniel Veillard <veillard@redhat.com>
 */

D
Daniel P. Berrange 已提交
23
#ifndef __VIR_BUFFER_H__
24
# define __VIR_BUFFER_H__
D
Daniel Veillard 已提交
25

26
# include "internal.h"
D
Daniel Veillard 已提交
27

E
Eric Blake 已提交
28 29
# include <stdarg.h>

D
Daniel Veillard 已提交
30
/**
D
Daniel P. Berrange 已提交
31
 * virBuffer:
D
Daniel Veillard 已提交
32 33 34
 *
 * A buffer structure.
 */
D
Daniel P. Berrange 已提交
35 36
typedef struct _virBuffer virBuffer;
typedef virBuffer *virBufferPtr;
37

38
# ifndef __VIR_BUFFER_C__
E
Eric Blake 已提交
39
#  define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL }
40

E
Eric Blake 已提交
41
/* This struct must be kept in sync with the real struct
42
   in the buf.c impl file */
D
Daniel P. Berrange 已提交
43
struct _virBuffer {
44 45 46
    unsigned int a;
    unsigned int b;
    unsigned int c;
E
Eric Blake 已提交
47 48
    int d;
    char *e;
D
Daniel Veillard 已提交
49
};
50
# endif
D
Daniel Veillard 已提交
51

52
const char *virBufferCurrentContent(virBufferPtr buf);
E
Eric Blake 已提交
53 54
char *virBufferContentAndReset(virBufferPtr buf);
void virBufferFreeAndReset(virBufferPtr buf);
55
int virBufferError(const virBuffer *buf);
J
Ján Tomko 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
int virBufferCheckErrorInternal(const virBuffer *buf,
                                int domcode,
                                const char *filename,
                                const char *funcname,
                                size_t linenr)
    ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1);
/**
 * virBufferCheckError
 *
 * Checks if the buffer is in error state and reports an error.
 *
 * Returns 0 if no error has occured, otherwise an error is reported
 * and -1 is returned.
 */
# define virBufferCheckError(buf) \
    virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__, \
    __LINE__)
73
unsigned int virBufferUse(const virBuffer *buf);
E
Eric Blake 已提交
74 75 76
void virBufferAdd(virBufferPtr buf, const char *str, int len);
void virBufferAddChar(virBufferPtr buf, char c);
void virBufferAsprintf(virBufferPtr buf, const char *format, ...)
77
  ATTRIBUTE_FMT_PRINTF(2, 3);
E
Eric Blake 已提交
78
void virBufferVasprintf(virBufferPtr buf, const char *format, va_list ap)
E
Eric Blake 已提交
79
  ATTRIBUTE_FMT_PRINTF(2, 0);
E
Eric Blake 已提交
80
void virBufferStrcat(virBufferPtr buf, ...)
81
  ATTRIBUTE_SENTINEL;
82
void virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
E
Eric Blake 已提交
83 84 85 86 87
                     const char *format, const char *str);
void virBufferEscapeString(virBufferPtr buf, const char *format,
                           const char *str);
void virBufferEscapeSexpr(virBufferPtr buf, const char *format,
                          const char *str);
G
Guido Günther 已提交
88
void virBufferEscapeShell(virBufferPtr buf, const char *str);
E
Eric Blake 已提交
89
void virBufferURIEncodeString(virBufferPtr buf, const char *str);
D
Daniel Veillard 已提交
90

91
# define virBufferAddLit(buf_, literal_string_) \
92
    virBufferAdd(buf_, "" literal_string_ "", sizeof(literal_string_) - 1)
93

E
Eric Blake 已提交
94
void virBufferAdjustIndent(virBufferPtr buf, int indent);
95
int virBufferGetIndent(const virBuffer *buf, bool dynamic);
E
Eric Blake 已提交
96

J
Ján Tomko 已提交
97
void virBufferTrim(virBufferPtr buf, const char *trim, int len);
98

D
Daniel P. Berrange 已提交
99
#endif /* __VIR_BUFFER_H__ */