beta-0.89.2
[luatex.git] / source / libs / gmp / gmp-src / printf / printffuns.c
blob058c6b9d8bc237676785480ed33852b01572566a
1 /* __gmp_fprintf_funs -- support for formatted output to FILEs.
3 THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY. THEY'RE ALMOST
4 CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
5 FUTURE GNU MP RELEASES.
7 Copyright 2001 Free Software Foundation, Inc.
9 This file is part of the GNU MP Library.
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of either:
14 * the GNU Lesser General Public License as published by the Free
15 Software Foundation; either version 3 of the License, or (at your
16 option) any later version.
20 * the GNU General Public License as published by the Free Software
21 Foundation; either version 2 of the License, or (at your option) any
22 later version.
24 or both in parallel, as here.
26 The GNU MP Library is distributed in the hope that it will be useful, but
27 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
28 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 for more details.
31 You should have received copies of the GNU General Public License and the
32 GNU Lesser General Public License along with the GNU MP Library. If not,
33 see https://www.gnu.org/licenses/. */
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <string.h>
39 #include "gmp.h"
40 #include "gmp-impl.h"
42 /* SunOS 4 stdio.h doesn't provide a prototype for this */
43 #if ! HAVE_DECL_VFPRINTF
44 int vfprintf (FILE *, const char *, va_list);
45 #endif
48 static int
49 gmp_fprintf_memory (FILE *fp, const char *str, size_t len)
51 return fwrite (str, 1, len, fp);
54 /* glibc putc is a function, at least when it's in multi-threaded mode or
55 some such, so fwrite chunks instead of making many calls. */
56 static int
57 gmp_fprintf_reps (FILE *fp, int c, int reps)
59 char buf[256];
60 int i, piece, ret;
61 ASSERT (reps >= 0);
63 memset (buf, c, MIN (reps, sizeof (buf)));
64 for (i = reps; i > 0; i -= sizeof (buf))
66 piece = MIN (i, sizeof (buf));
67 ret = fwrite (buf, 1, piece, fp);
68 if (ret == -1)
69 return ret;
70 ASSERT (ret == piece);
73 return reps;
76 const struct doprnt_funs_t __gmp_fprintf_funs = {
77 (doprnt_format_t) vfprintf,
78 (doprnt_memory_t) gmp_fprintf_memory,
79 (doprnt_reps_t) gmp_fprintf_reps,