Austin Schuh | dace2a6 | 2020-08-18 10:56:48 -0700 | [diff] [blame^] | 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, 2018 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 either: |
| 14 | |
| 15 | * the GNU Lesser General Public License as published by the Free |
| 16 | Software Foundation; either version 3 of the License, or (at your |
| 17 | option) any later version. |
| 18 | |
| 19 | or |
| 20 | |
| 21 | * the GNU General Public License as published by the Free Software |
| 22 | Foundation; either version 2 of the License, or (at your option) any |
| 23 | later version. |
| 24 | |
| 25 | or both in parallel, as here. |
| 26 | |
| 27 | The GNU MP Library is distributed in the hope that it will be useful, but |
| 28 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 29 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 30 | for more details. |
| 31 | |
| 32 | You should have received copies of the GNU General Public License and the |
| 33 | GNU Lesser General Public License along with the GNU MP Library. If not, |
| 34 | see https://www.gnu.org/licenses/. */ |
| 35 | |
| 36 | #include "config.h" |
| 37 | |
| 38 | #if HAVE_OBSTACK_VPRINTF |
| 39 | |
| 40 | #define _GNU_SOURCE /* ask glibc <stdio.h> for obstack_vprintf */ |
| 41 | |
| 42 | #include <stdarg.h> |
| 43 | #include <stdio.h> /* for obstack_vprintf */ |
| 44 | #include <string.h> |
| 45 | #include <obstack.h> |
| 46 | |
| 47 | #include "gmp-impl.h" |
| 48 | |
| 49 | |
| 50 | static int |
| 51 | gmp_obstack_memory (struct obstack *ob, const char *ptr, size_t len) |
| 52 | { |
| 53 | obstack_grow (ob, ptr, len); |
| 54 | return len; |
| 55 | } |
| 56 | |
| 57 | static int |
| 58 | gmp_obstack_reps (struct obstack *ob, int c, int reps) |
| 59 | { |
| 60 | obstack_blank (ob, reps); |
| 61 | memset ((char *) obstack_next_free(ob) - reps, c, reps); |
| 62 | return reps; |
| 63 | } |
| 64 | |
| 65 | const struct doprnt_funs_t __gmp_obstack_printf_funs = { |
| 66 | (doprnt_format_t) obstack_vprintf, |
| 67 | (doprnt_memory_t) gmp_obstack_memory, |
| 68 | (doprnt_reps_t) gmp_obstack_reps |
| 69 | }; |
| 70 | |
| 71 | #else |
| 72 | typedef int __gmp_dummy_typedef; |
| 73 | #endif /* HAVE_OBSTACK_VPRINTF */ |