~ubuntu-branches/ubuntu/quantal/gclcvs/quantal

« back to all changes in this revision

Viewing changes to gmp3/printf/sprintffuns.c

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-06-24 15:13:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040624151346-xh0xaaktyyp7aorc
Tags: 2.7.0-26
C_GC_OFFSET is 2 on m68k-linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 the GNU Lesser General Public License as published by
 
13
the Free Software Foundation; either version 2.1 of the License, or (at your
 
14
option) any later version.
 
15
 
 
16
The GNU MP Library is distributed in the hope that it will be useful, but
 
17
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
18
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 
19
License for more details.
 
20
 
 
21
You should have received a copy of the GNU Lesser General Public License
 
22
along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
 
23
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 
24
MA 02111-1307, USA. */
 
25
 
 
26
#include "config.h"
 
27
 
 
28
#if HAVE_STDARG
 
29
#include <stdarg.h>
 
30
#else
 
31
#include <varargs.h>
 
32
#endif
 
33
 
 
34
#include <stdio.h>
 
35
#include <stdlib.h>
 
36
#include <string.h>
 
37
 
 
38
#include "gmp.h"
 
39
#include "gmp-impl.h"
 
40
 
 
41
 
 
42
/* The data parameter "bufp" points to a "char *buf" which is the next
 
43
   character to be written, having started as the destination from the
 
44
   application.  This is then increased each time output is produced.  */
 
45
 
 
46
 
 
47
/* If vsprintf returns -1 then pass it upwards.  It doesn't matter that
 
48
   "*bufp" is ruined in this case, since gmp_doprint will bail out
 
49
   immediately anyway.  */
 
50
static int
 
51
gmp_sprintf_format (char **bufp, const char *fmt, va_list ap)
 
52
{
 
53
  char  *buf = *bufp;
 
54
  int   ret;
 
55
  vsprintf (buf, fmt, ap);
 
56
  ret = strlen (buf);
 
57
  *bufp = buf + ret;
 
58
  return ret;  
 
59
}
 
60
 
 
61
static int
 
62
gmp_sprintf_memory (char **bufp, const char *str, size_t len)
 
63
{
 
64
  char  *buf = *bufp;
 
65
  *bufp = buf + len;
 
66
  memcpy (buf, str, len);
 
67
  return len;  
 
68
}
 
69
 
 
70
static int
 
71
gmp_sprintf_reps (char **bufp, int c, int reps)
 
72
{
 
73
  char  *buf = *bufp;
 
74
  ASSERT (reps >= 0);
 
75
  *bufp = buf + reps;
 
76
  memset (buf, c, reps);
 
77
  return reps;  
 
78
}
 
79
 
 
80
static int
 
81
gmp_sprintf_final (char **bufp, int c, int reps)
 
82
{
 
83
  char  *buf = *bufp;
 
84
  *buf = '\0';
 
85
  return 0;
 
86
}
 
87
 
 
88
const struct doprnt_funs_t  __gmp_sprintf_funs = {
 
89
  (doprnt_format_t) gmp_sprintf_format,
 
90
  (doprnt_memory_t) gmp_sprintf_memory,
 
91
  (doprnt_reps_t)   gmp_sprintf_reps,
 
92
  (doprnt_final_t)  gmp_sprintf_final
 
93
};