sprintf.c revision 1.1 1 1.1 mrg /* gmp_sprintf -- formatted output to an unrestricted string.
2 1.1 mrg
3 1.1 mrg Copyright 2001 Free Software Foundation, Inc.
4 1.1 mrg
5 1.1 mrg This file is part of the GNU MP Library.
6 1.1 mrg
7 1.1 mrg The GNU MP Library is free software; you can redistribute it and/or modify
8 1.1 mrg it under the terms of the GNU Lesser General Public License as published by
9 1.1 mrg the Free Software Foundation; either version 3 of the License, or (at your
10 1.1 mrg option) any later version.
11 1.1 mrg
12 1.1 mrg The GNU MP Library is distributed in the hope that it will be useful, but
13 1.1 mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 1.1 mrg or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 1.1 mrg License for more details.
16 1.1 mrg
17 1.1 mrg You should have received a copy of the GNU Lesser General Public License
18 1.1 mrg along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
19 1.1 mrg
20 1.1 mrg #include "config.h"
21 1.1 mrg
22 1.1 mrg #if HAVE_STDARG
23 1.1 mrg #include <stdarg.h>
24 1.1 mrg #else
25 1.1 mrg #include <varargs.h>
26 1.1 mrg #endif
27 1.1 mrg
28 1.1 mrg #include <string.h> /* for strlen */
29 1.1 mrg
30 1.1 mrg #include "gmp.h"
31 1.1 mrg #include "gmp-impl.h"
32 1.1 mrg
33 1.1 mrg
34 1.1 mrg int
35 1.1 mrg #if HAVE_STDARG
36 1.1 mrg gmp_sprintf (char *buf, const char *fmt, ...)
37 1.1 mrg #else
38 1.1 mrg gmp_sprintf (va_alist)
39 1.1 mrg va_dcl
40 1.1 mrg #endif
41 1.1 mrg {
42 1.1 mrg #if WANT_ASSERT
43 1.1 mrg int fmtlen = strlen(fmt);
44 1.1 mrg #endif
45 1.1 mrg va_list ap;
46 1.1 mrg int ret;
47 1.1 mrg
48 1.1 mrg #if HAVE_STDARG
49 1.1 mrg va_start (ap, fmt);
50 1.1 mrg #else
51 1.1 mrg char *buf;
52 1.1 mrg const char *fmt;
53 1.1 mrg va_start (ap);
54 1.1 mrg buf = va_arg (ap, char *);
55 1.1 mrg fmt = va_arg (ap, const char *);
56 1.1 mrg #endif
57 1.1 mrg
58 1.1 mrg ret = __gmp_doprnt (&__gmp_sprintf_funs, &buf, fmt, ap);
59 1.1 mrg va_end (ap);
60 1.1 mrg
61 1.1 mrg ASSERT (! MEM_OVERLAP_P (buf, strlen(buf)+1, fmt, fmtlen+1));
62 1.1 mrg
63 1.1 mrg return ret;
64 1.1 mrg }
65