8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsm / stringf.c
blobb839f2cef1f963c21d9b2f78994b6d5bdc06e9e5
1 /*
2 * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include <sm/gen.h>
13 SM_RCSID("@(#)$Id: stringf.c,v 1.13 2001/03/03 03:40:43 ca Exp $")
14 #include <errno.h>
15 #include <stdio.h>
16 #include <sm/exc.h>
17 #include <sm/heap.h>
18 #include <sm/string.h>
19 #include <sm/varargs.h>
22 ** SM_STRINGF_X -- printf() to dynamically allocated string.
24 ** Takes the same arguments as printf.
25 ** It returns a pointer to a dynamically allocated string
26 ** containing the text that printf would print to standard output.
27 ** It raises an exception on error.
28 ** The name comes from a PWB Unix function called stringf.
30 ** Parameters:
31 ** fmt -- format string.
32 ** ... -- arguments for format.
34 ** Returns:
35 ** Pointer to a dynamically allocated string.
37 ** Exceptions:
38 ** F:sm_heap -- out of memory (via sm_vstringf_x()).
41 char *
42 #if SM_VA_STD
43 sm_stringf_x(const char *fmt, ...)
44 #else /* SM_VA_STD */
45 sm_stringf_x(fmt, va_alist)
46 const char *fmt;
47 va_dcl
48 #endif /* SM_VA_STD */
50 SM_VA_LOCAL_DECL
51 char *s;
53 SM_VA_START(ap, fmt);
54 s = sm_vstringf_x(fmt, ap);
55 SM_VA_END(ap);
56 return s;
60 ** SM_VSTRINGF_X -- printf() to dynamically allocated string.
62 ** Parameters:
63 ** fmt -- format string.
64 ** ap -- arguments for format.
66 ** Returns:
67 ** Pointer to a dynamically allocated string.
69 ** Exceptions:
70 ** F:sm_heap -- out of memory
73 char *
74 sm_vstringf_x(fmt, ap)
75 const char *fmt;
76 SM_VA_LOCAL_DECL
78 char *s;
80 sm_vasprintf(&s, fmt, ap);
81 if (s == NULL)
83 if (errno == ENOMEM)
84 sm_exc_raise_x(&SmHeapOutOfMemory);
85 sm_exc_raisenew_x(&SmEtypeOs, errno, "sm_vasprintf", NULL);
87 return s;