Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / gmp / printf / obprntffuns.c
1 /* __gmp_obstack_printf_funs -- support for gmp_obstack_printf and
2    gmp_obstack_vprintf.
3
4    THE FUNCTIONS IN THIS FILE ARE FOR INTERNAL USE ONLY.  THEY'RE ALMOST
5    CERTAIN TO BE SUBJECT TO INCOMPATIBLE CHANGES OR DISAPPEAR COMPLETELY IN
6    FUTURE GNU MP RELEASES.
7
8 Copyright 2001 Free Software Foundation, Inc.
9
10 This file is part of the GNU MP Library.
11
12 The GNU MP Library is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as published by
14 the Free Software Foundation; either version 3 of the License, or (at your
15 option) any later version.
16
17 The GNU MP Library is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20 License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
24
25 #include "config.h"
26
27 #if HAVE_OBSTACK_VPRINTF
28
29 #define _GNU_SOURCE   /* ask glibc <stdio.h> for obstack_vprintf */
30
31 #if HAVE_STDARG
32 #include <stdarg.h>
33 #else
34 #include <varargs.h>
35 #endif
36
37 #include <stdio.h>    /* for obstack_vprintf */
38 #include <string.h>
39 #include <obstack.h>
40
41 #include "gmp.h"
42 #include "gmp-impl.h"
43
44
45 static int
46 gmp_obstack_memory (struct obstack *ob, const char *ptr, size_t len)
47 {
48   obstack_grow (ob, ptr, len);
49   return len;
50 }
51
52 static int
53 gmp_obstack_reps (struct obstack *ob, int c, int reps)
54 {
55   obstack_blank (ob, reps);
56   memset ((char *) obstack_next_free(ob) - reps, c, reps);
57   return reps;
58 }
59
60 const struct doprnt_funs_t  __gmp_obstack_printf_funs = {
61   (doprnt_format_t) obstack_vprintf,
62   (doprnt_memory_t) gmp_obstack_memory,
63   (doprnt_reps_t)   gmp_obstack_reps
64 };
65
66 #endif /* HAVE_OBSTACK_VPRINTF */