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