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

« back to all changes in this revision

Viewing changes to gmp3/printf/printffuns.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_fprintf_funs -- support for formatted output to FILEs.
 
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 <string.h>
 
36
 
 
37
#include "gmp.h"
 
38
#include "gmp-impl.h"
 
39
 
 
40
/* SunOS 4 stdio.h doesn't provide a prototype for this */
 
41
#if ! HAVE_DECL_VFPRINTF
 
42
int vfprintf _PROTO ((FILE *fp, const char *fmt, va_list ap));
 
43
#endif
 
44
 
 
45
 
 
46
static int
 
47
gmp_fprintf_memory (FILE *fp, const char *str, size_t len)
 
48
{
 
49
  return fwrite (str, 1, len, fp);
 
50
}
 
51
 
 
52
/* glibc putc is a function, at least when it's in multi-threaded mode or
 
53
   some such, so fwrite chunks instead of making many calls. */
 
54
static int
 
55
gmp_fprintf_reps (FILE *fp, int c, int reps)
 
56
{
 
57
  char  buf[256];
 
58
  int   i, piece, ret;
 
59
  ASSERT (reps >= 0);
 
60
 
 
61
  memset (buf, c, MIN (reps, sizeof (buf)));
 
62
  for (i = reps; i > 0; i -= piece)
 
63
    {
 
64
      piece = MIN (reps, sizeof (buf));
 
65
      ret = fwrite (buf, 1, piece, fp);
 
66
      if (ret == -1)
 
67
        return ret;
 
68
      ASSERT (ret == piece);
 
69
    }
 
70
 
 
71
  return reps;
 
72
}
 
73
 
 
74
const struct doprnt_funs_t  __gmp_fprintf_funs = {
 
75
  (doprnt_format_t) vfprintf,
 
76
  (doprnt_memory_t) gmp_fprintf_memory,
 
77
  (doprnt_reps_t)   gmp_fprintf_reps,
 
78
};