buf.h 2.0 KB
Newer Older
D
Daniel Veillard 已提交
1
/*
D
Daniel P. Berrange 已提交
2
 * buf.h: buffers for libvirt
D
Daniel Veillard 已提交
3
 *
4
 * Copyright (C) 2005-2008, 2011, 2012 Red Hat, Inc.
D
Daniel Veillard 已提交
5 6 7 8 9 10
 *
 * See COPYING.LIB for the License of this software
 *
 * Daniel Veillard <veillard@redhat.com>
 */

D
Daniel P. Berrange 已提交
11
#ifndef __VIR_BUFFER_H__
12
# define __VIR_BUFFER_H__
D
Daniel Veillard 已提交
13

14
# include "internal.h"
D
Daniel Veillard 已提交
15

E
Eric Blake 已提交
16 17
# include <stdarg.h>

D
Daniel Veillard 已提交
18
/**
D
Daniel P. Berrange 已提交
19
 * virBuffer:
D
Daniel Veillard 已提交
20 21 22
 *
 * A buffer structure.
 */
D
Daniel P. Berrange 已提交
23 24
typedef struct _virBuffer virBuffer;
typedef virBuffer *virBufferPtr;
25

26
# ifndef __VIR_BUFFER_C__
E
Eric Blake 已提交
27
#  define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL }
28

E
Eric Blake 已提交
29
/* This struct must be kept in sync with the real struct
30
   in the buf.c impl file */
D
Daniel P. Berrange 已提交
31
struct _virBuffer {
32 33 34
    unsigned int a;
    unsigned int b;
    unsigned int c;
E
Eric Blake 已提交
35 36
    int d;
    char *e;
D
Daniel Veillard 已提交
37
};
38
# endif
D
Daniel Veillard 已提交
39

E
Eric Blake 已提交
40 41
char *virBufferContentAndReset(virBufferPtr buf);
void virBufferFreeAndReset(virBufferPtr buf);
D
Daniel P. Berrange 已提交
42
int virBufferError(const virBufferPtr buf);
43
unsigned int virBufferUse(const virBufferPtr buf);
E
Eric Blake 已提交
44 45 46
void virBufferAdd(virBufferPtr buf, const char *str, int len);
void virBufferAddChar(virBufferPtr buf, char c);
void virBufferAsprintf(virBufferPtr buf, const char *format, ...)
47
  ATTRIBUTE_FMT_PRINTF(2, 3);
E
Eric Blake 已提交
48
void virBufferVasprintf(virBufferPtr buf, const char *format, va_list ap)
E
Eric Blake 已提交
49
  ATTRIBUTE_FMT_PRINTF(2, 0);
E
Eric Blake 已提交
50
void virBufferStrcat(virBufferPtr buf, ...)
51
  ATTRIBUTE_SENTINEL;
52
void virBufferEscape(virBufferPtr buf, char escape, const char *toescape,
E
Eric Blake 已提交
53 54 55 56 57
                     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 已提交
58
void virBufferEscapeShell(virBufferPtr buf, const char *str);
E
Eric Blake 已提交
59
void virBufferURIEncodeString(virBufferPtr buf, const char *str);
D
Daniel Veillard 已提交
60

61
# define virBufferAddLit(buf_, literal_string_) \
E
Eric Blake 已提交
62
    virBufferAdd(buf_, "" literal_string_ "", sizeof literal_string_ - 1)
63

E
Eric Blake 已提交
64 65 66
void virBufferAdjustIndent(virBufferPtr buf, int indent);
int virBufferGetIndent(const virBufferPtr buf, bool dynamic);

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