Merge from vendor branch FILE:
[dragonfly.git] / contrib / sendmail / libsm / vsprintf.c
1 /*
2  * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3  *      All rights reserved.
4  * Copyright (c) 1990, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Chris Torek.
9  *
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.
13  */
14
15 #include <sm/gen.h>
16 SM_RCSID("@(#)$Id: vsprintf.c,v 1.21 2001/09/11 04:04:49 gshapiro Exp $")
17 #include <limits.h>
18 #include <sm/io.h>
19 #include "local.h"
20
21 /*
22 **  SM_VSPRINTF -- format data for "output" into a string
23 **
24 **      Assigned 'str' to a "fake" file pointer. This allows common
25 **      o/p formatting function sm_vprintf() to be used.
26 **
27 **      Parameters:
28 **              str -- location for output
29 **              fmt -- format directives
30 **              ap -- data unit vectors for use by 'fmt'
31 **
32 **      Results:
33 **              result from sm_io_vfprintf()
34 **
35 **      Side Effects:
36 **              Quietly limits the size to INT_MAX though this may
37 **              not prevent SEGV's.
38 */
39
40 int
41 sm_vsprintf(str, fmt, ap)
42         char *str;
43         const char *fmt;
44         SM_VA_LOCAL_DECL
45 {
46         int ret;
47         SM_FILE_T fake;
48
49         fake.sm_magic = SmFileMagic;
50         fake.f_file = -1;
51         fake.f_flags = SMWR | SMSTR;
52         fake.f_bf.smb_base = fake.f_p = (unsigned char *)str;
53         fake.f_bf.smb_size = fake.f_w = INT_MAX;
54         fake.f_timeout = SM_TIME_FOREVER;
55         fake.f_timeoutstate = SM_TIME_BLOCK;
56         fake.f_close = NULL;
57         fake.f_open = NULL;
58         fake.f_read = NULL;
59         fake.f_write = NULL;
60         fake.f_seek = NULL;
61         fake.f_setinfo = fake.f_getinfo = NULL;
62         fake.f_type = "sm_vsprintf:fake";
63         ret = sm_io_vfprintf(&fake, SM_TIME_FOREVER, fmt, ap);
64         *fake.f_p = '\0';
65         return ret;
66 }