remove .la files
[platform/upstream/gmp.git] / printf / sprintffuns.c
1 /* __gmp_sprintf_funs -- support for gmp_sprintf and gmp_vsprintf.
2
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.
6
7 Copyright 2001 Free Software Foundation, Inc.
8
9 This file is part of the GNU MP Library.
10
11 The GNU MP Library is free software; you can redistribute it and/or modify
12 it under the terms of either:
13
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.
17
18 or
19
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.
23
24 or both in parallel, as here.
25
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.
30
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/.  */
34
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include "gmp.h"
41 #include "gmp-impl.h"
42
43
44 /* The data parameter "bufp" points to a "char *buf" which is the next
45    character to be written, having started as the destination from the
46    application.  This is then increased each time output is produced.  */
47
48
49 /* If vsprintf returns -1 then pass it upwards.  It doesn't matter that
50    "*bufp" is ruined in this case, since gmp_doprint will bail out
51    immediately anyway.  */
52 static int
53 gmp_sprintf_format (char **bufp, const char *fmt, va_list ap)
54 {
55   char  *buf = *bufp;
56   int   ret;
57   vsprintf (buf, fmt, ap);
58   ret = strlen (buf);
59   *bufp = buf + ret;
60   return ret;
61 }
62
63 static int
64 gmp_sprintf_memory (char **bufp, const char *str, size_t len)
65 {
66   char  *buf = *bufp;
67   *bufp = buf + len;
68   memcpy (buf, str, len);
69   return len;
70 }
71
72 static int
73 gmp_sprintf_reps (char **bufp, int c, int reps)
74 {
75   char  *buf = *bufp;
76   ASSERT (reps >= 0);
77   *bufp = buf + reps;
78   memset (buf, c, reps);
79   return reps;
80 }
81
82 static int
83 gmp_sprintf_final (char **bufp, int c, int reps)
84 {
85   char  *buf = *bufp;
86   *buf = '\0';
87   return 0;
88 }
89
90 const struct doprnt_funs_t  __gmp_sprintf_funs = {
91   (doprnt_format_t) gmp_sprintf_format,
92   (doprnt_memory_t) gmp_sprintf_memory,
93   (doprnt_reps_t)   gmp_sprintf_reps,
94   (doprnt_final_t)  gmp_sprintf_final
95 };