Mercurial > libpst
comparison src/vbuf.h @ 182:b65e8d0a088a
more cleanup on external names in the shared object file
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 13 Apr 2009 11:39:33 -0700 |
parents | ac6e22c8a9cf |
children |
comparison
equal
deleted
inserted
replaced
181:3b04745ff76d | 182:b65e8d0a088a |
---|---|
1 /* vbuf.h - variable length buffer functions | |
2 * | |
3 * Functions that try to make dealing with buffers easier. | |
4 * | |
5 * vbuf | |
6 * | |
7 * vstr | |
8 * - should always contain a valid string | |
9 * | |
10 */ | |
11 | 1 |
12 #ifndef VBUF_H | 2 #ifndef __PST_VBUF_H |
13 #define VBUF_H | 3 #define __PST_VBUF_H |
14 | 4 |
15 #include "common.h" | 5 #include "common.h" |
16 | 6 |
17 #define SZ_MAX 4096 | |
18 /***************************************************/ | |
19 | |
20 | 7 |
21 // Variable-length buffers | 8 // Variable-length buffers |
22 struct varbuf { | 9 struct pst_varbuf { |
23 size_t dlen; //length of data stored in buffer | 10 size_t dlen; //length of data stored in buffer |
24 size_t blen; //length of buffer | 11 size_t blen; //length of buffer |
25 char *buf; //buffer | 12 char *buf; //buffer |
26 char *b; //start of stored data | 13 char *b; //start of stored data |
27 }; | 14 }; |
28 | 15 |
29 | 16 |
30 // The exact same thing as a varbuf but should always contain at least '\0' | 17 typedef struct pst_varbuf pst_vbuf; |
31 struct varstr { | 18 |
32 size_t dlen; //length of data stored in buffer | 19 pst_vbuf *pst_vballoc(size_t len); |
33 size_t blen; //length of buffer | 20 void pst_vbgrow(pst_vbuf *vb, size_t len); // grow buffer by len bytes, data are preserved |
34 char *buf; //buffer | 21 void pst_vbset(pst_vbuf *vb, void *data, size_t len); |
35 char *b; //start of stored data | 22 void pst_vbappend(pst_vbuf *vb, void *data, size_t length); |
36 }; | 23 void pst_unicode_init(); |
24 size_t pst_vb_utf16to8(pst_vbuf *dest, const char *inbuf, int iblen); | |
25 size_t pst_vb_utf8to8bit(pst_vbuf *dest, const char *inbuf, int iblen, const char* charset); | |
26 size_t pst_vb_8bit2utf8(pst_vbuf *dest, const char *inbuf, int iblen, const char* charset); | |
37 | 27 |
38 | 28 |
39 typedef struct varbuf vbuf; | 29 #endif |
40 typedef struct varstr vstr; | |
41 | |
42 #define VBUF_STATIC(x,y) static vbuf *x = NULL; if(!x) x = pst_vballoc(y); | |
43 #define VSTR_STATIC(x,y) static vstr *x = NULL; if(!x) x = pst_vsalloc(y); | |
44 | |
45 vbuf *pst_vballoc(size_t len); | |
46 void pst_vbgrow(vbuf *vb, size_t len); // grow buffer by len bytes, data are preserved | |
47 void pst_vbset(vbuf *vb, void *data, size_t len); | |
48 void pst_vbappend(vbuf *vb, void *data, size_t length); | |
49 void pst_unicode_init(); | |
50 size_t pst_vb_utf16to8(vbuf *dest, const char *inbuf, int iblen); | |
51 size_t pst_vb_utf8to8bit(vbuf *dest, const char *inbuf, int iblen, const char* charset); | |
52 size_t pst_vb_8bit2utf8(vbuf *dest, const char *inbuf, int iblen, const char* charset); | |
53 | |
54 | |
55 #endif // VBUF_H |