3
3
* varbuf.h - variable length expandable buffer handling
5
5
* Copyright © 1994, 1995 Ian Jackson <ian@chiark.greenend.org.uk>
6
* Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>
6
* Copyright © 2008-2011 Guillem Jover <guillem@debian.org>
8
8
* This is free software; you can redistribute it and/or modify
9
9
* it under the terms of the GNU General Public License as published by
33
* varbufinit must be called exactly once before the use of each varbuf
33
* varbuf_init must be called exactly once before the use of each varbuf
34
34
* (including before any call to varbuf_destroy), or the variable must be
35
35
* initialized with VARBUF_INIT.
37
* However, varbufs allocated ‘static’ are properly initialised anyway and
38
* do not need varbufinit; multiple consecutive calls to varbufinit before
37
* However, varbufs allocated ‘static’ are properly initialized anyway and
38
* do not need varbuf_init; multiple consecutive calls to varbuf_init before
39
39
* any use are allowed.
41
41
* varbuf_destroy must be called after a varbuf is finished with, if anything
42
* other than varbufinit has been done. After this you are allowed but
43
* not required to call varbufinit again if you want to start using the
42
* other than varbuf_init has been done. After this you are allowed but
43
* not required to call varbuf_init again if you want to start using the
46
46
* Callers using C++ need not worry about any of this.
65
65
#define VARBUF_INIT { 0, 0, NULL }
67
void varbufinit(struct varbuf *v, size_t size);
67
void varbuf_init(struct varbuf *v, size_t size);
68
68
void varbuf_grow(struct varbuf *v, size_t need_size);
69
69
void varbuf_trunc(struct varbuf *v, size_t used_size);
70
70
char *varbuf_detach(struct varbuf *v);
71
void varbufreset(struct varbuf *v);
71
void varbuf_reset(struct varbuf *v);
72
72
void varbuf_destroy(struct varbuf *v);
74
void varbufaddc(struct varbuf *v, int c);
75
void varbufdupc(struct varbuf *v, int c, size_t n);
76
void varbufsubstc(struct varbuf *v, int c_src, int c_dst);
77
#define varbufaddstr(v, s) varbufaddbuf(v, s, strlen(s))
78
void varbufaddbuf(struct varbuf *v, const void *s, size_t size);
74
void varbuf_add_char(struct varbuf *v, int c);
75
void varbuf_dup_char(struct varbuf *v, int c, size_t n);
76
void varbuf_map_char(struct varbuf *v, int c_src, int c_dst);
77
#define varbuf_add_str(v, s) varbuf_add_buf(v, s, strlen(s))
78
void varbuf_add_buf(struct varbuf *v, const void *s, size_t size);
79
void varbuf_end_str(struct varbuf *v);
80
int varbufprintf(struct varbuf *v, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
81
int varbufvprintf(struct varbuf *v, const char *fmt, va_list va)
81
int varbuf_printf(struct varbuf *v, const char *fmt, ...) DPKG_ATTR_PRINTF(2);
82
int varbuf_vprintf(struct varbuf *v, const char *fmt, va_list va)
82
83
DPKG_ATTR_VPRINTF(2);