Print this page
XXXX update sendmail to 8.14.9
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/sendmail/libsm/vsnprintf.c
+++ new/usr/src/cmd/sendmail/libsm/vsnprintf.c
1 1 /*
2 - * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
2 + * Copyright (c) 2000-2001 Proofpoint, Inc. and its suppliers.
3 3 * All rights reserved.
4 4 * Copyright (c) 1990, 1993
5 5 * The Regents of the University of California. All rights reserved.
6 6 *
7 7 * This code is derived from software contributed to Berkeley by
8 8 * Chris Torek.
9 9 *
10 10 * By using this file, you agree to the terms and conditions set
11 11 * forth in the LICENSE file which can be found at the top level of
12 12 * the sendmail distribution.
13 13 */
14 14
15 -#pragma ident "%Z%%M% %I% %E% SMI"
16 -
17 15 #include <sm/gen.h>
18 -SM_RCSID("@(#)$Id: vsnprintf.c,v 1.21 2001/03/04 23:28:41 ca Exp $")
16 +SM_RCSID("@(#)$Id: vsnprintf.c,v 1.24 2013-11-22 20:51:44 ca Exp $")
19 17 #include <limits.h>
20 18 #include <sm/io.h>
21 19 #include "local.h"
22 20
23 21 /*
24 22 ** SM_VSNPRINTF -- format data for "output" into a string
25 23 **
26 24 ** Assigned 'str' to a "fake" file pointer. This allows common
27 25 ** o/p formatting function sm_vprintf() to be used.
28 26 **
29 27 ** Parameters:
30 28 ** str -- location for output
31 29 ** n -- maximum size for o/p
32 30 ** fmt -- format directives
33 31 ** ap -- data unit vectors for use by 'fmt'
34 32 **
35 33 ** Results:
36 34 ** result from sm_io_vfprintf()
37 35 **
38 36 ** Side Effects:
39 37 ** Limits the size ('n') to INT_MAX.
40 38 */
41 39
42 40 int
43 41 sm_vsnprintf(str, n, fmt, ap)
44 42 char *str;
45 43 size_t n;
46 44 const char *fmt;
47 45 SM_VA_LOCAL_DECL
48 46 {
49 47 int ret;
50 48 char dummy;
51 49 SM_FILE_T fake;
52 50
53 51 /* While snprintf(3) specifies size_t stdio uses an int internally */
54 52 if (n > INT_MAX)
55 53 n = INT_MAX;
56 54
57 55 /* Stdio internals do not deal correctly with zero length buffer */
58 56 if (n == 0)
59 57 {
60 58 str = &dummy;
61 59 n = 1;
62 60 }
63 61 fake.sm_magic = SmFileMagic;
64 62 fake.f_timeout = SM_TIME_FOREVER;
65 63 fake.f_timeoutstate = SM_TIME_BLOCK;
66 64 fake.f_file = -1;
67 65 fake.f_flags = SMWR | SMSTR;
68 66 fake.f_bf.smb_base = fake.f_p = (unsigned char *)str;
69 67 fake.f_bf.smb_size = fake.f_w = n - 1;
70 68 fake.f_close = NULL;
71 69 fake.f_open = NULL;
72 70 fake.f_read = NULL;
73 71 fake.f_write = NULL;
74 72 fake.f_seek = NULL;
75 73 fake.f_setinfo = fake.f_getinfo = NULL;
76 74 fake.f_type = "sm_vsnprintf:fake";
77 75 ret = sm_io_vfprintf(&fake, SM_TIME_FOREVER, fmt, ap);
78 76 *fake.f_p = 0;
79 77 return ret;
80 78 }
|
↓ open down ↓ |
52 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX