3 #ifndef _VSTRING_H_INCLUDED_
4 #define _VSTRING_H_INCLUDED_
10 /* arbitrary-length string manager
12 /* #include "vstring.h"
27 * We can't allow bare VBUFs in the interface, because VSTRINGs have a
28 * specific initialization and destruction sequence.
30 typedef struct VSTRING
{
35 extern VSTRING
*vstring_alloc(ssize_t
);
36 extern void vstring_ctl(VSTRING
*,...);
37 extern VSTRING
*vstring_truncate(VSTRING
*, ssize_t
);
38 extern VSTRING
*vstring_free(VSTRING
*);
39 extern VSTRING
*vstring_strcpy(VSTRING
*, const char *);
40 extern VSTRING
*vstring_strncpy(VSTRING
*, const char *, ssize_t
);
41 extern VSTRING
*vstring_strcat(VSTRING
*, const char *);
42 extern VSTRING
*vstring_strncat(VSTRING
*, const char *, ssize_t
);
43 extern VSTRING
*vstring_memcpy(VSTRING
*, const char *, ssize_t
);
44 extern VSTRING
*vstring_memcat(VSTRING
*, const char *, ssize_t
);
45 extern char *vstring_memchr(VSTRING
*, int);
46 extern VSTRING
*vstring_insert(VSTRING
*, ssize_t
, const char *, ssize_t
);
47 extern VSTRING
*vstring_prepend(VSTRING
*, const char *, ssize_t
);
48 extern VSTRING
*PRINTFLIKE(2, 3) vstring_sprintf(VSTRING
*, const char *,...);
49 extern VSTRING
*PRINTFLIKE(2, 3) vstring_sprintf_append(VSTRING
*, const char *,...);
50 extern VSTRING
*PRINTFLIKE(2, 3) vstring_sprintf_prepend(VSTRING
*, const char *, ...);
51 extern char *vstring_export(VSTRING
*);
52 extern VSTRING
*vstring_import(char *);
54 #define VSTRING_CTL_MAXLEN 1
55 #define VSTRING_CTL_END 0
58 * Macros. Unsafe macros have UPPERCASE names.
60 #define VSTRING_SPACE(vp, len) ((vp)->vbuf.space(&(vp)->vbuf, len))
61 #define vstring_str(vp) ((char *) (vp)->vbuf.data)
62 #define VSTRING_LEN(vp) ((ssize_t) ((vp)->vbuf.ptr - (vp)->vbuf.data))
63 #define vstring_end(vp) ((char *) (vp)->vbuf.ptr)
64 #define VSTRING_TERMINATE(vp) do { \
65 if ((vp)->vbuf.cnt <= 0) \
66 VSTRING_SPACE((vp),1); \
67 *(vp)->vbuf.ptr = 0; \
69 #define VSTRING_RESET(vp) do { \
70 (vp)->vbuf.ptr = (vp)->vbuf.data; \
71 (vp)->vbuf.cnt = (vp)->vbuf.len; \
73 #define VSTRING_ADDCH(vp, ch) VBUF_PUT(&(vp)->vbuf, ch)
74 #define VSTRING_SKIP(vp) do { \
75 while ((vp)->vbuf.cnt > 0 && *(vp)->vbuf.ptr) \
76 (vp)->vbuf.ptr++, (vp)->vbuf.cnt--; \
78 #define vstring_avail(vp) ((vp)->vbuf.cnt)
81 * The following macro is not part of the public interface, because it can
82 * really screw up a buffer by positioning past allocated memory.
84 #define VSTRING_AT_OFFSET(vp, offset) do { \
85 (vp)->vbuf.ptr = (vp)->vbuf.data + (offset); \
86 (vp)->vbuf.cnt = (vp)->vbuf.len - (offset); \
89 extern VSTRING
*vstring_vsprintf(VSTRING
*, const char *, va_list);
90 extern VSTRING
*vstring_vsprintf_append(VSTRING
*, const char *, va_list);
93 /* Auto-resizing may change the address of the string data in
94 /* a vstring structure. Beware of dangling pointers.
98 /* A vstring module appears in the UNPROTO software by Wietse Venema.
102 /* The Secure Mailer license must be distributed with this software.
105 /* IBM T.J. Watson Research
107 /* Yorktown Heights, NY 10598, USA