2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
10 * By using this file, you agree to the terms and conditions set
11 * forth in the LICENSE file which can be found at the top level of
12 * the sendmail distribution.
15 #pragma ident "%Z%%M% %I% %E% SMI"
18 SM_RCSID("@(#)$Id: vsnprintf.c,v 1.21 2001/03/04 23:28:41 ca Exp $")
24 ** SM_VSNPRINTF -- format data for "output" into a string
26 ** Assigned 'str' to a "fake" file pointer. This allows common
27 ** o/p formatting function sm_vprintf() to be used.
30 ** str -- location for output
31 ** n -- maximum size for o/p
32 ** fmt -- format directives
33 ** ap -- data unit vectors for use by 'fmt'
36 ** result from sm_io_vfprintf()
39 ** Limits the size ('n') to INT_MAX.
43 sm_vsnprintf(str
, n
, fmt
, ap
)
53 /* While snprintf(3) specifies size_t stdio uses an int internally */
57 /* Stdio internals do not deal correctly with zero length buffer */
63 fake
.sm_magic
= SmFileMagic
;
64 fake
.f_timeout
= SM_TIME_FOREVER
;
65 fake
.f_timeoutstate
= SM_TIME_BLOCK
;
67 fake
.f_flags
= SMWR
| SMSTR
;
68 fake
.f_bf
.smb_base
= fake
.f_p
= (unsigned char *)str
;
69 fake
.f_bf
.smb_size
= fake
.f_w
= n
- 1;
75 fake
.f_setinfo
= fake
.f_getinfo
= NULL
;
76 fake
.f_type
= "sm_vsnprintf:fake";
77 ret
= sm_io_vfprintf(&fake
, SM_TIME_FOREVER
, fmt
, ap
);