1 #ifndef _VSTRING_VSTREAM_H_INCLUDED_
2 #define _VSTRING_VSTREAM_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /*	vstring_vstream 3h
7 /* SUMMARY
8 /*	auto-resizing string library
9 /* SYNOPSIS
10 /*	#include <vstring_vstream.h>
11 /* DESCRIPTION
12 
13  /*
14   * Utility library.
15   */
16 #include <vstream.h>
17 #include <vstring.h>
18 
19  /*
20   * External interface.
21   */
22 #define VSTRING_GET_FLAG_NONE	(0)
23 #define VSTRING_GET_FLAG_APPEND	(1<<1)	/* append instead of overwrite */
24 
25 extern int WARN_UNUSED_RESULT vstring_get_flags(VSTRING *, VSTREAM *, int);
26 extern int WARN_UNUSED_RESULT vstring_get_flags_nonl(VSTRING *, VSTREAM *, int);
27 extern int WARN_UNUSED_RESULT vstring_get_flags_null(VSTRING *, VSTREAM *, int);
28 extern int WARN_UNUSED_RESULT vstring_get_flags_bound(VSTRING *, VSTREAM *, int, ssize_t);
29 extern int WARN_UNUSED_RESULT vstring_get_flags_nonl_bound(VSTRING *, VSTREAM *, int, ssize_t);
30 extern int WARN_UNUSED_RESULT vstring_get_flags_null_bound(VSTRING *, VSTREAM *, int, ssize_t);
31 
32  /*
33   * Convenience aliases for most use cases.
34   */
35 #define vstring_get(string, stream) \
36 	vstring_get_flags((string), (stream), VSTRING_GET_FLAG_NONE)
37 #define vstring_get_nonl(string, stream) \
38 	vstring_get_flags_nonl((string), (stream), VSTRING_GET_FLAG_NONE)
39 #define vstring_get_null(string, stream) \
40 	vstring_get_flags_null((string), (stream), VSTRING_GET_FLAG_NONE)
41 
42 #define vstring_get_bound(string, stream, size) \
43 	vstring_get_flags_bound((string), (stream), VSTRING_GET_FLAG_NONE, size)
44 #define vstring_get_nonl_bound(string, stream, size) \
45 	vstring_get_flags_nonl_bound((string), (stream), \
46 	    VSTRING_GET_FLAG_NONE, size)
47 #define vstring_get_null_bound(string, stream, size) \
48 	vstring_get_flags_null_bound((string), (stream), \
49 	    VSTRING_GET_FLAG_NONE, size)
50 
51  /*
52   * Backwards compatibility for code that still uses the vstring_fgets()
53   * interface. Unfortunately we can't change the macro name to upper case.
54   */
55 #define vstring_fgets(s, p) \
56 	(vstring_get((s), (p)) == VSTREAM_EOF ? 0 : (s))
57 #define vstring_fgets_nonl(s, p) \
58 	(vstring_get_nonl((s), (p)) == VSTREAM_EOF ? 0 : (s))
59 #define vstring_fgets_null(s, p) \
60 	(vstring_get_null((s), (p)) == VSTREAM_EOF ? 0 : (s))
61 #define vstring_fgets_bound(s, p, l) \
62 	(vstring_get_bound((s), (p), (l)) == VSTREAM_EOF ? 0 : (s))
63 #define vstring_fgets_nonl_bound(s, p, l) \
64 	(vstring_get_nonl_bound((s), (p), (l)) == VSTREAM_EOF ? 0 : (s))
65 
66 /* LICENSE
67 /* .ad
68 /* .fi
69 /*	The Secure Mailer license must be distributed with this software.
70 /* AUTHOR(S)
71 /*	Wietse Venema
72 /*	IBM T.J. Watson Research
73 /*	P.O. Box 704
74 /*	Yorktown Heights, NY 10598, USA
75 /*
76 /*	Wietse Venema
77 /*	Google, Inc.
78 /*	111 8th Avenue
79 /*	New York, NY 10011, USA
80 /*--*/
81 
82 #endif
83