1 /* GCC Quad-Precision Math Library
2 Copyright (C) 2011 Free Software Foundation, Inc.
3 Written by Jakub Jelinek <jakub@redhat.com>
5 This file is part of the libquadmath library.
6 Libquadmath is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 Libquadmath is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public
17 License along with libquadmath; see the file COPYING.LIB. If
18 not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19 Boston, MA 02110-1301, USA. */
26 #ifdef HAVE_LANGINFO_H
38 #ifdef HAVE_PRINTF_HOOKS
44 #include "quadmath-imp.h"
57 #define putwc(c,f) putc(c,f)
62 /* Won't work for EBCDIC. */
66 #define isupper(x) ((x) >= 'A' && (x) <= 'Z')
67 #define isdigit(x) ((x) >= '0' && (x) <= '9')
68 #define tolower(x) (isupper (x) ? (x) - 'A' + 'a' : (x))
72 #ifdef __CHAR_UNSIGNED__
73 #define CHAR_MAX (2 * __SCHAR_MAX__ + 1)
75 #define CHAR_MAX __SCHAR_MAX__
79 #ifndef HAVE_PRINTF_HOOKS
80 #define printf_info __quadmath_printf_info
83 int prec; /* Precision. */
84 int width; /* Width. */
85 wchar_t spec; /* Format letter. */
86 unsigned int is_long_double:1;/* L flag. */
87 unsigned int is_short:1; /* h flag. */
88 unsigned int is_long:1; /* l flag. */
89 unsigned int alt:1; /* # flag. */
90 unsigned int space:1; /* Space flag. */
91 unsigned int left:1; /* - flag. */
92 unsigned int showsign:1; /* + flag. */
93 unsigned int group:1; /* ' flag. */
94 unsigned int extra:1; /* For special use. */
95 unsigned int is_char:1; /* hh flag. */
96 unsigned int wide:1; /* Nonzero for wide character streams. */
97 unsigned int i18n:1; /* I flag. */
98 unsigned short int user; /* Bits for user-installed modifiers. */
99 wchar_t pad; /* Padding character. */
103 struct __quadmath_printf_file
113 __quadmath_printf_fp (struct __quadmath_printf_file *fp,
114 const struct printf_info *info,
115 const void *const *args) attribute_hidden;
117 __quadmath_printf_fphex (struct __quadmath_printf_file *fp,
118 const struct printf_info *info,
119 const void *const *args) attribute_hidden;
121 size_t __quadmath_do_pad (struct __quadmath_printf_file *fp, int wide,
122 int c, size_t n) attribute_hidden;
124 static inline __attribute__((__unused__)) size_t
125 __quadmath_do_put (struct __quadmath_printf_file *fp, int wide,
126 const char *s, size_t n)
134 const wchar_t *ls = (const wchar_t *) s;
135 for (cnt = 0; cnt < n; cnt++)
136 if (putwc (ls[cnt], fp->fp) == WEOF)
140 return fwrite (s, 1, n, fp->fp);
142 len = MIN (fp->size, n);
143 memcpy (fp->str, s, len);
150 static inline __attribute__((__unused__)) int
151 __quadmath_do_putc (struct __quadmath_printf_file *fp, int wide,
155 return wide ? (int) putwc (c, fp->fp) : putc (c, fp->fp);
162 return (unsigned char) c;
165 #define PUT(f, s, n) __quadmath_do_put (f, wide, s, n)
166 #define PAD(f, c, n) __quadmath_do_pad (f, wide, c, n)
167 #define PUTC(c, f) __quadmath_do_putc (f, wide, c)
169 #define nl_langinfo_wc(x) \
170 ({ union { const char *mb; wchar_t wc; } u; u.mb = nl_langinfo (x); u.wc; })
173 #define _itoa __quadmath_itoa