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.
16 SM_RCSID("@(#)$Id: snprintf.c,v 1.23 2001/09/11 04:04:49 gshapiro Exp $")
18 #include <sm/varargs.h>
23 ** SM_SNPRINTF -- format a string to a memory location of restricted size
26 ** str -- memory location to place formatted string
27 ** n -- size of buffer pointed to by str, capped to
28 ** a maximum of INT_MAX
29 ** fmt -- the formatting directives
30 ** ... -- the data to satisfy the formatting
34 ** Success: number of bytes that would have been written
35 ** to str, not including the trailing '\0',
36 ** up to a maximum of INT_MAX, as if there was
37 ** no buffer size limitation. If the result >= n
38 ** then the output was truncated.
41 ** If n > 0, then between 0 and n-1 bytes of formatted output
42 ** are written into 'str', followed by a '\0'.
47 sm_snprintf(char *str
, size_t n
, char const *fmt
, ...)
49 sm_snprintf(str
, n
, fmt
, va_alist
)
54 #endif /* SM_VA_STD */
60 /* While snprintf(3) specifies size_t stdio uses an int internally */
65 /* XXX put this into a static? */
66 fake
.sm_magic
= SmFileMagic
;
68 fake
.f_flags
= SMWR
| SMSTR
;
69 fake
.f_cookie
= &fake
;
70 fake
.f_bf
.smb_base
= fake
.f_p
= (unsigned char *)str
;
71 fake
.f_bf
.smb_size
= fake
.f_w
= n
? n
- 1 : 0;
72 fake
.f_timeout
= SM_TIME_FOREVER
;
73 fake
.f_timeoutstate
= SM_TIME_BLOCK
;
79 fake
.f_setinfo
= fake
.f_getinfo
= NULL
;
80 fake
.f_type
= "sm_snprintf:fake";
81 ret
= sm_io_vfprintf(&fake
, SM_TIME_FOREVER
, fmt
, ap
);