Initial revision
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3008 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
SubDir OBOS_TOP src kernel libroot posix glibc stdio-common ;
|
||||||
|
|
||||||
|
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include arch $(OBOS_ARCH) ;
|
||||||
|
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc stdio-common ;
|
||||||
|
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc libio ;
|
||||||
|
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc include ;
|
||||||
|
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc locale ;
|
||||||
|
SubDirHdrs $(OBOS_TOP) src kernel libroot posix glibc ;
|
||||||
|
|
||||||
|
SubDirCcFlags -imacrolibc-symbols.h ;
|
||||||
|
|
||||||
|
# ToDo: for now, all wide character functions are disabled
|
||||||
|
|
||||||
|
KernelMergeObject posix_gnu_stdio_common.o :
|
||||||
|
<$(SOURCE_GRIST)>_itoa.c
|
||||||
|
# <$(SOURCE_GRIST)>_itowa.c
|
||||||
|
<$(SOURCE_GRIST)>asprintf.c
|
||||||
|
<$(SOURCE_GRIST)>dprintf.c
|
||||||
|
<$(SOURCE_GRIST)>fprintf.c
|
||||||
|
<$(SOURCE_GRIST)>fscanf.c
|
||||||
|
<$(SOURCE_GRIST)>getline.c
|
||||||
|
<$(SOURCE_GRIST)>getw.c
|
||||||
|
<$(SOURCE_GRIST)>itoa-digits.c
|
||||||
|
<$(SOURCE_GRIST)>itoa-udigits.c
|
||||||
|
# <$(SOURCE_GRIST)>itowa-digits.c
|
||||||
|
# <$(SOURCE_GRIST)>perror.c
|
||||||
|
<$(SOURCE_GRIST)>printf-prs.c
|
||||||
|
<$(SOURCE_GRIST)>printf.c
|
||||||
|
<$(SOURCE_GRIST)>printf_fp.c
|
||||||
|
<$(SOURCE_GRIST)>printf_size.c
|
||||||
|
<$(SOURCE_GRIST)>putw.c
|
||||||
|
<$(SOURCE_GRIST)>reg-printf.c
|
||||||
|
<$(SOURCE_GRIST)>scanf.c
|
||||||
|
<$(SOURCE_GRIST)>snprintf.c
|
||||||
|
<$(SOURCE_GRIST)>sprintf.c
|
||||||
|
<$(SOURCE_GRIST)>sscanf.c
|
||||||
|
<$(SOURCE_GRIST)>tempnam.c
|
||||||
|
<$(SOURCE_GRIST)>tmpnam.c
|
||||||
|
<$(SOURCE_GRIST)>tmpnam_r.c
|
||||||
|
<$(SOURCE_GRIST)>vfprintf.c
|
||||||
|
<$(SOURCE_GRIST)>vfscanf.c
|
||||||
|
# <$(SOURCE_GRIST)>vfwprintf.c
|
||||||
|
# <$(SOURCE_GRIST)>vfwscanf.c
|
||||||
|
<$(SOURCE_GRIST)>vprintf.c
|
||||||
|
:
|
||||||
|
-fPIC -DPIC
|
||||||
|
;
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/* Copyright (C) 2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, 2000.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include "../locale/outdigits.h"
|
||||||
|
#include "../locale/outdigitswc.h"
|
||||||
|
|
||||||
|
static CHAR_T *
|
||||||
|
_i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr)
|
||||||
|
{
|
||||||
|
CHAR_T *src, *s;
|
||||||
|
|
||||||
|
/* Copy existing string so that nothing gets overwritten. */
|
||||||
|
src = (CHAR_T *) alloca ((rear_ptr - w) * sizeof (CHAR_T));
|
||||||
|
s = (CHAR_T *) __mempcpy (src, w,
|
||||||
|
(rear_ptr - w) * sizeof (CHAR_T));
|
||||||
|
w = rear_ptr;
|
||||||
|
|
||||||
|
/* Process all characters in the string. */
|
||||||
|
while (--s >= src)
|
||||||
|
{
|
||||||
|
if (*s >= '0' && *s <= '9')
|
||||||
|
{
|
||||||
|
if (sizeof (CHAR_T) == 1)
|
||||||
|
w = (CHAR_T *) outdigit_value ((char *) w, *s - '0');
|
||||||
|
else
|
||||||
|
*--w = (CHAR_T) outdigitwc_value (*s - '0');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*--w = *s;
|
||||||
|
}
|
||||||
|
|
||||||
|
return w;
|
||||||
|
}
|
||||||
@@ -0,0 +1,426 @@
|
|||||||
|
/* Internal function for converting integers to ASCII.
|
||||||
|
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2002, 2003
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Torbjorn Granlund <[email protected]>
|
||||||
|
and Ulrich Drepper <[email protected]>.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <gmp-mparam.h>
|
||||||
|
#include <gmp.h>
|
||||||
|
#include <stdlib/gmp-impl.h>
|
||||||
|
#include <stdlib/longlong.h>
|
||||||
|
|
||||||
|
#include "_itoa.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Canonize environment. For some architectures not all values might
|
||||||
|
be defined in the GMP header files. */
|
||||||
|
#ifndef UMUL_TIME
|
||||||
|
# define UMUL_TIME 1
|
||||||
|
#endif
|
||||||
|
#ifndef UDIV_TIME
|
||||||
|
# define UDIV_TIME 3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Control memory layout. */
|
||||||
|
#ifdef PACK
|
||||||
|
# undef PACK
|
||||||
|
# define PACK __attribute__ ((packed))
|
||||||
|
#else
|
||||||
|
# define PACK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Declare local types. */
|
||||||
|
struct base_table_t
|
||||||
|
{
|
||||||
|
#if (UDIV_TIME > 2 * UMUL_TIME)
|
||||||
|
mp_limb_t base_multiplier;
|
||||||
|
#endif
|
||||||
|
char flag;
|
||||||
|
char post_shift;
|
||||||
|
#if BITS_PER_MP_LIMB == 32
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
char normalization_steps;
|
||||||
|
char ndigits;
|
||||||
|
mp_limb_t base PACK;
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
mp_limb_t base_ninv PACK;
|
||||||
|
#endif
|
||||||
|
} big;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/* To reduce the memory needed we include some fields of the tables
|
||||||
|
only conditionally. */
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
# define SEL1(X) X,
|
||||||
|
# define SEL2(X) ,X
|
||||||
|
#else
|
||||||
|
# define SEL1(X)
|
||||||
|
# define SEL2(X)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Local variables. */
|
||||||
|
const struct base_table_t _itoa_base_table[] attribute_hidden =
|
||||||
|
{
|
||||||
|
#if BITS_PER_MP_LIMB == 64
|
||||||
|
/* 2 */ {SEL1(0ull) 1, 1},
|
||||||
|
/* 3 */ {SEL1(0xaaaaaaaaaaaaaaabull) 0, 1},
|
||||||
|
/* 4 */ {SEL1(0ull) 1, 2},
|
||||||
|
/* 5 */ {SEL1(0xcccccccccccccccdull) 0, 2},
|
||||||
|
/* 6 */ {SEL1(0xaaaaaaaaaaaaaaabull) 0, 2},
|
||||||
|
/* 7 */ {SEL1(0x2492492492492493ull) 1, 3},
|
||||||
|
/* 8 */ {SEL1(0ull) 1, 3},
|
||||||
|
/* 9 */ {SEL1(0xe38e38e38e38e38full) 0, 3},
|
||||||
|
/* 10 */ {SEL1(0xcccccccccccccccdull) 0, 3},
|
||||||
|
/* 11 */ {SEL1(0x2e8ba2e8ba2e8ba3ull) 0, 1},
|
||||||
|
/* 12 */ {SEL1(0xaaaaaaaaaaaaaaabull) 0, 3},
|
||||||
|
/* 13 */ {SEL1(0x4ec4ec4ec4ec4ec5ull) 0, 2},
|
||||||
|
/* 14 */ {SEL1(0x2492492492492493ull) 1, 4},
|
||||||
|
/* 15 */ {SEL1(0x8888888888888889ull) 0, 3},
|
||||||
|
/* 16 */ {SEL1(0ull) 1, 4},
|
||||||
|
/* 17 */ {SEL1(0xf0f0f0f0f0f0f0f1ull) 0, 4},
|
||||||
|
/* 18 */ {SEL1(0xe38e38e38e38e38full) 0, 4},
|
||||||
|
/* 19 */ {SEL1(0xd79435e50d79435full) 0, 4},
|
||||||
|
/* 20 */ {SEL1(0xcccccccccccccccdull) 0, 4},
|
||||||
|
/* 21 */ {SEL1(0x8618618618618619ull) 1, 5},
|
||||||
|
/* 22 */ {SEL1(0x2e8ba2e8ba2e8ba3ull) 0, 2},
|
||||||
|
/* 23 */ {SEL1(0x642c8590b21642c9ull) 1, 5},
|
||||||
|
/* 24 */ {SEL1(0xaaaaaaaaaaaaaaabull) 0, 4},
|
||||||
|
/* 25 */ {SEL1(0x47ae147ae147ae15ull) 1, 5},
|
||||||
|
/* 26 */ {SEL1(0x4ec4ec4ec4ec4ec5ull) 0, 3},
|
||||||
|
/* 27 */ {SEL1(0x97b425ed097b425full) 0, 4},
|
||||||
|
/* 28 */ {SEL1(0x2492492492492493ull) 1, 5},
|
||||||
|
/* 29 */ {SEL1(0x1a7b9611a7b9611bull) 1, 5},
|
||||||
|
/* 30 */ {SEL1(0x8888888888888889ull) 0, 4},
|
||||||
|
/* 31 */ {SEL1(0x0842108421084211ull) 1, 5},
|
||||||
|
/* 32 */ {SEL1(0ull) 1, 5},
|
||||||
|
/* 33 */ {SEL1(0x0f83e0f83e0f83e1ull) 0, 1},
|
||||||
|
/* 34 */ {SEL1(0xf0f0f0f0f0f0f0f1ull) 0, 5},
|
||||||
|
/* 35 */ {SEL1(0xea0ea0ea0ea0ea0full) 0, 5},
|
||||||
|
/* 36 */ {SEL1(0xe38e38e38e38e38full) 0, 5}
|
||||||
|
#endif
|
||||||
|
#if BITS_PER_MP_LIMB == 32
|
||||||
|
/* 2 */ {SEL1(0ul) 1, 1, {0, 31, 0x80000000ul SEL2(0xfffffffful)}},
|
||||||
|
/* 3 */ {SEL1(0xaaaaaaabul) 0, 1, {0, 20, 0xcfd41b91ul SEL2(0x3b563c24ul)}},
|
||||||
|
/* 4 */ {SEL1(0ul) 1, 2, {1, 15, 0x40000000ul SEL2(0xfffffffful)}},
|
||||||
|
/* 5 */ {SEL1(0xcccccccdul) 0, 2, {1, 13, 0x48c27395ul SEL2(0xc25c2684ul)}},
|
||||||
|
/* 6 */ {SEL1(0xaaaaaaabul) 0, 2, {0, 12, 0x81bf1000ul SEL2(0xf91bd1b6ul)}},
|
||||||
|
/* 7 */ {SEL1(0x24924925ul) 1, 3, {1, 11, 0x75db9c97ul SEL2(0x1607a2cbul)}},
|
||||||
|
/* 8 */ {SEL1(0ul) 1, 3, {1, 10, 0x40000000ul SEL2(0xfffffffful)}},
|
||||||
|
/* 9 */ {SEL1(0x38e38e39ul) 0, 1, {0, 10, 0xcfd41b91ul SEL2(0x3b563c24ul)}},
|
||||||
|
/* 10 */ {SEL1(0xcccccccdul) 0, 3, {2, 9, 0x3b9aca00ul SEL2(0x12e0be82ul)}},
|
||||||
|
/* 11 */ {SEL1(0xba2e8ba3ul) 0, 3, {0, 9, 0x8c8b6d2bul SEL2(0xd24cde04ul)}},
|
||||||
|
/* 12 */ {SEL1(0xaaaaaaabul) 0, 3, {3, 8, 0x19a10000ul SEL2(0x3fa39ab5ul)}},
|
||||||
|
/* 13 */ {SEL1(0x4ec4ec4ful) 0, 2, {2, 8, 0x309f1021ul SEL2(0x50f8ac5ful)}},
|
||||||
|
/* 14 */ {SEL1(0x24924925ul) 1, 4, {1, 8, 0x57f6c100ul SEL2(0x74843b1eul)}},
|
||||||
|
/* 15 */ {SEL1(0x88888889ul) 0, 3, {0, 8, 0x98c29b81ul SEL2(0xad0326c2ul)}},
|
||||||
|
/* 16 */ {SEL1(0ul) 1, 4, {3, 7, 0x10000000ul SEL2(0xfffffffful)}},
|
||||||
|
/* 17 */ {SEL1(0xf0f0f0f1ul) 0, 4, {3, 7, 0x18754571ul SEL2(0x4ef0b6bdul)}},
|
||||||
|
/* 18 */ {SEL1(0x38e38e39ul) 0, 2, {2, 7, 0x247dbc80ul SEL2(0xc0fc48a1ul)}},
|
||||||
|
/* 19 */ {SEL1(0xaf286bcbul) 1, 5, {2, 7, 0x3547667bul SEL2(0x33838942ul)}},
|
||||||
|
/* 20 */ {SEL1(0xcccccccdul) 0, 4, {1, 7, 0x4c4b4000ul SEL2(0xad7f29abul)}},
|
||||||
|
/* 21 */ {SEL1(0x86186187ul) 1, 5, {1, 7, 0x6b5a6e1dul SEL2(0x313c3d15ul)}},
|
||||||
|
/* 22 */ {SEL1(0xba2e8ba3ul) 0, 4, {0, 7, 0x94ace180ul SEL2(0xb8cca9e0ul)}},
|
||||||
|
/* 23 */ {SEL1(0xb21642c9ul) 0, 4, {0, 7, 0xcaf18367ul SEL2(0x42ed6de9ul)}},
|
||||||
|
/* 24 */ {SEL1(0xaaaaaaabul) 0, 4, {4, 6, 0x0b640000ul SEL2(0x67980e0bul)}},
|
||||||
|
/* 25 */ {SEL1(0x51eb851ful) 0, 3, {4, 6, 0x0e8d4a51ul SEL2(0x19799812ul)}},
|
||||||
|
/* 26 */ {SEL1(0x4ec4ec4ful) 0, 3, {3, 6, 0x1269ae40ul SEL2(0xbce85396ul)}},
|
||||||
|
/* 27 */ {SEL1(0x2f684bdbul) 1, 5, {3, 6, 0x17179149ul SEL2(0x62c103a9ul)}},
|
||||||
|
/* 28 */ {SEL1(0x24924925ul) 1, 5, {3, 6, 0x1cb91000ul SEL2(0x1d353d43ul)}},
|
||||||
|
/* 29 */ {SEL1(0x8d3dcb09ul) 0, 4, {2, 6, 0x23744899ul SEL2(0xce1deceaul)}},
|
||||||
|
/* 30 */ {SEL1(0x88888889ul) 0, 4, {2, 6, 0x2b73a840ul SEL2(0x790fc511ul)}},
|
||||||
|
/* 31 */ {SEL1(0x08421085ul) 1, 5, {2, 6, 0x34e63b41ul SEL2(0x35b865a0ul)}},
|
||||||
|
/* 32 */ {SEL1(0ul) 1, 5, {1, 6, 0x40000000ul SEL2(0xfffffffful)}},
|
||||||
|
/* 33 */ {SEL1(0x3e0f83e1ul) 0, 3, {1, 6, 0x4cfa3cc1ul SEL2(0xa9aed1b3ul)}},
|
||||||
|
/* 34 */ {SEL1(0xf0f0f0f1ul) 0, 5, {1, 6, 0x5c13d840ul SEL2(0x63dfc229ul)}},
|
||||||
|
/* 35 */ {SEL1(0xd41d41d5ul) 1, 6, {1, 6, 0x6d91b519ul SEL2(0x2b0fee30ul)}},
|
||||||
|
/* 36 */ {SEL1(0x38e38e39ul) 0, 3, {0, 6, 0x81bf1000ul SEL2(0xf91bd1b6ul)}}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Lower-case digits. */
|
||||||
|
extern const char _itoa_lower_digits[];
|
||||||
|
extern const char _itoa_lower_digits_internal[] attribute_hidden;
|
||||||
|
/* Upper-case digits. */
|
||||||
|
extern const char _itoa_upper_digits[];
|
||||||
|
extern const char _itoa_upper_digits_internal[] attribute_hidden;
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
_itoa (value, buflim, base, upper_case)
|
||||||
|
unsigned long long int value;
|
||||||
|
char *buflim;
|
||||||
|
unsigned int base;
|
||||||
|
int upper_case;
|
||||||
|
{
|
||||||
|
const char *digits = (upper_case
|
||||||
|
? INTUSE(_itoa_upper_digits)
|
||||||
|
: INTUSE(_itoa_lower_digits));
|
||||||
|
const struct base_table_t *brec = &_itoa_base_table[base - 2];
|
||||||
|
|
||||||
|
switch (base)
|
||||||
|
{
|
||||||
|
#define RUN_2N(BITS) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
/* `unsigned long long int' always has 64 bits. */ \
|
||||||
|
mp_limb_t work_hi = value >> (64 - BITS_PER_MP_LIMB); \
|
||||||
|
\
|
||||||
|
if (BITS_PER_MP_LIMB == 32) \
|
||||||
|
{ \
|
||||||
|
if (work_hi != 0) \
|
||||||
|
{ \
|
||||||
|
mp_limb_t work_lo; \
|
||||||
|
int cnt; \
|
||||||
|
\
|
||||||
|
work_lo = value & 0xfffffffful; \
|
||||||
|
for (cnt = BITS_PER_MP_LIMB / BITS; cnt > 0; --cnt) \
|
||||||
|
{ \
|
||||||
|
*--buflim = digits[work_lo & ((1ul << BITS) - 1)]; \
|
||||||
|
work_lo >>= BITS; \
|
||||||
|
} \
|
||||||
|
if (BITS_PER_MP_LIMB % BITS != 0) \
|
||||||
|
{ \
|
||||||
|
work_lo \
|
||||||
|
|= ((work_hi \
|
||||||
|
& ((1 << (BITS - BITS_PER_MP_LIMB%BITS)) \
|
||||||
|
- 1)) \
|
||||||
|
<< BITS_PER_MP_LIMB % BITS); \
|
||||||
|
work_hi >>= BITS - BITS_PER_MP_LIMB % BITS; \
|
||||||
|
if (work_hi == 0) \
|
||||||
|
work_hi = work_lo; \
|
||||||
|
else \
|
||||||
|
*--buflim = digits[work_lo]; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
work_hi = value & 0xfffffffful; \
|
||||||
|
} \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
*--buflim = digits[work_hi & ((1 << BITS) - 1)]; \
|
||||||
|
work_hi >>= BITS; \
|
||||||
|
} \
|
||||||
|
while (work_hi != 0); \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
case 8:
|
||||||
|
RUN_2N (3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
RUN_2N (4);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
#if BITS_PER_MP_LIMB == 64
|
||||||
|
mp_limb_t base_multiplier = brec->base_multiplier;
|
||||||
|
if (brec->flag)
|
||||||
|
while (value != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, value, base_multiplier);
|
||||||
|
quo = (x + ((value - x) >> 1)) >> (brec->post_shift - 1);
|
||||||
|
rem = value - quo * base;
|
||||||
|
*--buflim = digits[rem];
|
||||||
|
value = quo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (value != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, value, base_multiplier);
|
||||||
|
quo = x >> brec->post_shift;
|
||||||
|
rem = value - quo * base;
|
||||||
|
*--buflim = digits[rem];
|
||||||
|
value = quo;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if BITS_PER_MP_LIMB == 32
|
||||||
|
mp_limb_t t[3];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
/* First convert x0 to 1-3 words in base s->big.base.
|
||||||
|
Optimize for frequent cases of 32 bit numbers. */
|
||||||
|
if ((mp_limb_t) (value >> 32) >= 1)
|
||||||
|
{
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME || UDIV_NEEDS_NORMALIZATION
|
||||||
|
int big_normalization_steps = brec->big.normalization_steps;
|
||||||
|
mp_limb_t big_base_norm
|
||||||
|
= brec->big.base << big_normalization_steps;
|
||||||
|
#endif
|
||||||
|
if ((mp_limb_t) (value >> 32) >= brec->big.base)
|
||||||
|
{
|
||||||
|
mp_limb_t x1hi, x1lo, r;
|
||||||
|
/* If you want to optimize this, take advantage of
|
||||||
|
that the quotient in the first udiv_qrnnd will
|
||||||
|
always be very small. It might be faster just to
|
||||||
|
subtract in a tight loop. */
|
||||||
|
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
mp_limb_t x, xh, xl;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = 0;
|
||||||
|
else
|
||||||
|
xh = (mp_limb_t) (value >> (64 - big_normalization_steps));
|
||||||
|
xl = (mp_limb_t) (value >> (32 - big_normalization_steps));
|
||||||
|
udiv_qrnnd_preinv (x1hi, r, xh, xl, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
|
||||||
|
xl = ((mp_limb_t) value) << big_normalization_steps;
|
||||||
|
udiv_qrnnd_preinv (x1lo, x, r, xl, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
t[2] = x >> big_normalization_steps;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = x1hi;
|
||||||
|
else
|
||||||
|
xh = ((x1hi << big_normalization_steps)
|
||||||
|
| (x1lo >> (32 - big_normalization_steps)));
|
||||||
|
xl = x1lo << big_normalization_steps;
|
||||||
|
udiv_qrnnd_preinv (t[0], x, xh, xl, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
t[1] = x >> big_normalization_steps;
|
||||||
|
#elif UDIV_NEEDS_NORMALIZATION
|
||||||
|
mp_limb_t x, xh, xl;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = 0;
|
||||||
|
else
|
||||||
|
xh = (mp_limb_t) (value >> 64 - big_normalization_steps);
|
||||||
|
xl = (mp_limb_t) (value >> 32 - big_normalization_steps);
|
||||||
|
udiv_qrnnd (x1hi, r, xh, xl, big_base_norm);
|
||||||
|
|
||||||
|
xl = ((mp_limb_t) value) << big_normalization_steps;
|
||||||
|
udiv_qrnnd (x1lo, x, r, xl, big_base_norm);
|
||||||
|
t[2] = x >> big_normalization_steps;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = x1hi;
|
||||||
|
else
|
||||||
|
xh = ((x1hi << big_normalization_steps)
|
||||||
|
| (x1lo >> 32 - big_normalization_steps));
|
||||||
|
xl = x1lo << big_normalization_steps;
|
||||||
|
udiv_qrnnd (t[0], x, xh, xl, big_base_norm);
|
||||||
|
t[1] = x >> big_normalization_steps;
|
||||||
|
#else
|
||||||
|
udiv_qrnnd (x1hi, r, 0, (mp_limb_t) (value >> 32),
|
||||||
|
brec->big.base);
|
||||||
|
udiv_qrnnd (x1lo, t[2], r, (mp_limb_t) value, brec->big.base);
|
||||||
|
udiv_qrnnd (t[0], t[1], x1hi, x1lo, brec->big.base);
|
||||||
|
#endif
|
||||||
|
n = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if (UDIV_TIME > 2 * UMUL_TIME)
|
||||||
|
mp_limb_t x;
|
||||||
|
|
||||||
|
value <<= brec->big.normalization_steps;
|
||||||
|
udiv_qrnnd_preinv (t[0], x, (mp_limb_t) (value >> 32),
|
||||||
|
(mp_limb_t) value, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
t[1] = x >> brec->big.normalization_steps;
|
||||||
|
#elif UDIV_NEEDS_NORMALIZATION
|
||||||
|
mp_limb_t x;
|
||||||
|
|
||||||
|
value <<= big_normalization_steps;
|
||||||
|
udiv_qrnnd (t[0], x, (mp_limb_t) (value >> 32),
|
||||||
|
(mp_limb_t) value, big_base_norm);
|
||||||
|
t[1] = x >> big_normalization_steps;
|
||||||
|
#else
|
||||||
|
udiv_qrnnd (t[0], t[1], (mp_limb_t) (value >> 32),
|
||||||
|
(mp_limb_t) value, brec->big.base);
|
||||||
|
#endif
|
||||||
|
n = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t[0] = value;
|
||||||
|
n = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the 1-3 words in t[], word by word, to ASCII. */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
mp_limb_t ti = t[--n];
|
||||||
|
int ndig_for_this_limb = 0;
|
||||||
|
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
mp_limb_t base_multiplier = brec->base_multiplier;
|
||||||
|
if (brec->flag)
|
||||||
|
while (ti != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, ti, base_multiplier);
|
||||||
|
quo = (x + ((ti - x) >> 1)) >> (brec->post_shift - 1);
|
||||||
|
rem = ti - quo * base;
|
||||||
|
*--buflim = digits[rem];
|
||||||
|
ti = quo;
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (ti != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, ti, base_multiplier);
|
||||||
|
quo = x >> brec->post_shift;
|
||||||
|
rem = ti - quo * base;
|
||||||
|
*--buflim = digits[rem];
|
||||||
|
ti = quo;
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
while (ti != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem;
|
||||||
|
|
||||||
|
quo = ti / base;
|
||||||
|
rem = ti % base;
|
||||||
|
*--buflim = digits[rem];
|
||||||
|
ti = quo;
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* If this wasn't the most significant word, pad with zeros. */
|
||||||
|
if (n != 0)
|
||||||
|
while (ndig_for_this_limb < brec->big.ndigits)
|
||||||
|
{
|
||||||
|
*--buflim = '0';
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (n != 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return buflim;
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/* Internal function for converting integers to ASCII.
|
||||||
|
Copyright (C) 1994, 95, 96, 97, 98, 99, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef _ITOA_H
|
||||||
|
#define _ITOA_H
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
/* Convert VALUE into ASCII in base BASE (2..36).
|
||||||
|
Write backwards starting the character just before BUFLIM.
|
||||||
|
Return the address of the first (left-to-right) character in the number.
|
||||||
|
Use upper case letters iff UPPER_CASE is nonzero. */
|
||||||
|
|
||||||
|
extern char *_itoa (unsigned long long int value, char *buflim,
|
||||||
|
unsigned int base, int upper_case);
|
||||||
|
|
||||||
|
extern const char _itoa_upper_digits[];
|
||||||
|
extern const char _itoa_upper_digits_internal[] attribute_hidden;
|
||||||
|
extern const char _itoa_lower_digits[];
|
||||||
|
extern const char _itoa_lower_digits_internal[] attribute_hidden;
|
||||||
|
|
||||||
|
static inline char * __attribute__ ((unused))
|
||||||
|
_itoa_word (unsigned long value, char *buflim,
|
||||||
|
unsigned int base, int upper_case)
|
||||||
|
{
|
||||||
|
const char *digits = (upper_case
|
||||||
|
#if !defined NOT_IN_libc || defined IS_IN_rtld
|
||||||
|
? INTUSE(_itoa_upper_digits)
|
||||||
|
: INTUSE(_itoa_lower_digits)
|
||||||
|
#else
|
||||||
|
? _itoa_upper_digits
|
||||||
|
: _itoa_lower_digits
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
|
switch (base)
|
||||||
|
{
|
||||||
|
#define SPECIAL(Base) \
|
||||||
|
case Base: \
|
||||||
|
do \
|
||||||
|
*--buflim = digits[value % Base]; \
|
||||||
|
while ((value /= Base) != 0); \
|
||||||
|
break
|
||||||
|
|
||||||
|
SPECIAL (10);
|
||||||
|
SPECIAL (16);
|
||||||
|
SPECIAL (8);
|
||||||
|
default:
|
||||||
|
do
|
||||||
|
*--buflim = digits[value % base];
|
||||||
|
while ((value /= base) != 0);
|
||||||
|
}
|
||||||
|
return buflim;
|
||||||
|
}
|
||||||
|
#undef SPECIAL
|
||||||
|
|
||||||
|
static inline char * __attribute__ ((unused))
|
||||||
|
_fitoa_word (unsigned long value, char *buf, unsigned int base, int upper_case)
|
||||||
|
{
|
||||||
|
char tmpbuf[sizeof (value) * 4]; /* Worst case length: base 2. */
|
||||||
|
char *cp = _itoa_word (value, tmpbuf + sizeof (value) * 4, base, upper_case);
|
||||||
|
while (cp < tmpbuf + sizeof (value) * 4)
|
||||||
|
*buf++ = *cp++;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline char * __attribute__ ((unused))
|
||||||
|
_fitoa (unsigned long long value, char *buf, unsigned int base, int upper_case)
|
||||||
|
{
|
||||||
|
char tmpbuf[sizeof (value) * 4]; /* Worst case length: base 2. */
|
||||||
|
char *cp = _itoa (value, tmpbuf + sizeof (value) * 4, base, upper_case);
|
||||||
|
while (cp < tmpbuf + sizeof (value) * 4)
|
||||||
|
*buf++ = *cp++;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* itoa.h */
|
||||||
@@ -0,0 +1,346 @@
|
|||||||
|
/* Internal function for converting integers to ASCII.
|
||||||
|
Copyright (C) 1994,1995,1996,1999,2000,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Torbjorn Granlund <[email protected]>
|
||||||
|
and Ulrich Drepper <[email protected]>.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <gmp-mparam.h>
|
||||||
|
#include <gmp.h>
|
||||||
|
#include <stdlib/gmp-impl.h>
|
||||||
|
#include <stdlib/longlong.h>
|
||||||
|
|
||||||
|
#include "_itowa.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* Canonize environment. For some architectures not all values might
|
||||||
|
be defined in the GMP header files. */
|
||||||
|
#ifndef UMUL_TIME
|
||||||
|
# define UMUL_TIME 1
|
||||||
|
#endif
|
||||||
|
#ifndef UDIV_TIME
|
||||||
|
# define UDIV_TIME 3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Control memory layout. */
|
||||||
|
#ifdef PACK
|
||||||
|
# undef PACK
|
||||||
|
# define PACK __attribute__ ((packed))
|
||||||
|
#else
|
||||||
|
# define PACK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Declare local types. */
|
||||||
|
struct base_table_t
|
||||||
|
{
|
||||||
|
#if (UDIV_TIME > 2 * UMUL_TIME)
|
||||||
|
mp_limb_t base_multiplier;
|
||||||
|
#endif
|
||||||
|
char flag;
|
||||||
|
char post_shift;
|
||||||
|
#if BITS_PER_MP_LIMB == 32
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
char normalization_steps;
|
||||||
|
char ndigits;
|
||||||
|
mp_limb_t base PACK;
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
mp_limb_t base_ninv PACK;
|
||||||
|
#endif
|
||||||
|
} big;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/* To reduce the memory needed we include some fields of the tables
|
||||||
|
only conditionally. */
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
# define SEL1(X) X,
|
||||||
|
# define SEL2(X) ,X
|
||||||
|
#else
|
||||||
|
# define SEL1(X)
|
||||||
|
# define SEL2(X)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Factor table for the different bases. */
|
||||||
|
extern const struct base_table_t _itoa_base_table[] attribute_hidden;
|
||||||
|
|
||||||
|
/* Lower-case digits. */
|
||||||
|
extern const wchar_t _itowa_lower_digits[] attribute_hidden;
|
||||||
|
/* Upper-case digits. */
|
||||||
|
extern const wchar_t _itowa_upper_digits[] attribute_hidden;
|
||||||
|
|
||||||
|
|
||||||
|
wchar_t *
|
||||||
|
_itowa (value, buflim, base, upper_case)
|
||||||
|
unsigned long long int value;
|
||||||
|
wchar_t *buflim;
|
||||||
|
unsigned int base;
|
||||||
|
int upper_case;
|
||||||
|
{
|
||||||
|
const wchar_t *digits = (upper_case
|
||||||
|
? _itowa_upper_digits : _itowa_lower_digits);
|
||||||
|
wchar_t *bp = buflim;
|
||||||
|
const struct base_table_t *brec = &_itoa_base_table[base - 2];
|
||||||
|
|
||||||
|
switch (base)
|
||||||
|
{
|
||||||
|
#define RUN_2N(BITS) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
/* `unsigned long long int' always has 64 bits. */ \
|
||||||
|
mp_limb_t work_hi = value >> (64 - BITS_PER_MP_LIMB); \
|
||||||
|
\
|
||||||
|
if (BITS_PER_MP_LIMB == 32) \
|
||||||
|
{ \
|
||||||
|
if (work_hi != 0) \
|
||||||
|
{ \
|
||||||
|
mp_limb_t work_lo; \
|
||||||
|
int cnt; \
|
||||||
|
\
|
||||||
|
work_lo = value & 0xfffffffful; \
|
||||||
|
for (cnt = BITS_PER_MP_LIMB / BITS; cnt > 0; --cnt) \
|
||||||
|
{ \
|
||||||
|
*--bp = digits[work_lo & ((1ul << BITS) - 1)]; \
|
||||||
|
work_lo >>= BITS; \
|
||||||
|
} \
|
||||||
|
if (BITS_PER_MP_LIMB % BITS != 0) \
|
||||||
|
{ \
|
||||||
|
work_lo \
|
||||||
|
|= ((work_hi \
|
||||||
|
& ((1 << (BITS - BITS_PER_MP_LIMB%BITS)) \
|
||||||
|
- 1)) \
|
||||||
|
<< BITS_PER_MP_LIMB % BITS); \
|
||||||
|
work_hi >>= BITS - BITS_PER_MP_LIMB % BITS; \
|
||||||
|
if (work_hi == 0) \
|
||||||
|
work_hi = work_lo; \
|
||||||
|
else \
|
||||||
|
*--bp = digits[work_lo]; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
work_hi = value & 0xfffffffful; \
|
||||||
|
} \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
*--bp = digits[work_hi & ((1 << BITS) - 1)]; \
|
||||||
|
work_hi >>= BITS; \
|
||||||
|
} \
|
||||||
|
while (work_hi != 0); \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
case 8:
|
||||||
|
RUN_2N (3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 16:
|
||||||
|
RUN_2N (4);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
#if BITS_PER_MP_LIMB == 64
|
||||||
|
mp_limb_t base_multiplier = brec->base_multiplier;
|
||||||
|
if (brec->flag)
|
||||||
|
while (value != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, value, base_multiplier);
|
||||||
|
quo = (x + ((value - x) >> 1)) >> (brec->post_shift - 1);
|
||||||
|
rem = value - quo * base;
|
||||||
|
*--bp = digits[rem];
|
||||||
|
value = quo;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (value != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, value, base_multiplier);
|
||||||
|
quo = x >> brec->post_shift;
|
||||||
|
rem = value - quo * base;
|
||||||
|
*--bp = digits[rem];
|
||||||
|
value = quo;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#if BITS_PER_MP_LIMB == 32
|
||||||
|
mp_limb_t t[3];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
/* First convert x0 to 1-3 words in base s->big.base.
|
||||||
|
Optimize for frequent cases of 32 bit numbers. */
|
||||||
|
if ((mp_limb_t) (value >> 32) >= 1)
|
||||||
|
{
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME || UDIV_NEEDS_NORMALIZATION
|
||||||
|
int big_normalization_steps = brec->big.normalization_steps;
|
||||||
|
mp_limb_t big_base_norm
|
||||||
|
= brec->big.base << big_normalization_steps;
|
||||||
|
#endif
|
||||||
|
if ((mp_limb_t) (value >> 32) >= brec->big.base)
|
||||||
|
{
|
||||||
|
mp_limb_t x1hi, x1lo, r;
|
||||||
|
/* If you want to optimize this, take advantage of
|
||||||
|
that the quotient in the first udiv_qrnnd will
|
||||||
|
always be very small. It might be faster just to
|
||||||
|
subtract in a tight loop. */
|
||||||
|
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
mp_limb_t x, xh, xl;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = 0;
|
||||||
|
else
|
||||||
|
xh = (mp_limb_t) (value >> (64 - big_normalization_steps));
|
||||||
|
xl = (mp_limb_t) (value >> (32 - big_normalization_steps));
|
||||||
|
udiv_qrnnd_preinv (x1hi, r, xh, xl, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
|
||||||
|
xl = ((mp_limb_t) value) << big_normalization_steps;
|
||||||
|
udiv_qrnnd_preinv (x1lo, x, r, xl, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
t[2] = x >> big_normalization_steps;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = x1hi;
|
||||||
|
else
|
||||||
|
xh = ((x1hi << big_normalization_steps)
|
||||||
|
| (x1lo >> (32 - big_normalization_steps)));
|
||||||
|
xl = x1lo << big_normalization_steps;
|
||||||
|
udiv_qrnnd_preinv (t[0], x, xh, xl, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
t[1] = x >> big_normalization_steps;
|
||||||
|
#elif UDIV_NEEDS_NORMALIZATION
|
||||||
|
mp_limb_t x, xh, xl;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = 0;
|
||||||
|
else
|
||||||
|
xh = (mp_limb_t) (value >> 64 - big_normalization_steps);
|
||||||
|
xl = (mp_limb_t) (value >> 32 - big_normalization_steps);
|
||||||
|
udiv_qrnnd (x1hi, r, xh, xl, big_base_norm);
|
||||||
|
|
||||||
|
xl = ((mp_limb_t) value) << big_normalization_steps;
|
||||||
|
udiv_qrnnd (x1lo, x, r, xl, big_base_norm);
|
||||||
|
t[2] = x >> big_normalization_steps;
|
||||||
|
|
||||||
|
if (big_normalization_steps == 0)
|
||||||
|
xh = x1hi;
|
||||||
|
else
|
||||||
|
xh = ((x1hi << big_normalization_steps)
|
||||||
|
| (x1lo >> 32 - big_normalization_steps));
|
||||||
|
xl = x1lo << big_normalization_steps;
|
||||||
|
udiv_qrnnd (t[0], x, xh, xl, big_base_norm);
|
||||||
|
t[1] = x >> big_normalization_steps;
|
||||||
|
#else
|
||||||
|
udiv_qrnnd (x1hi, r, 0, (mp_limb_t) (value >> 32),
|
||||||
|
brec->big.base);
|
||||||
|
udiv_qrnnd (x1lo, t[2], r, (mp_limb_t) value, brec->big.base);
|
||||||
|
udiv_qrnnd (t[0], t[1], x1hi, x1lo, brec->big.base);
|
||||||
|
#endif
|
||||||
|
n = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
#if (UDIV_TIME > 2 * UMUL_TIME)
|
||||||
|
mp_limb_t x;
|
||||||
|
|
||||||
|
value <<= brec->big.normalization_steps;
|
||||||
|
udiv_qrnnd_preinv (t[0], x, (mp_limb_t) (value >> 32),
|
||||||
|
(mp_limb_t) value, big_base_norm,
|
||||||
|
brec->big.base_ninv);
|
||||||
|
t[1] = x >> brec->big.normalization_steps;
|
||||||
|
#elif UDIV_NEEDS_NORMALIZATION
|
||||||
|
mp_limb_t x;
|
||||||
|
|
||||||
|
value <<= big_normalization_steps;
|
||||||
|
udiv_qrnnd (t[0], x, (mp_limb_t) (value >> 32),
|
||||||
|
(mp_limb_t) value, big_base_norm);
|
||||||
|
t[1] = x >> big_normalization_steps;
|
||||||
|
#else
|
||||||
|
udiv_qrnnd (t[0], t[1], (mp_limb_t) (value >> 32),
|
||||||
|
(mp_limb_t) value, brec->big.base);
|
||||||
|
#endif
|
||||||
|
n = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
t[0] = value;
|
||||||
|
n = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Convert the 1-3 words in t[], word by word, to ASCII. */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
mp_limb_t ti = t[--n];
|
||||||
|
int ndig_for_this_limb = 0;
|
||||||
|
|
||||||
|
#if UDIV_TIME > 2 * UMUL_TIME
|
||||||
|
mp_limb_t base_multiplier = brec->base_multiplier;
|
||||||
|
if (brec->flag)
|
||||||
|
while (ti != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, ti, base_multiplier);
|
||||||
|
quo = (x + ((ti - x) >> 1)) >> (brec->post_shift - 1);
|
||||||
|
rem = ti - quo * base;
|
||||||
|
*--bp = digits[rem];
|
||||||
|
ti = quo;
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (ti != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem, x, dummy;
|
||||||
|
|
||||||
|
umul_ppmm (x, dummy, ti, base_multiplier);
|
||||||
|
quo = x >> brec->post_shift;
|
||||||
|
rem = ti - quo * base;
|
||||||
|
*--bp = digits[rem];
|
||||||
|
ti = quo;
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
while (ti != 0)
|
||||||
|
{
|
||||||
|
mp_limb_t quo, rem;
|
||||||
|
|
||||||
|
quo = ti / base;
|
||||||
|
rem = ti % base;
|
||||||
|
*--bp = digits[rem];
|
||||||
|
ti = quo;
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/* If this wasn't the most significant word, pad with zeros. */
|
||||||
|
if (n != 0)
|
||||||
|
while (ndig_for_this_limb < brec->big.ndigits)
|
||||||
|
{
|
||||||
|
*--bp = '0';
|
||||||
|
++ndig_for_this_limb;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (n != 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bp;
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/* Internal function for converting integers to ASCII.
|
||||||
|
Copyright (C) 1994, 95, 96, 97, 98, 99, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef _ITOWA_H
|
||||||
|
#define _ITOWA_H 1
|
||||||
|
#include <features.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
/* Convert VALUE into ASCII in base BASE (2..36).
|
||||||
|
Write backwards starting the character just before BUFLIM.
|
||||||
|
Return the address of the first (left-to-right) character in the number.
|
||||||
|
Use upper case letters iff UPPER_CASE is nonzero. */
|
||||||
|
|
||||||
|
extern wchar_t *_itowa (unsigned long long int value, wchar_t *buflim,
|
||||||
|
unsigned int base, int upper_case);
|
||||||
|
|
||||||
|
static inline wchar_t *
|
||||||
|
__attribute__ ((unused))
|
||||||
|
_itowa_word (unsigned long value, wchar_t *buflim,
|
||||||
|
unsigned int base, int upper_case)
|
||||||
|
{
|
||||||
|
extern const wchar_t _itowa_upper_digits[] attribute_hidden;
|
||||||
|
extern const wchar_t _itowa_lower_digits[] attribute_hidden;
|
||||||
|
const wchar_t *digits = (upper_case
|
||||||
|
? _itowa_upper_digits : _itowa_lower_digits);
|
||||||
|
wchar_t *bp = buflim;
|
||||||
|
|
||||||
|
switch (base)
|
||||||
|
{
|
||||||
|
#define SPECIAL(Base) \
|
||||||
|
case Base: \
|
||||||
|
do \
|
||||||
|
*--bp = digits[value % Base]; \
|
||||||
|
while ((value /= Base) != 0); \
|
||||||
|
break
|
||||||
|
|
||||||
|
SPECIAL (10);
|
||||||
|
SPECIAL (16);
|
||||||
|
SPECIAL (8);
|
||||||
|
default:
|
||||||
|
do
|
||||||
|
*--bp = digits[value % base];
|
||||||
|
while ((value /= base) != 0);
|
||||||
|
}
|
||||||
|
return bp;
|
||||||
|
}
|
||||||
|
#undef SPECIAL
|
||||||
|
|
||||||
|
#endif /* itowa.h */
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright (C) 1991, 1995, 1997, 1998, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libio/libioP.h>
|
||||||
|
# define vasprintf(s, f, a) _IO_vasprintf (s, f, a)
|
||||||
|
#endif
|
||||||
|
#undef __asprintf
|
||||||
|
|
||||||
|
/* Write formatted output from FORMAT to a string which is
|
||||||
|
allocated with malloc and stored in *STRING_PTR. */
|
||||||
|
/* VARARGS2 */
|
||||||
|
int
|
||||||
|
__asprintf (char **string_ptr, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = vasprintf (string_ptr, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
INTDEF(__asprintf)
|
||||||
|
weak_alias (__asprintf, asprintf)
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* Copyright (C) 1991,95,97,98,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libio/libioP.h>
|
||||||
|
# define vdprintf(d, f, a) _IO_vdprintf (d, f, a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Write formatted output to D, according to the format string FORMAT. */
|
||||||
|
/* VARARGS2 */
|
||||||
|
int
|
||||||
|
dprintf (int d, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = vdprintf (d, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
libc_hidden_def (dprintf)
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright (C) 1991,97,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Write formatted output to STREAM from the format string FORMAT. */
|
||||||
|
/* VARARGS2 */
|
||||||
|
int
|
||||||
|
fprintf (FILE *stream, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = vfprintf (stream, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
libc_hidden_def (fprintf)
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
/* We define the function with the real name here. But deep down in
|
||||||
|
libio the original function _IO_fprintf is also needed. So make
|
||||||
|
an alias. */
|
||||||
|
weak_alias (fprintf, _IO_fprintf)
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Read formatted input from STREAM according to the format string FORMAT. */
|
||||||
|
/* VARARGS2 */
|
||||||
|
int
|
||||||
|
fscanf (FILE *stream, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = __vfscanf (stream, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/* Copyright (C) 1991, 1992, 1995, 1996, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#undef __getline
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include "../libio/libioP.h"
|
||||||
|
# undef ssize_t
|
||||||
|
# define ssize_t _IO_ssize_t
|
||||||
|
# define __getdelim _IO_getdelim
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Like getdelim, but always looks for a newline. */
|
||||||
|
ssize_t
|
||||||
|
__getline (char **lineptr, size_t *n, FILE *stream)
|
||||||
|
{
|
||||||
|
return __getdelim (lineptr, n, '\n', stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__getline, getline)
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* Copyright (C) 1991, 1997, 1998, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libio/iolibio.h>
|
||||||
|
# define fread(p, m, n, s) INTUSE(_IO_fread) (p, m, n, s)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Read a word (int) from STREAM. */
|
||||||
|
int
|
||||||
|
getw (FILE *stream)
|
||||||
|
{
|
||||||
|
int w;
|
||||||
|
|
||||||
|
/* Is there a better way? */
|
||||||
|
if (fread ((void *) &w, sizeof (w), 1, stream) != 1)
|
||||||
|
return EOF;
|
||||||
|
return w;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/* Digits.
|
||||||
|
Copyright (C) 1994,1995,1996,1999,2000,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/* Lower-case digits. */
|
||||||
|
const char _itoa_lower_digits[36]
|
||||||
|
= "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
|
INTVARDEF(_itoa_lower_digits)
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/* Digits.
|
||||||
|
Copyright (C) 1994,1995,1996,1999,2000,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/* Upper-case digits. */
|
||||||
|
const char _itoa_upper_digits[36]
|
||||||
|
= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
INTVARDEF(_itoa_upper_digits)
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/* Digits.
|
||||||
|
Copyright (C) 1994, 1995, 1996, 1999, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
/* Lower-case digits. */
|
||||||
|
const wchar_t _itowa_lower_digits[36] attribute_hidden
|
||||||
|
= L"0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
|
/* Upper-case digits. */
|
||||||
|
const wchar_t _itowa_upper_digits[36] attribute_hidden
|
||||||
|
= L"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/* Copyright (C) 1991-1993,1997,1998,2000-2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include "libioP.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
perror_internal (FILE *fp, const char *s, int errnum)
|
||||||
|
{
|
||||||
|
char buf[1024];
|
||||||
|
const char *colon;
|
||||||
|
const char *errstring;
|
||||||
|
|
||||||
|
if (s == NULL || *s == '\0')
|
||||||
|
s = colon = "";
|
||||||
|
else
|
||||||
|
colon = ": ";
|
||||||
|
|
||||||
|
errstring = __strerror_r (errnum, buf, sizeof buf);
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
if (_IO_fwide (fp, 0) > 0)
|
||||||
|
(void) __fwprintf (fp, L"%s%s%s\n", s, colon, errstring);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
(void) fprintf (fp, "%s%s%s\n", s, colon, errstring);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Print a line on stderr consisting of the text in S, a colon, a space,
|
||||||
|
a message describing the meaning of the contents of `errno' and a newline.
|
||||||
|
If S is NULL or "", the colon and space are omitted. */
|
||||||
|
void
|
||||||
|
perror (const char *s)
|
||||||
|
{
|
||||||
|
int errnum = errno;
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
FILE *fp;
|
||||||
|
int fd = -1;
|
||||||
|
|
||||||
|
|
||||||
|
/* The standard says that 'perror' must not change the orientation
|
||||||
|
of the stream. What is supposed to happen when the stream isn't
|
||||||
|
oriented yet? In this case we'll create a new stream which is
|
||||||
|
using the same underlying file descriptor. */
|
||||||
|
if (__builtin_expect (_IO_fwide (stderr, 0) != 0, 1)
|
||||||
|
|| (fd = fileno (stderr)) == -1
|
||||||
|
|| (fd = __dup (fd)) == -1
|
||||||
|
|| (fp = fdopen (fd, "w+")) == NULL)
|
||||||
|
{
|
||||||
|
if (__builtin_expect (fd != -1, 0))
|
||||||
|
__close (fd);
|
||||||
|
|
||||||
|
/* Use standard error as is. */
|
||||||
|
perror_internal (stderr, s, errnum);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* We don't have to do any special hacks regarding the file
|
||||||
|
position. Since the stderr stream wasn't used so far we just
|
||||||
|
write to the descriptor. */
|
||||||
|
perror_internal (fp, s, errnum);
|
||||||
|
/* Close the stream. */
|
||||||
|
fclose (fp);
|
||||||
|
|
||||||
|
((_IO_FILE *) stderr)->_offset = _IO_pos_BAD;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
perror_internal (stderr, s, errnum);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
libc_hidden_def (perror)
|
||||||
@@ -0,0 +1,454 @@
|
|||||||
|
/* Internal header for parsing printf format strings.
|
||||||
|
Copyright (C) 1995-1999, 2000, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of th GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define NDEBUG 1
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct printf_spec
|
||||||
|
{
|
||||||
|
/* Information parsed from the format spec. */
|
||||||
|
struct printf_info info;
|
||||||
|
|
||||||
|
/* Pointers into the format string for the end of this format
|
||||||
|
spec and the next (or to the end of the string if no more). */
|
||||||
|
const UCHAR_T *end_of_fmt, *next_fmt;
|
||||||
|
|
||||||
|
/* Position of arguments for precision and width, or -1 if `info' has
|
||||||
|
the constant value. */
|
||||||
|
int prec_arg, width_arg;
|
||||||
|
|
||||||
|
int data_arg; /* Position of data argument. */
|
||||||
|
int data_arg_type; /* Type of first argument. */
|
||||||
|
/* Number of arguments consumed by this format specifier. */
|
||||||
|
size_t ndata_args;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* The various kinds off arguments that can be passed to printf. */
|
||||||
|
union printf_arg
|
||||||
|
{
|
||||||
|
unsigned char pa_char;
|
||||||
|
wchar_t pa_wchar;
|
||||||
|
short int pa_short_int;
|
||||||
|
int pa_int;
|
||||||
|
long int pa_long_int;
|
||||||
|
long long int pa_long_long_int;
|
||||||
|
unsigned short int pa_u_short_int;
|
||||||
|
unsigned int pa_u_int;
|
||||||
|
unsigned long int pa_u_long_int;
|
||||||
|
unsigned long long int pa_u_long_long_int;
|
||||||
|
float pa_float;
|
||||||
|
double pa_double;
|
||||||
|
long double pa_long_double;
|
||||||
|
const char *pa_string;
|
||||||
|
const wchar_t *pa_wstring;
|
||||||
|
void *pa_pointer;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Read a simple integer from a string and update the string pointer.
|
||||||
|
It is assumed that the first character is a digit. */
|
||||||
|
static inline unsigned int
|
||||||
|
read_int (const UCHAR_T * *pstr)
|
||||||
|
{
|
||||||
|
unsigned int retval = **pstr - L_('0');
|
||||||
|
|
||||||
|
while (ISDIGIT (*++(*pstr)))
|
||||||
|
{
|
||||||
|
retval *= 10;
|
||||||
|
retval += **pstr - L_('0');
|
||||||
|
}
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Find the next spec in FORMAT, or the end of the string. Returns
|
||||||
|
a pointer into FORMAT, to a '%' or a '\0'. */
|
||||||
|
static inline const UCHAR_T *
|
||||||
|
#ifdef COMPILE_WPRINTF
|
||||||
|
find_spec (const UCHAR_T *format)
|
||||||
|
#else
|
||||||
|
find_spec (const UCHAR_T *format, mbstate_t *ps)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef COMPILE_WPRINTF
|
||||||
|
return (const UCHAR_T *) __wcschrnul ((const CHAR_T *) format, L'%');
|
||||||
|
#else
|
||||||
|
while (*format != L_('\0') && *format != L_('%'))
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
/* Remove any hints of a wrong encoding. */
|
||||||
|
ps->__count = 0;
|
||||||
|
if (! isascii (*format) && (len = __mbrlen (format, MB_CUR_MAX, ps)) > 0)
|
||||||
|
format += len;
|
||||||
|
else
|
||||||
|
++format;
|
||||||
|
}
|
||||||
|
return format;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* These are defined in reg-printf.c. */
|
||||||
|
extern printf_arginfo_function **__printf_arginfo_table attribute_hidden;
|
||||||
|
extern printf_function **__printf_function_table attribute_hidden;
|
||||||
|
|
||||||
|
|
||||||
|
/* FORMAT must point to a '%' at the beginning of a spec. Fills in *SPEC
|
||||||
|
with the parsed details. POSN is the number of arguments already
|
||||||
|
consumed. At most MAXTYPES - POSN types are filled in TYPES. Return
|
||||||
|
the number of args consumed by this spec; *MAX_REF_ARG is updated so it
|
||||||
|
remains the highest argument index used. */
|
||||||
|
static inline size_t
|
||||||
|
#ifdef COMPILE_WPRINTF
|
||||||
|
parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
|
||||||
|
size_t *max_ref_arg)
|
||||||
|
#else
|
||||||
|
parse_one_spec (const UCHAR_T *format, size_t posn, struct printf_spec *spec,
|
||||||
|
size_t *max_ref_arg, mbstate_t *ps)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
unsigned int n;
|
||||||
|
size_t nargs = 0;
|
||||||
|
|
||||||
|
/* Skip the '%'. */
|
||||||
|
++format;
|
||||||
|
|
||||||
|
/* Clear information structure. */
|
||||||
|
spec->data_arg = -1;
|
||||||
|
spec->info.alt = 0;
|
||||||
|
spec->info.space = 0;
|
||||||
|
spec->info.left = 0;
|
||||||
|
spec->info.showsign = 0;
|
||||||
|
spec->info.group = 0;
|
||||||
|
spec->info.i18n = 0;
|
||||||
|
spec->info.pad = ' ';
|
||||||
|
spec->info.wide = sizeof (UCHAR_T) > 1;
|
||||||
|
|
||||||
|
/* Test for positional argument. */
|
||||||
|
if (ISDIGIT (*format))
|
||||||
|
{
|
||||||
|
const UCHAR_T *begin = format;
|
||||||
|
|
||||||
|
n = read_int (&format);
|
||||||
|
|
||||||
|
if (n > 0 && *format == L_('$'))
|
||||||
|
/* Is positional parameter. */
|
||||||
|
{
|
||||||
|
++format; /* Skip the '$'. */
|
||||||
|
spec->data_arg = n - 1;
|
||||||
|
*max_ref_arg = MAX (*max_ref_arg, n);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* Oops; that was actually the width and/or 0 padding flag.
|
||||||
|
Step back and read it again. */
|
||||||
|
format = begin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for spec modifiers. */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
switch (*format)
|
||||||
|
{
|
||||||
|
case L_(' '):
|
||||||
|
/* Output a space in place of a sign, when there is no sign. */
|
||||||
|
spec->info.space = 1;
|
||||||
|
continue;
|
||||||
|
case L_('+'):
|
||||||
|
/* Always output + or - for numbers. */
|
||||||
|
spec->info.showsign = 1;
|
||||||
|
continue;
|
||||||
|
case L_('-'):
|
||||||
|
/* Left-justify things. */
|
||||||
|
spec->info.left = 1;
|
||||||
|
continue;
|
||||||
|
case L_('#'):
|
||||||
|
/* Use the "alternate form":
|
||||||
|
Hex has 0x or 0X, FP always has a decimal point. */
|
||||||
|
spec->info.alt = 1;
|
||||||
|
continue;
|
||||||
|
case L_('0'):
|
||||||
|
/* Pad with 0s. */
|
||||||
|
spec->info.pad = '0';
|
||||||
|
continue;
|
||||||
|
case L_('\''):
|
||||||
|
/* Show grouping in numbers if the locale information
|
||||||
|
indicates any. */
|
||||||
|
spec->info.group = 1;
|
||||||
|
continue;
|
||||||
|
case L_('I'):
|
||||||
|
/* Use the internationalized form of the output. Currently
|
||||||
|
means to use the `outdigits' of the current locale. */
|
||||||
|
spec->info.i18n = 1;
|
||||||
|
continue;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
while (*++format);
|
||||||
|
|
||||||
|
if (spec->info.left)
|
||||||
|
spec->info.pad = ' ';
|
||||||
|
|
||||||
|
/* Get the field width. */
|
||||||
|
spec->width_arg = -1;
|
||||||
|
spec->info.width = 0;
|
||||||
|
if (*format == L_('*'))
|
||||||
|
{
|
||||||
|
/* The field width is given in an argument.
|
||||||
|
A negative field width indicates left justification. */
|
||||||
|
const UCHAR_T *begin = ++format;
|
||||||
|
|
||||||
|
if (ISDIGIT (*format))
|
||||||
|
{
|
||||||
|
/* The width argument might be found in a positional parameter. */
|
||||||
|
n = read_int (&format);
|
||||||
|
|
||||||
|
if (n > 0 && *format == L_('$'))
|
||||||
|
{
|
||||||
|
spec->width_arg = n - 1;
|
||||||
|
*max_ref_arg = MAX (*max_ref_arg, n);
|
||||||
|
++format; /* Skip '$'. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spec->width_arg < 0)
|
||||||
|
{
|
||||||
|
/* Not in a positional parameter. Consume one argument. */
|
||||||
|
spec->width_arg = posn++;
|
||||||
|
++nargs;
|
||||||
|
format = begin; /* Step back and reread. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ISDIGIT (*format))
|
||||||
|
/* Constant width specification. */
|
||||||
|
spec->info.width = read_int (&format);
|
||||||
|
|
||||||
|
/* Get the precision. */
|
||||||
|
spec->prec_arg = -1;
|
||||||
|
/* -1 means none given; 0 means explicit 0. */
|
||||||
|
spec->info.prec = -1;
|
||||||
|
if (*format == L_('.'))
|
||||||
|
{
|
||||||
|
++format;
|
||||||
|
if (*format == L_('*'))
|
||||||
|
{
|
||||||
|
/* The precision is given in an argument. */
|
||||||
|
const UCHAR_T *begin = ++format;
|
||||||
|
|
||||||
|
if (ISDIGIT (*format))
|
||||||
|
{
|
||||||
|
n = read_int (&format);
|
||||||
|
|
||||||
|
if (n > 0 && *format == L_('$'))
|
||||||
|
{
|
||||||
|
spec->prec_arg = n - 1;
|
||||||
|
*max_ref_arg = MAX (*max_ref_arg, n);
|
||||||
|
++format;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spec->prec_arg < 0)
|
||||||
|
{
|
||||||
|
/* Not in a positional parameter. */
|
||||||
|
spec->prec_arg = posn++;
|
||||||
|
++nargs;
|
||||||
|
format = begin;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ISDIGIT (*format))
|
||||||
|
spec->info.prec = read_int (&format);
|
||||||
|
else
|
||||||
|
/* "%.?" is treated like "%.0?". */
|
||||||
|
spec->info.prec = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for type modifiers. */
|
||||||
|
spec->info.is_long_double = 0;
|
||||||
|
spec->info.is_short = 0;
|
||||||
|
spec->info.is_long = 0;
|
||||||
|
spec->info.is_char = 0;
|
||||||
|
|
||||||
|
switch (*format++)
|
||||||
|
{
|
||||||
|
case L_('h'):
|
||||||
|
/* ints are short ints or chars. */
|
||||||
|
if (*format != L_('h'))
|
||||||
|
spec->info.is_short = 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++format;
|
||||||
|
spec->info.is_char = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case L_('l'):
|
||||||
|
/* ints are long ints. */
|
||||||
|
spec->info.is_long = 1;
|
||||||
|
if (*format != L_('l'))
|
||||||
|
break;
|
||||||
|
++format;
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case L_('L'):
|
||||||
|
/* doubles are long doubles, and ints are long long ints. */
|
||||||
|
case L_('q'):
|
||||||
|
/* 4.4 uses this for long long. */
|
||||||
|
spec->info.is_long_double = 1;
|
||||||
|
break;
|
||||||
|
case L_('z'):
|
||||||
|
case L_('Z'):
|
||||||
|
/* ints are size_ts. */
|
||||||
|
assert (sizeof (size_t) <= sizeof (unsigned long long int));
|
||||||
|
#if LONG_MAX != LONG_LONG_MAX
|
||||||
|
spec->info.is_long_double = sizeof (size_t) > sizeof (unsigned long int);
|
||||||
|
#endif
|
||||||
|
spec->info.is_long = sizeof (size_t) > sizeof (unsigned int);
|
||||||
|
break;
|
||||||
|
case L_('t'):
|
||||||
|
assert (sizeof (ptrdiff_t) <= sizeof (long long int));
|
||||||
|
#if LONG_MAX != LONG_LONG_MAX
|
||||||
|
spec->info.is_long_double = (sizeof (ptrdiff_t) > sizeof (long int));
|
||||||
|
#endif
|
||||||
|
spec->info.is_long = sizeof (ptrdiff_t) > sizeof (int);
|
||||||
|
break;
|
||||||
|
case L_('j'):
|
||||||
|
assert (sizeof (uintmax_t) <= sizeof (unsigned long long int));
|
||||||
|
#if LONG_MAX != LONG_LONG_MAX
|
||||||
|
spec->info.is_long_double = (sizeof (uintmax_t)
|
||||||
|
> sizeof (unsigned long int));
|
||||||
|
#endif
|
||||||
|
spec->info.is_long = sizeof (uintmax_t) > sizeof (unsigned int);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* Not a recognized modifier. Backup. */
|
||||||
|
--format;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get the format specification. */
|
||||||
|
spec->info.spec = (wchar_t) *format++;
|
||||||
|
if (__builtin_expect (__printf_function_table != NULL, 0)
|
||||||
|
&& spec->info.spec <= UCHAR_MAX
|
||||||
|
&& __printf_arginfo_table[spec->info.spec] != NULL)
|
||||||
|
/* We don't try to get the types for all arguments if the format
|
||||||
|
uses more than one. The normal case is covered though. */
|
||||||
|
spec->ndata_args = (*__printf_arginfo_table[spec->info.spec])
|
||||||
|
(&spec->info, 1, &spec->data_arg_type);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Find the data argument types of a built-in spec. */
|
||||||
|
spec->ndata_args = 1;
|
||||||
|
|
||||||
|
switch (spec->info.spec)
|
||||||
|
{
|
||||||
|
case L'i':
|
||||||
|
case L'd':
|
||||||
|
case L'u':
|
||||||
|
case L'o':
|
||||||
|
case L'X':
|
||||||
|
case L'x':
|
||||||
|
#if LONG_MAX != LONG_LONG_MAX
|
||||||
|
if (spec->info.is_long_double)
|
||||||
|
spec->data_arg_type = PA_INT|PA_FLAG_LONG_LONG;
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if (spec->info.is_long)
|
||||||
|
spec->data_arg_type = PA_INT|PA_FLAG_LONG;
|
||||||
|
else if (spec->info.is_short)
|
||||||
|
spec->data_arg_type = PA_INT|PA_FLAG_SHORT;
|
||||||
|
else if (spec->info.is_char)
|
||||||
|
spec->data_arg_type = PA_CHAR;
|
||||||
|
else
|
||||||
|
spec->data_arg_type = PA_INT;
|
||||||
|
break;
|
||||||
|
case L'e':
|
||||||
|
case L'E':
|
||||||
|
case L'f':
|
||||||
|
case L'F':
|
||||||
|
case L'g':
|
||||||
|
case L'G':
|
||||||
|
case L'a':
|
||||||
|
case L'A':
|
||||||
|
if (spec->info.is_long_double)
|
||||||
|
spec->data_arg_type = PA_DOUBLE|PA_FLAG_LONG_DOUBLE;
|
||||||
|
else
|
||||||
|
spec->data_arg_type = PA_DOUBLE;
|
||||||
|
break;
|
||||||
|
case L'c':
|
||||||
|
spec->data_arg_type = PA_CHAR;
|
||||||
|
break;
|
||||||
|
case L'C':
|
||||||
|
spec->data_arg_type = PA_WCHAR;
|
||||||
|
break;
|
||||||
|
case L's':
|
||||||
|
spec->data_arg_type = PA_STRING;
|
||||||
|
break;
|
||||||
|
case L'S':
|
||||||
|
spec->data_arg_type = PA_WSTRING;
|
||||||
|
break;
|
||||||
|
case L'p':
|
||||||
|
spec->data_arg_type = PA_POINTER;
|
||||||
|
break;
|
||||||
|
case L'n':
|
||||||
|
spec->data_arg_type = PA_INT|PA_FLAG_PTR;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case L'm':
|
||||||
|
default:
|
||||||
|
/* An unknown spec will consume no args. */
|
||||||
|
spec->ndata_args = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spec->data_arg == -1 && spec->ndata_args > 0)
|
||||||
|
{
|
||||||
|
/* There are args consumed, but no positional spec. Use the
|
||||||
|
next sequential arg position. */
|
||||||
|
spec->data_arg = posn;
|
||||||
|
nargs += spec->ndata_args;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (spec->info.spec == L'\0')
|
||||||
|
/* Format ended before this spec was complete. */
|
||||||
|
spec->end_of_fmt = spec->next_fmt = format - 1;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Find the next format spec. */
|
||||||
|
spec->end_of_fmt = format;
|
||||||
|
#ifdef COMPILE_WPRINTF
|
||||||
|
spec->next_fmt = find_spec (format);
|
||||||
|
#else
|
||||||
|
spec->next_fmt = find_spec (format, ps);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
return nargs;
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
/* Copyright (C) 1991,92,95,96,99,2000,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
#include "../locale/localeinfo.h"
|
||||||
|
|
||||||
|
#ifndef COMPILE_WPRINTF
|
||||||
|
# define CHAR_T char
|
||||||
|
# define UCHAR_T unsigned char
|
||||||
|
# define INT_T int
|
||||||
|
# define L_(Str) Str
|
||||||
|
# define ISDIGIT(Ch) isdigit (Ch)
|
||||||
|
# define ISASCII(Ch) isascii (Ch)
|
||||||
|
# define MBRLEN(Cp, L, St) __mbrlen (Cp, L, St)
|
||||||
|
|
||||||
|
# ifdef USE_IN_LIBIO
|
||||||
|
# define PUT(F, S, N) _IO_sputn (F, S, N)
|
||||||
|
# define PAD(Padchar) \
|
||||||
|
if (width > 0) \
|
||||||
|
done += INTUSE(_IO_padn) (s, Padchar, width)
|
||||||
|
# else
|
||||||
|
# define PUTC(C, F) putc (C, F)
|
||||||
|
ssize_t __printf_pad __P ((FILE *, char pad, size_t n));
|
||||||
|
# define PAD(Padchar) \
|
||||||
|
if (width > 0) \
|
||||||
|
{ if (__printf_pad (s, Padchar, width) == -1) \
|
||||||
|
return -1; else done += width; }
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
# define vfprintf vfwprintf
|
||||||
|
# define CHAR_T wchar_t
|
||||||
|
# define UCHAR_T uwchar_t
|
||||||
|
# define INT_T wint_t
|
||||||
|
# define L_(Str) L##Str
|
||||||
|
# define ISDIGIT(Ch) iswdigit (Ch)
|
||||||
|
|
||||||
|
# ifdef USE_IN_LIBIO
|
||||||
|
# define PUT(F, S, N) _IO_sputn (F, S, N)
|
||||||
|
# define PAD(Padchar) \
|
||||||
|
if (width > 0) \
|
||||||
|
done += _IO_wpadn (s, Padchar, width)
|
||||||
|
# else
|
||||||
|
# define PUTC(C, F) wputc (C, F)
|
||||||
|
ssize_t __wprintf_pad __P ((FILE *, wchar_t pad, size_t n));
|
||||||
|
# define PAD(Padchar) \
|
||||||
|
if (width > 0) \
|
||||||
|
{ if (__wprintf_pad (s, Padchar, width) == -1) \
|
||||||
|
return -1; else done += width; }
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "printf-parse.h"
|
||||||
|
|
||||||
|
|
||||||
|
size_t
|
||||||
|
parse_printf_format (fmt, n, argtypes)
|
||||||
|
const char *fmt;
|
||||||
|
size_t n;
|
||||||
|
int *argtypes;
|
||||||
|
{
|
||||||
|
size_t nargs; /* Number of arguments. */
|
||||||
|
size_t max_ref_arg; /* Highest index used in a positional arg. */
|
||||||
|
struct printf_spec spec;
|
||||||
|
mbstate_t mbstate;
|
||||||
|
|
||||||
|
nargs = 0;
|
||||||
|
max_ref_arg = 0;
|
||||||
|
|
||||||
|
/* Search for format specifications. */
|
||||||
|
for (fmt = find_spec (fmt, &mbstate); *fmt != '\0'; fmt = spec.next_fmt)
|
||||||
|
{
|
||||||
|
/* Parse this spec. */
|
||||||
|
nargs += parse_one_spec (fmt, nargs, &spec, &max_ref_arg, &mbstate);
|
||||||
|
|
||||||
|
/* If the width is determined by an argument this is an int. */
|
||||||
|
if (spec.width_arg != -1 && (size_t) spec.width_arg < n)
|
||||||
|
argtypes[spec.width_arg] = PA_INT;
|
||||||
|
|
||||||
|
/* If the precision is determined by an argument this is an int. */
|
||||||
|
if (spec.prec_arg != -1 && (size_t) spec.prec_arg < n)
|
||||||
|
argtypes[spec.prec_arg] = PA_INT;
|
||||||
|
|
||||||
|
if ((size_t) spec.data_arg < n)
|
||||||
|
switch (spec.ndata_args)
|
||||||
|
{
|
||||||
|
case 0: /* No arguments. */
|
||||||
|
break;
|
||||||
|
case 1: /* One argument; we already have the type. */
|
||||||
|
argtypes[spec.data_arg] = spec.data_arg_type;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* We have more than one argument for this format spec. We must
|
||||||
|
call the arginfo function again to determine all the types. */
|
||||||
|
(void) (*__printf_arginfo_table[spec.info.spec])
|
||||||
|
(&spec.info, n - spec.data_arg, &argtypes[spec.data_arg]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MAX (nargs, max_ref_arg);
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/* Copyright (C) 1991, 1995, 1996, 1997, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#undef printf
|
||||||
|
|
||||||
|
/* Write formatted output to stdout from the format string FORMAT. */
|
||||||
|
/* VARARGS1 */
|
||||||
|
int
|
||||||
|
printf (const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = vfprintf (stdout, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# undef _IO_printf
|
||||||
|
/* This is for libg++. */
|
||||||
|
strong_alias (printf, _IO_printf);
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
/* Copyright (C) 1991-1993,1995-1999,2000,2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef _PRINTF_H
|
||||||
|
|
||||||
|
#define _PRINTF_H 1
|
||||||
|
#include <features.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
#define __need_FILE
|
||||||
|
#include <stdio.h>
|
||||||
|
#define __need_size_t
|
||||||
|
#define __need_wchar_t
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct printf_info
|
||||||
|
{
|
||||||
|
int prec; /* Precision. */
|
||||||
|
int width; /* Width. */
|
||||||
|
wchar_t spec; /* Format letter. */
|
||||||
|
unsigned int is_long_double:1;/* L flag. */
|
||||||
|
unsigned int is_short:1; /* h flag. */
|
||||||
|
unsigned int is_long:1; /* l flag. */
|
||||||
|
unsigned int alt:1; /* # flag. */
|
||||||
|
unsigned int space:1; /* Space flag. */
|
||||||
|
unsigned int left:1; /* - flag. */
|
||||||
|
unsigned int showsign:1; /* + flag. */
|
||||||
|
unsigned int group:1; /* ' flag. */
|
||||||
|
unsigned int extra:1; /* For special use. */
|
||||||
|
unsigned int is_char:1; /* hh flag. */
|
||||||
|
unsigned int wide:1; /* Nonzero for wide character streams. */
|
||||||
|
unsigned int i18n:1; /* I flag. */
|
||||||
|
wchar_t pad; /* Padding character. */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Type of a printf specifier-handler function.
|
||||||
|
STREAM is the FILE on which to write output.
|
||||||
|
INFO gives information about the format specification.
|
||||||
|
ARGS is a vector of pointers to the argument data;
|
||||||
|
the number of pointers will be the number returned
|
||||||
|
by the associated arginfo function for the same INFO.
|
||||||
|
|
||||||
|
The function should return the number of characters written,
|
||||||
|
or -1 for errors. */
|
||||||
|
|
||||||
|
typedef int printf_function (FILE *__stream,
|
||||||
|
__const struct printf_info *__info,
|
||||||
|
__const void *__const *__args);
|
||||||
|
|
||||||
|
/* Type of a printf specifier-arginfo function.
|
||||||
|
INFO gives information about the format specification.
|
||||||
|
N, ARGTYPES, and return value are as for parse_printf_format. */
|
||||||
|
|
||||||
|
typedef int printf_arginfo_function (__const struct printf_info *__info,
|
||||||
|
size_t __n, int *__argtypes);
|
||||||
|
|
||||||
|
|
||||||
|
/* Register FUNC to be called to format SPEC specifiers; ARGINFO must be
|
||||||
|
specified to determine how many arguments a SPEC conversion requires and
|
||||||
|
what their types are. */
|
||||||
|
|
||||||
|
extern int register_printf_function (int __spec, printf_function __func,
|
||||||
|
printf_arginfo_function __arginfo);
|
||||||
|
|
||||||
|
|
||||||
|
/* Parse FMT, and fill in N elements of ARGTYPES with the
|
||||||
|
types needed for the conversions FMT specifies. Returns
|
||||||
|
the number of arguments required by FMT.
|
||||||
|
|
||||||
|
The ARGINFO function registered with a user-defined format is passed a
|
||||||
|
`struct printf_info' describing the format spec being parsed. A width
|
||||||
|
or precision of INT_MIN means a `*' was used to indicate that the
|
||||||
|
width/precision will come from an arg. The function should fill in the
|
||||||
|
array it is passed with the types of the arguments it wants, and return
|
||||||
|
the number of arguments it wants. */
|
||||||
|
|
||||||
|
extern size_t parse_printf_format (__const char *__restrict __fmt, size_t __n,
|
||||||
|
int *__restrict __argtypes) __THROW;
|
||||||
|
|
||||||
|
|
||||||
|
/* Codes returned by `parse_printf_format' for basic types.
|
||||||
|
|
||||||
|
These values cover all the standard format specifications.
|
||||||
|
Users can add new values after PA_LAST for their own types. */
|
||||||
|
|
||||||
|
enum
|
||||||
|
{ /* C type: */
|
||||||
|
PA_INT, /* int */
|
||||||
|
PA_CHAR, /* int, cast to char */
|
||||||
|
PA_WCHAR, /* wide char */
|
||||||
|
PA_STRING, /* const char *, a '\0'-terminated string */
|
||||||
|
PA_WSTRING, /* const wchar_t *, wide character string */
|
||||||
|
PA_POINTER, /* void * */
|
||||||
|
PA_FLOAT, /* float */
|
||||||
|
PA_DOUBLE, /* double */
|
||||||
|
PA_LAST
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Flag bits that can be set in a type returned by `parse_printf_format'. */
|
||||||
|
#define PA_FLAG_MASK 0xff00
|
||||||
|
#define PA_FLAG_LONG_LONG (1 << 8)
|
||||||
|
#define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG
|
||||||
|
#define PA_FLAG_LONG (1 << 9)
|
||||||
|
#define PA_FLAG_SHORT (1 << 10)
|
||||||
|
#define PA_FLAG_PTR (1 << 11)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Function which can be registered as `printf'-handlers. */
|
||||||
|
|
||||||
|
/* Print floating point value using using abbreviations for the orders
|
||||||
|
of magnitude used for numbers ('k' for kilo, 'm' for mega etc). If
|
||||||
|
the format specifier is a uppercase character powers of 1000 are
|
||||||
|
used. Otherwise powers of 1024. */
|
||||||
|
extern int printf_size (FILE *__restrict __fp,
|
||||||
|
__const struct printf_info *__info,
|
||||||
|
__const void *__const *__restrict __args) __THROW;
|
||||||
|
|
||||||
|
/* This is the appropriate argument information function for `printf_size'. */
|
||||||
|
extern int printf_size_info (__const struct printf_info *__restrict
|
||||||
|
__info, size_t __n, int *__restrict __argtypes)
|
||||||
|
__THROW;
|
||||||
|
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* printf.h */
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,266 @@
|
|||||||
|
/* Print size value using units for orders of magnitude.
|
||||||
|
Copyright (C) 1997,1998,1999,2000,2001,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, 1997.
|
||||||
|
Based on a proposal by Larry McVoy <[email protected]>.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <ieee754.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <printf.h>
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libioP.h>
|
||||||
|
#else
|
||||||
|
# include <stdio.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* This defines make it possible to use the same code for GNU C library and
|
||||||
|
the GNU I/O library. */
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# define PUT(f, s, n) _IO_sputn (f, s, n)
|
||||||
|
# define PAD(f, c, n) (wide ? _IO_wpadn (f, c, n) : INTUSE(_IO_padn) (f, c, n))
|
||||||
|
/* We use this file GNU C library and GNU I/O library. So make
|
||||||
|
names equal. */
|
||||||
|
# undef putc
|
||||||
|
# define putc(c, f) (wide \
|
||||||
|
? (int)_IO_putwc_unlocked (c, f) : _IO_putc_unlocked (c, f))
|
||||||
|
# define size_t _IO_size_t
|
||||||
|
# define FILE _IO_FILE
|
||||||
|
#else /* ! USE_IN_LIBIO */
|
||||||
|
# define PUT(f, s, n) fwrite (s, 1, n, f)
|
||||||
|
# define PAD(f, c, n) __printf_pad (f, c, n)
|
||||||
|
ssize_t __printf_pad __P ((FILE *, char pad, int n)); /* In vfprintf.c. */
|
||||||
|
#endif /* USE_IN_LIBIO */
|
||||||
|
|
||||||
|
/* Macros for doing the actual output. */
|
||||||
|
|
||||||
|
#define outchar(ch) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
register const int outc = (ch); \
|
||||||
|
if (putc (outc, fp) == EOF) \
|
||||||
|
return -1; \
|
||||||
|
++done; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define PRINT(ptr, wptr, len) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
register size_t outlen = (len); \
|
||||||
|
if (len > 20) \
|
||||||
|
{ \
|
||||||
|
if (PUT (fp, wide ? (const char *) wptr : ptr, outlen) != outlen) \
|
||||||
|
return -1; \
|
||||||
|
ptr += outlen; \
|
||||||
|
done += outlen; \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
if (wide) \
|
||||||
|
while (outlen-- > 0) \
|
||||||
|
outchar (*wptr++); \
|
||||||
|
else \
|
||||||
|
while (outlen-- > 0) \
|
||||||
|
outchar (*ptr++); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define PADN(ch, len) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if (PAD (fp, ch, len) != len) \
|
||||||
|
return -1; \
|
||||||
|
done += len; \
|
||||||
|
} \
|
||||||
|
while (0)
|
||||||
|
|
||||||
|
/* Prototype for helper functions. */
|
||||||
|
extern int __printf_fp (FILE *fp, const struct printf_info *info,
|
||||||
|
const void *const *args);
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
printf_size (FILE *fp, const struct printf_info *info, const void *const *args)
|
||||||
|
{
|
||||||
|
/* Units for the both formats. */
|
||||||
|
#define BINARY_UNITS " kmgtpezy"
|
||||||
|
#define DECIMAL_UNITS " KMGTPEZY"
|
||||||
|
static const char units[2][sizeof (BINARY_UNITS)] =
|
||||||
|
{
|
||||||
|
BINARY_UNITS, /* For binary format. */
|
||||||
|
DECIMAL_UNITS /* For decimal format. */
|
||||||
|
};
|
||||||
|
const char *tag = units[isupper (info->spec) != 0];
|
||||||
|
int divisor = isupper (info->spec) ? 1000 : 1024;
|
||||||
|
|
||||||
|
/* The floating-point value to output. */
|
||||||
|
union
|
||||||
|
{
|
||||||
|
union ieee754_double dbl;
|
||||||
|
union ieee854_long_double ldbl;
|
||||||
|
}
|
||||||
|
fpnum;
|
||||||
|
const void *ptr = &fpnum;
|
||||||
|
|
||||||
|
int negative = 0;
|
||||||
|
|
||||||
|
/* "NaN" or "Inf" for the special cases. */
|
||||||
|
const char *special = NULL;
|
||||||
|
const wchar_t *wspecial = NULL;
|
||||||
|
|
||||||
|
struct printf_info fp_info;
|
||||||
|
int done = 0;
|
||||||
|
int wide = info->wide;
|
||||||
|
|
||||||
|
|
||||||
|
/* Fetch the argument value. */
|
||||||
|
#ifndef __NO_LONG_DOUBLE_MATH
|
||||||
|
if (info->is_long_double && sizeof (long double) > sizeof (double))
|
||||||
|
{
|
||||||
|
fpnum.ldbl.d = *(const long double *) args[0];
|
||||||
|
|
||||||
|
/* Check for special values: not a number or infinity. */
|
||||||
|
if (__isnanl (fpnum.ldbl.d))
|
||||||
|
{
|
||||||
|
special = "nan";
|
||||||
|
wspecial = L"nan";
|
||||||
|
negative = 0;
|
||||||
|
}
|
||||||
|
else if (__isinfl (fpnum.ldbl.d))
|
||||||
|
{
|
||||||
|
special = "inf";
|
||||||
|
wspecial = L"inf";
|
||||||
|
|
||||||
|
negative = fpnum.ldbl.d < 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (fpnum.ldbl.d >= divisor && tag[1] != '\0')
|
||||||
|
{
|
||||||
|
fpnum.ldbl.d /= divisor;
|
||||||
|
++tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif /* no long double */
|
||||||
|
{
|
||||||
|
fpnum.dbl.d = *(const double *) args[0];
|
||||||
|
|
||||||
|
/* Check for special values: not a number or infinity. */
|
||||||
|
if (__isnan (fpnum.dbl.d))
|
||||||
|
{
|
||||||
|
special = "nan";
|
||||||
|
wspecial = L"nan";
|
||||||
|
negative = 0;
|
||||||
|
}
|
||||||
|
else if (__isinf (fpnum.dbl.d))
|
||||||
|
{
|
||||||
|
special = "inf";
|
||||||
|
wspecial = L"inf";
|
||||||
|
|
||||||
|
negative = fpnum.dbl.d < 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (fpnum.dbl.d >= divisor && tag[1] != '\0')
|
||||||
|
{
|
||||||
|
fpnum.dbl.d /= divisor;
|
||||||
|
++tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (special)
|
||||||
|
{
|
||||||
|
int width = info->prec > width ? info->prec : width;
|
||||||
|
|
||||||
|
if (negative || info->showsign || info->space)
|
||||||
|
--width;
|
||||||
|
width -= 3;
|
||||||
|
|
||||||
|
if (!info->left && width > 0)
|
||||||
|
PADN (' ', width);
|
||||||
|
|
||||||
|
if (negative)
|
||||||
|
outchar ('-');
|
||||||
|
else if (info->showsign)
|
||||||
|
outchar ('+');
|
||||||
|
else if (info->space)
|
||||||
|
outchar (' ');
|
||||||
|
|
||||||
|
PRINT (special, wspecial, 3);
|
||||||
|
|
||||||
|
if (info->left && width > 0)
|
||||||
|
PADN (' ', width);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prepare to print the number. We want to use `__printf_fp' so we
|
||||||
|
have to prepare a `printf_info' structure. */
|
||||||
|
fp_info.spec = 'f';
|
||||||
|
fp_info.prec = info->prec < 0 ? 3 : info->prec;
|
||||||
|
fp_info.is_long_double = info->is_long_double;
|
||||||
|
fp_info.is_short = info->is_short;
|
||||||
|
fp_info.is_long = info->is_long;
|
||||||
|
fp_info.alt = info->alt;
|
||||||
|
fp_info.space = info->space;
|
||||||
|
fp_info.left = info->left;
|
||||||
|
fp_info.showsign = info->showsign;
|
||||||
|
fp_info.group = info->group;
|
||||||
|
fp_info.extra = info->extra;
|
||||||
|
fp_info.pad = info->pad;
|
||||||
|
fp_info.wide = wide;
|
||||||
|
|
||||||
|
if (fp_info.left && fp_info.pad == L' ')
|
||||||
|
{
|
||||||
|
/* We must do the padding ourself since the unit character must
|
||||||
|
be placed before the padding spaces. */
|
||||||
|
fp_info.width = 0;
|
||||||
|
|
||||||
|
done = __printf_fp (fp, &fp_info, &ptr);
|
||||||
|
if (done > 0)
|
||||||
|
{
|
||||||
|
outchar (*tag);
|
||||||
|
if (info->width > done)
|
||||||
|
PADN (' ', info->width - done);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* We can let __printf_fp do all the printing and just add our
|
||||||
|
unit character afterwards. */
|
||||||
|
fp_info.width = info->width - 1;
|
||||||
|
|
||||||
|
done = __printf_fp (fp, &fp_info, &ptr);
|
||||||
|
if (done > 0)
|
||||||
|
outchar (*tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This is the function used by `vfprintf' to determine number and
|
||||||
|
type of the arguments. */
|
||||||
|
int
|
||||||
|
printf_size_info (const struct printf_info *info, size_t n, int *argtypes)
|
||||||
|
{
|
||||||
|
/* We need only one double or long double argument. */
|
||||||
|
if (n >= 1)
|
||||||
|
argtypes[0] = PA_DOUBLE | (info->is_long_double ? PA_FLAG_LONG_DOUBLE : 0);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
/* Copyright (C) 1991,1992,1995-1997,2001,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <libintl.h>
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <wchar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef HAVE_GNU_LD
|
||||||
|
#define _sys_siglist sys_siglist
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Defined in sys_siglist.c. */
|
||||||
|
extern const char *const _sys_siglist[];
|
||||||
|
extern const char *const _sys_siglist_internal[] attribute_hidden;
|
||||||
|
|
||||||
|
|
||||||
|
/* Print out on stderr a line consisting of the test in S, a colon, a space,
|
||||||
|
a message describing the meaning of the signal number SIG and a newline.
|
||||||
|
If S is NULL or "", the colon and space are omitted. */
|
||||||
|
void
|
||||||
|
psignal (int sig, const char *s)
|
||||||
|
{
|
||||||
|
const char *colon, *desc;
|
||||||
|
|
||||||
|
if (s == NULL || s == '\0')
|
||||||
|
s = colon = "";
|
||||||
|
else
|
||||||
|
colon = ": ";
|
||||||
|
|
||||||
|
if (sig >= 0 && sig < NSIG && (desc = INTUSE(_sys_siglist)[sig]) != NULL)
|
||||||
|
{
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
if (_IO_fwide (stderr, 0) > 0)
|
||||||
|
(void) __fwprintf (stderr, L"%s%s%s\n", s, colon, _(desc));
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
(void) fprintf (stderr, "%s%s%s\n", s, colon, _(desc));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
(void) __asprintf (&buf, _("%s%sUnknown signal %d\n"), s, colon, sig);
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
if (_IO_fwide (stderr, 0) > 0)
|
||||||
|
(void) __fwprintf (stderr, L"%s", buf);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
(void) fputs (buf, stderr);
|
||||||
|
|
||||||
|
free (buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/* Copyright (C) 1991, 1997, 1998, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libio/iolibio.h>
|
||||||
|
# define fwrite(p, n, m, s) INTUSE(_IO_fwrite) (p, n, m, s)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Write the word (int) W to STREAM. */
|
||||||
|
int
|
||||||
|
putw (int w, FILE *stream)
|
||||||
|
{
|
||||||
|
/* Is there a better way? */
|
||||||
|
if (fwrite ((const void *) &w, sizeof (w), 1, stream) < 1)
|
||||||
|
return EOF;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/* Copyright (C) 1991, 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <printf.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/* Array of functions indexed by format character. */
|
||||||
|
libc_freeres_ptr (printf_arginfo_function **__printf_arginfo_table)
|
||||||
|
attribute_hidden;
|
||||||
|
printf_function **__printf_function_table attribute_hidden;
|
||||||
|
|
||||||
|
int __register_printf_function __P ((int, printf_function,
|
||||||
|
printf_arginfo_function));
|
||||||
|
|
||||||
|
/* Register FUNC to be called to format SPEC specifiers. */
|
||||||
|
int
|
||||||
|
__register_printf_function (spec, converter, arginfo)
|
||||||
|
int spec;
|
||||||
|
printf_function converter;
|
||||||
|
printf_arginfo_function arginfo;
|
||||||
|
{
|
||||||
|
if (spec < 0 || spec > (int) UCHAR_MAX)
|
||||||
|
{
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (__printf_function_table == NULL)
|
||||||
|
{
|
||||||
|
__printf_arginfo_table = (printf_arginfo_function **)
|
||||||
|
malloc ((UCHAR_MAX + 1) * sizeof (void *) * 2);
|
||||||
|
if (__printf_arginfo_table == NULL)
|
||||||
|
return -1;
|
||||||
|
__printf_function_table = (printf_function **)
|
||||||
|
(__printf_arginfo_table + UCHAR_MAX + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
__printf_function_table[spec] = converter;
|
||||||
|
__printf_arginfo_table[spec] = arginfo;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
weak_alias (__register_printf_function, register_printf_function)
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright (C) 1991, 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libioP.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Read formatted input from stdin according to the format string FORMAT. */
|
||||||
|
/* VARARGS1 */
|
||||||
|
int
|
||||||
|
scanf (const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
done = INTUSE(_IO_vfscanf) (stdin, format, arg, NULL);
|
||||||
|
#else
|
||||||
|
done = vfscanf (stdin, format, arg);
|
||||||
|
#endif
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright (C) 1991, 1995, 1997, 1998 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libio/libioP.h>
|
||||||
|
# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Write formatted output into S, according to the format
|
||||||
|
string FORMAT, writing no more than MAXLEN characters. */
|
||||||
|
/* VARARGS3 */
|
||||||
|
int
|
||||||
|
__snprintf (char *s, size_t maxlen, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = __vsnprintf (s, maxlen, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
weak_alias (__snprintf, snprintf)
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/* Copyright (C) 1991, 1995, 1997, 1998, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libio/iolibio.h>
|
||||||
|
# define vsprintf(s, f, a) INTUSE(_IO_vsprintf) (s, f, a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Write formatted output into S, according to the format string FORMAT. */
|
||||||
|
/* VARARGS2 */
|
||||||
|
int
|
||||||
|
sprintf (char *s, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = vsprintf (s, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
libc_hidden_def (sprintf)
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
strong_alias(sprintf, _IO_sprintf)
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/* Copyright (C) 1991,1995,1996,1998,2002,2003 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <libio/iolibio.h>
|
||||||
|
# define __vsscanf(s, f, a) _IO_vsscanf (s, f, a)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Read formatted input from S, according to the format string FORMAT. */
|
||||||
|
/* VARARGS2 */
|
||||||
|
int
|
||||||
|
sscanf (const char *s, const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list arg;
|
||||||
|
int done;
|
||||||
|
|
||||||
|
va_start (arg, format);
|
||||||
|
done = __vsscanf (s, format, arg);
|
||||||
|
va_end (arg);
|
||||||
|
|
||||||
|
return done;
|
||||||
|
}
|
||||||
|
libc_hidden_def (sscanf)
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# undef _IO_sscanf
|
||||||
|
/* This is for libg++. */
|
||||||
|
strong_alias (sscanf, _IO_sscanf)
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/* Functions to access FILE structure internals.
|
||||||
|
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/* This header contains the same definitions as the header of the same name
|
||||||
|
on Sun's Solaris OS. */
|
||||||
|
|
||||||
|
#ifndef _STDIO_EXT_H
|
||||||
|
#define _STDIO_EXT_H 1
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
/* Query current state of the locking status. */
|
||||||
|
FSETLOCKING_QUERY = 0,
|
||||||
|
#define FSETLOCKING_QUERY FSETLOCKING_QUERY
|
||||||
|
/* The library protects all uses of the stream functions, except for
|
||||||
|
uses of the *_unlocked functions, by calls equivalent to flockfile(). */
|
||||||
|
FSETLOCKING_INTERNAL,
|
||||||
|
#define FSETLOCKING_INTERNAL FSETLOCKING_INTERNAL
|
||||||
|
/* The user will take care of locking. */
|
||||||
|
FSETLOCKING_BYCALLER
|
||||||
|
#define FSETLOCKING_BYCALLER FSETLOCKING_BYCALLER
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
/* Return the size of the buffer of FP in bytes currently in use by
|
||||||
|
the given stream. */
|
||||||
|
extern size_t __fbufsize (FILE *__fp);
|
||||||
|
|
||||||
|
|
||||||
|
/* Return non-zero value iff the stream FP is opened readonly, or if the
|
||||||
|
last operation on the stream was a read operation. */
|
||||||
|
extern int __freading (FILE *__fp);
|
||||||
|
|
||||||
|
/* Return non-zero value iff the stream FP is opened write-only or
|
||||||
|
append-only, or if the last operation on the stream was a write
|
||||||
|
operation. */
|
||||||
|
extern int __fwriting (FILE *__fp);
|
||||||
|
|
||||||
|
|
||||||
|
/* Return non-zero value iff stream FP is not opened write-only or
|
||||||
|
append-only. */
|
||||||
|
extern int __freadable (FILE *__fp);
|
||||||
|
|
||||||
|
/* Return non-zero value iff stream FP is not opened read-only. */
|
||||||
|
extern int __fwritable (FILE *__fp);
|
||||||
|
|
||||||
|
|
||||||
|
/* Return non-zero value iff the stream FP is line-buffered. */
|
||||||
|
extern int __flbf (FILE *__fp);
|
||||||
|
|
||||||
|
|
||||||
|
/* Discard all pending buffered I/O on the stream FP. */
|
||||||
|
extern void __fpurge (FILE *__fp);
|
||||||
|
|
||||||
|
/* Return amount of output in bytes pending on a stream FP. */
|
||||||
|
extern size_t __fpending (FILE *__fp);
|
||||||
|
|
||||||
|
/* Flush all line-buffered files. */
|
||||||
|
extern void _flushlbf (void);
|
||||||
|
|
||||||
|
|
||||||
|
/* Set locking status of stream FP to TYPE. */
|
||||||
|
extern int __fsetlocking (FILE *__fp, int __type);
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* stdio_ext.h */
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* Copyright (C) 1994, 1997, 1998, 1999 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#if !defined _STDIO_H && !defined __need_FOPEN_MAX && !defined __need_IOV_MAX
|
||||||
|
# error "Never include <bits/stdio_lim.h> directly; use <stdio.h> instead."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _STDIO_H
|
||||||
|
# define L_tmpnam @L_tmpnam@
|
||||||
|
# define TMP_MAX @TMP_MAX@
|
||||||
|
# define FILENAME_MAX @FILENAME_MAX@
|
||||||
|
|
||||||
|
# ifdef __USE_POSIX
|
||||||
|
# define L_ctermid @L_ctermid@
|
||||||
|
# define L_cuserid @L_cuserid@
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined __need_FOPEN_MAX || defined _STDIO_H
|
||||||
|
# undef FOPEN_MAX
|
||||||
|
# define FOPEN_MAX @FOPEN_MAX@
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined __need_IOV_MAX && !defined IOV_MAX
|
||||||
|
@define_IOV_MAX@
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/* Copyright (C) 1991,1993,1996-1999,2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Generate a unique temporary filename using up to five characters of PFX
|
||||||
|
if it is not NULL. The directory to put this file in is searched for
|
||||||
|
as follows: First the environment variable "TMPDIR" is checked.
|
||||||
|
If it contains the name of a writable directory, that directory is used.
|
||||||
|
If not and if DIR is not NULL, that value is checked. If that fails,
|
||||||
|
P_tmpdir is tried and finally "/tmp". The storage for the filename
|
||||||
|
is allocated by `malloc'. */
|
||||||
|
char *
|
||||||
|
tempnam (const char *dir, const char *pfx)
|
||||||
|
{
|
||||||
|
char buf[FILENAME_MAX];
|
||||||
|
|
||||||
|
if (__path_search (buf, FILENAME_MAX, dir, pfx, 1))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (__gen_tempname (buf, __GT_NOCREATE))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return __strdup (buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
link_warning (tempnam,
|
||||||
|
"the use of `tempnam' is dangerous, better use `mkstemp'")
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
/* Copyright (C) 1991,1993,1996-1999,2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static char tmpnam_buffer[L_tmpnam];
|
||||||
|
|
||||||
|
/* Generate a unique filename in P_tmpdir.
|
||||||
|
|
||||||
|
This function is *not* thread safe! */
|
||||||
|
char *
|
||||||
|
tmpnam (char *s)
|
||||||
|
{
|
||||||
|
/* By using two buffers we manage to be thread safe in the case
|
||||||
|
where S != NULL. */
|
||||||
|
char tmpbufmem[L_tmpnam];
|
||||||
|
char *tmpbuf = s ?: tmpbufmem;
|
||||||
|
|
||||||
|
/* In the following call we use the buffer pointed to by S if
|
||||||
|
non-NULL although we don't know the size. But we limit the size
|
||||||
|
to L_tmpnam characters in any case. */
|
||||||
|
if (__builtin_expect (__path_search (tmpbuf, L_tmpnam, NULL, NULL, 0),
|
||||||
|
0))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE), 0))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (char *) memcpy (tmpnam_buffer, tmpbuf, L_tmpnam);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
link_warning (tmpnam,
|
||||||
|
"the use of `tmpnam' is dangerous, better use `mkstemp'")
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/* Copyright (C) 1991,1993,1996-1999,2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* Generate a unique filename in P_tmpdir. If S is NULL return NULL.
|
||||||
|
This makes this function thread safe. */
|
||||||
|
char *
|
||||||
|
tmpnam_r (char *s)
|
||||||
|
{
|
||||||
|
if (s == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (__path_search (s, L_tmpnam, NULL, NULL, 0))
|
||||||
|
return NULL;
|
||||||
|
if (__gen_tempname (s, __GT_NOCREATE))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
link_warning (tmpnam_r,
|
||||||
|
"the use of `tmpnam_r' is dangerous, better use `mkstemp'")
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
|||||||
|
#include <wctype.h>
|
||||||
|
#define COMPILE_WPRINTF 1
|
||||||
|
#include "vfprintf.c"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#define COMPILE_WSCANF 1
|
||||||
|
#include "vfscanf.c"
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/* Copyright (C) 1991, 1993, 1995, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#undef __OPTIMIZE__ /* Avoid inline `vprintf' function. */
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#undef vprintf
|
||||||
|
|
||||||
|
/* Write formatted output to stdout according to the
|
||||||
|
format string FORMAT, using the argument list in ARG. */
|
||||||
|
int
|
||||||
|
vprintf (format, arg)
|
||||||
|
const char *format;
|
||||||
|
__gnuc_va_list arg;
|
||||||
|
{
|
||||||
|
return vfprintf (stdout, format, arg);
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
# Copyright (C) 1991-1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||||
|
# This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
# The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU Lesser General Public
|
||||||
|
# License as published by the Free Software Foundation; either
|
||||||
|
# version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
# The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
# Lesser General Public License for more details.
|
||||||
|
|
||||||
|
# You should have received a copy of the GNU Lesser General Public
|
||||||
|
# License along with the GNU C Library; if not, write to the Free
|
||||||
|
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
# 02111-1307 USA.
|
||||||
|
|
||||||
|
#
|
||||||
|
# Makefile for stdlib routines
|
||||||
|
#
|
||||||
|
subdir := stdlib
|
||||||
|
|
||||||
|
headers := stdlib.h alloca.h monetary.h fmtmsg.h ucontext.h sys/ucontext.h \
|
||||||
|
inttypes.h stdint.h bits/wordsize.h bits/wchar.h \
|
||||||
|
errno.h sys/errno.h bits/errno.h
|
||||||
|
|
||||||
|
routines := \
|
||||||
|
atof atoi atol atoll \
|
||||||
|
abort \
|
||||||
|
bsearch qsort msort \
|
||||||
|
getenv putenv setenv secure-getenv \
|
||||||
|
exit on_exit atexit cxa_atexit cxa_finalize old_atexit \
|
||||||
|
abs labs llabs \
|
||||||
|
div ldiv lldiv \
|
||||||
|
mblen mbstowcs mbtowc wcstombs wctomb \
|
||||||
|
random random_r rand rand_r \
|
||||||
|
drand48 erand48 lrand48 nrand48 mrand48 jrand48 \
|
||||||
|
srand48 seed48 lcong48 \
|
||||||
|
drand48_r erand48_r lrand48_r nrand48_r mrand48_r jrand48_r \
|
||||||
|
srand48_r seed48_r lcong48_r \
|
||||||
|
drand48-iter \
|
||||||
|
strtol strtoul strtoll strtoull \
|
||||||
|
strtol_l strtoul_l strtoll_l strtoull_l \
|
||||||
|
strtof strtod strtold \
|
||||||
|
strtof_l strtod_l strtold_l \
|
||||||
|
system canonicalize \
|
||||||
|
a64l l64a \
|
||||||
|
rpmatch strfmon strfmon_l getsubopt xpg_basename fmtmsg \
|
||||||
|
strtoimax strtoumax wcstoimax wcstoumax \
|
||||||
|
getcontext setcontext makecontext swapcontext
|
||||||
|
|
||||||
|
# These routines will be omitted from the libc shared object.
|
||||||
|
# Instead the static object files will be included in a special archive
|
||||||
|
# linked against when the shared library will be used.
|
||||||
|
static-only-routines = atexit
|
||||||
|
|
||||||
|
distribute := exit.h grouping.h abort-instr.h isomac.c tst-fmtmsg.sh \
|
||||||
|
allocalim.h
|
||||||
|
test-srcs := tst-fmtmsg
|
||||||
|
tests := tst-strtol tst-strtod testmb testrand testsort testdiv \
|
||||||
|
test-canon test-canon2 tst-strtoll tst-environ \
|
||||||
|
tst-xpg-basename tst-random tst-bsearch tst-limits \
|
||||||
|
tst-rand48 bug-strtod tst-setcontext test-a64l tst-qsort \
|
||||||
|
tst-system
|
||||||
|
|
||||||
|
|
||||||
|
# Several mpn functions from GNU MP are used by the strtod function.
|
||||||
|
mpn-routines := inlines add_n addmul_1 cmp divmod_1 divrem udiv_qrnnd \
|
||||||
|
lshift rshift mod_1 mul mul_1 mul_n sub_n submul_1
|
||||||
|
mpn-headers = longlong.h gmp.h gmp-impl.h gmp-mparam.h asm-syntax.h
|
||||||
|
|
||||||
|
routines := $(strip $(routines) $(mpn-routines)) \
|
||||||
|
dbl2mpn ldbl2mpn \
|
||||||
|
mpn2flt mpn2dbl mpn2ldbl
|
||||||
|
aux := fpioconst mp_clz_tab
|
||||||
|
distribute := $(distribute) $(mpn-headers) gen-mpn-copy fpioconst.h
|
||||||
|
|
||||||
|
generated += isomac isomac.out
|
||||||
|
|
||||||
|
CFLAGS-bsearch.c = $(exceptions)
|
||||||
|
CFLAGS-msort.c = $(exceptions)
|
||||||
|
CFLAGS-qsort.c = $(exceptions)
|
||||||
|
|
||||||
|
include ../Makeconfig
|
||||||
|
|
||||||
|
ifneq (,$(filter %REENTRANT, $(defines)))
|
||||||
|
CFLAGS-strfmon.c = -D_IO_MTSAFE_IO
|
||||||
|
CFLAGS-strfmon_l.c = -D_IO_MTSAFE_IO
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq (yes,$(have-protected))
|
||||||
|
CFLAGS-atexit.c = -DHAVE_DOT_HIDDEN
|
||||||
|
endif
|
||||||
|
|
||||||
|
include ../Rules
|
||||||
|
|
||||||
|
# Testdir has to be named stdlib and needs to be writable
|
||||||
|
test-canon-ARGS = --test-dir=${common-objpfx}stdlib
|
||||||
|
|
||||||
|
tst-strtod-ENV = LOCPATH=$(common-objpfx)localedata
|
||||||
|
|
||||||
|
# Run a test on the header files we use.
|
||||||
|
tests: $(objpfx)isomac.out
|
||||||
|
|
||||||
|
ifeq (no,$(cross-compiling))
|
||||||
|
tests: $(objpfx)tst-fmtmsg.out
|
||||||
|
endif
|
||||||
|
|
||||||
|
$(objpfx)isomac.out: $(objpfx)isomac
|
||||||
|
$(dir $<)$(notdir $<) '$(CC)' \
|
||||||
|
'-I../include -I.. $(+sysdep-includes) $(sysincludes)' > $<.out
|
||||||
|
|
||||||
|
isomac-CFLAGS = -O
|
||||||
|
$(objpfx)isomac: isomac.c
|
||||||
|
$(native-compile)
|
||||||
|
|
||||||
|
$(objpfx)tst-fmtmsg.out: tst-fmtmsg.sh $(objpfx)tst-fmtmsg
|
||||||
|
$(SHELL) -e $< $(common-objpfx) '$(run-program-prefix)' $(common-objpfx)stdlib/
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
libc {
|
||||||
|
GLIBC_2.0 {
|
||||||
|
# functions with required interface outside normal name space
|
||||||
|
__xpg_basename;
|
||||||
|
|
||||||
|
# functions used in inline functions or macros
|
||||||
|
__strto*_internal;
|
||||||
|
|
||||||
|
# functions used in other libraries
|
||||||
|
__secure_getenv;
|
||||||
|
|
||||||
|
# a*
|
||||||
|
a64l; abort; abs; atexit; atof; atoi; atol; atoll;
|
||||||
|
|
||||||
|
# b*
|
||||||
|
bsearch;
|
||||||
|
|
||||||
|
# c*
|
||||||
|
canonicalize_file_name; clearenv;
|
||||||
|
|
||||||
|
# d*
|
||||||
|
div; drand48; drand48_r;
|
||||||
|
|
||||||
|
# e*
|
||||||
|
erand48; erand48_r; exit;
|
||||||
|
|
||||||
|
# g*
|
||||||
|
getenv; getsubopt;
|
||||||
|
|
||||||
|
# i*
|
||||||
|
initstate; initstate_r;
|
||||||
|
|
||||||
|
# l*
|
||||||
|
l64a; labs; lcong48; lcong48_r; ldiv; llabs; lldiv; lrand48; lrand48_r;
|
||||||
|
|
||||||
|
# m*
|
||||||
|
mblen; mbrlen; mbrtowc; mbsinit; mbsnrtowcs; mbsrtowcs; mbstowcs;
|
||||||
|
mbtowc; mcheck; mcount; mrand48; mrand48_r;
|
||||||
|
|
||||||
|
# n*
|
||||||
|
nrand48; nrand48_r;
|
||||||
|
|
||||||
|
# o*
|
||||||
|
on_exit;
|
||||||
|
|
||||||
|
# p*
|
||||||
|
putenv;
|
||||||
|
|
||||||
|
# q*
|
||||||
|
qsort;
|
||||||
|
|
||||||
|
# r*
|
||||||
|
rand; rand_r; random; random_r; realpath; rpmatch;
|
||||||
|
|
||||||
|
# s*
|
||||||
|
seed48; seed48_r; setcontext; setenv; setstate; setstate_r; srand; srand48;
|
||||||
|
srand48_r; srandom; srandom_r; step; strfmon; strtod; strtof; strtol;
|
||||||
|
strtold; strtoll; strtoq; strtoul; strtoull; strtouq; system;
|
||||||
|
|
||||||
|
# u*
|
||||||
|
unsetenv;
|
||||||
|
|
||||||
|
# w*
|
||||||
|
wcstombs; wctomb;
|
||||||
|
}
|
||||||
|
GLIBC_2.1 {
|
||||||
|
# a*
|
||||||
|
addseverity;
|
||||||
|
|
||||||
|
# f*
|
||||||
|
fmtmsg;
|
||||||
|
|
||||||
|
# g*
|
||||||
|
getcontext;
|
||||||
|
|
||||||
|
# m*
|
||||||
|
makecontext;
|
||||||
|
|
||||||
|
# s*
|
||||||
|
strtoimax; strtoumax; swapcontext;
|
||||||
|
}
|
||||||
|
GLIBC_2.1.1 {
|
||||||
|
# _*
|
||||||
|
_Exit;
|
||||||
|
|
||||||
|
# i*
|
||||||
|
imaxabs; imaxdiv;
|
||||||
|
}
|
||||||
|
GLIBC_2.1.3 {
|
||||||
|
# used by new G++ ABI
|
||||||
|
__cxa_atexit; __cxa_finalize;
|
||||||
|
}
|
||||||
|
GLIBC_2.3 {
|
||||||
|
# Silent change in SUS.
|
||||||
|
realpath;
|
||||||
|
}
|
||||||
|
GLIBC_PRIVATE {
|
||||||
|
# functions which have an additional interface since they are
|
||||||
|
# are cancelable.
|
||||||
|
__libc_system;
|
||||||
|
|
||||||
|
# functions used in other libraries.
|
||||||
|
__on_exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
/* Copyright (C) 1995, 1997, 1998, 1999 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TABLE_BASE 0x2e
|
||||||
|
#define TABLE_SIZE 0x4d
|
||||||
|
|
||||||
|
#define XX ((char)0x40)
|
||||||
|
|
||||||
|
|
||||||
|
static const char a64l_table[TABLE_SIZE] =
|
||||||
|
{
|
||||||
|
/* 0x2e */ 0, 1,
|
||||||
|
/* 0x30 */ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, XX, XX, XX, XX, XX, XX,
|
||||||
|
/* 0x40 */ XX, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
|
||||||
|
/* 0x50 */ 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, XX, XX, XX, XX, XX,
|
||||||
|
/* 0x60 */ XX, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52,
|
||||||
|
/* 0x70 */ 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
long int
|
||||||
|
a64l (string)
|
||||||
|
const char *string;
|
||||||
|
{
|
||||||
|
const char *ptr = string;
|
||||||
|
unsigned long int result = 0ul;
|
||||||
|
const char *end = ptr + 6;
|
||||||
|
int shift = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
unsigned index;
|
||||||
|
unsigned value;
|
||||||
|
|
||||||
|
index = *ptr - TABLE_BASE;
|
||||||
|
if ((unsigned int) index >= TABLE_SIZE)
|
||||||
|
break;
|
||||||
|
value = (int) a64l_table[index];
|
||||||
|
if (value == (int) XX)
|
||||||
|
break;
|
||||||
|
++ptr;
|
||||||
|
result |= value << shift;
|
||||||
|
shift += 6;
|
||||||
|
}
|
||||||
|
while (ptr != end);
|
||||||
|
|
||||||
|
return (long int) result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#undef abs
|
||||||
|
|
||||||
|
/* Return the absolute value of I. */
|
||||||
|
int
|
||||||
|
abs (int i)
|
||||||
|
{
|
||||||
|
return i < 0 ? -i : i;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/* Copyright (C) 1992, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef _ALLOCA_H
|
||||||
|
#define _ALLOCA_H 1
|
||||||
|
|
||||||
|
#include <features.h>
|
||||||
|
|
||||||
|
#define __need_size_t
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
/* Remove any previous definitions. */
|
||||||
|
#undef alloca
|
||||||
|
|
||||||
|
/* Allocate a block that will be freed when the calling function exits. */
|
||||||
|
extern void *alloca (size_t __size) __THROW;
|
||||||
|
|
||||||
|
#ifdef __GNUC__
|
||||||
|
# define alloca(size) __builtin_alloca (size)
|
||||||
|
#endif /* GCC. */
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* alloca.h */
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright (C) 1991, 1996, 1999, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "exit.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* This is defined by newer gcc version unique for each module. */
|
||||||
|
extern void *__dso_handle __attribute__ ((__weak__));
|
||||||
|
|
||||||
|
|
||||||
|
/* Register FUNC to be executed by `exit'. */
|
||||||
|
int
|
||||||
|
atexit (void (*func) (void))
|
||||||
|
{
|
||||||
|
return __cxa_atexit ((void (*) (void *)) func, NULL,
|
||||||
|
&__dso_handle == NULL ? NULL : __dso_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Hide the symbol so that no definition but the one locally in the
|
||||||
|
executable or DSO is used. */
|
||||||
|
#ifdef HAVE_DOT_HIDDEN
|
||||||
|
asm (".hidden\tatexit");
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#undef atof
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert a string to a double. */
|
||||||
|
double
|
||||||
|
atof (const char *nptr)
|
||||||
|
{
|
||||||
|
return strtod (nptr, (char **) NULL);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#undef atoi
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert a string to an int. */
|
||||||
|
int
|
||||||
|
atoi (const char *nptr)
|
||||||
|
{
|
||||||
|
return (int) strtol (nptr, (char **) NULL, 10);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright (C) 1991, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#undef atol
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert a string to a long int. */
|
||||||
|
long int
|
||||||
|
atol (const char *nptr)
|
||||||
|
{
|
||||||
|
return strtol (nptr, (char **) NULL, 10);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright (C) 1991, 1997, 1998 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#undef atoll
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert a string to a long long int. */
|
||||||
|
long long int
|
||||||
|
atoll (const char *nptr)
|
||||||
|
{
|
||||||
|
return strtoll (nptr, (char **) NULL, 10);
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/* Copyright (C) 1991,92,97,2000,02 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Perform a binary search for KEY in BASE which has NMEMB elements
|
||||||
|
of SIZE bytes each. The comparisons are done by (*COMPAR)(). */
|
||||||
|
void *
|
||||||
|
bsearch (const void *key, const void *base, size_t nmemb, size_t size,
|
||||||
|
int (*compar) (const void *, const void *))
|
||||||
|
{
|
||||||
|
size_t l, u, idx;
|
||||||
|
const void *p;
|
||||||
|
int comparison;
|
||||||
|
|
||||||
|
l = 0;
|
||||||
|
u = nmemb;
|
||||||
|
while (l < u)
|
||||||
|
{
|
||||||
|
idx = (l + u) / 2;
|
||||||
|
p = (void *) (((const char *) base) + (idx * size));
|
||||||
|
comparison = (*compar) (key, p);
|
||||||
|
if (comparison < 0)
|
||||||
|
u = idx;
|
||||||
|
else if (comparison > 0)
|
||||||
|
l = idx + 1;
|
||||||
|
else
|
||||||
|
return (void *) p;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
libc_hidden_def (bsearch)
|
||||||
@@ -0,0 +1,240 @@
|
|||||||
|
/* Return the canonical absolute name of a given file.
|
||||||
|
Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include <shlib-compat.h>
|
||||||
|
|
||||||
|
/* Return the canonical absolute name of file NAME. A canonical name
|
||||||
|
does not contain any `.', `..' components nor any repeated path
|
||||||
|
separators ('/') or symlinks. All path components must exist. If
|
||||||
|
RESOLVED is null, the result is malloc'd; otherwise, if the
|
||||||
|
canonical name is PATH_MAX chars or more, returns null with `errno'
|
||||||
|
set to ENAMETOOLONG; if the name fits in fewer than PATH_MAX chars,
|
||||||
|
returns the name in RESOLVED. If the name cannot be resolved and
|
||||||
|
RESOLVED is non-NULL, it contains the path of the first component
|
||||||
|
that cannot be resolved. If the path can be resolved, RESOLVED
|
||||||
|
holds the same value as the value returned. */
|
||||||
|
|
||||||
|
char *
|
||||||
|
__realpath (const char *name, char *resolved)
|
||||||
|
{
|
||||||
|
char *rpath, *dest, *extra_buf = NULL;
|
||||||
|
const char *start, *end, *rpath_limit;
|
||||||
|
long int path_max;
|
||||||
|
int num_links = 0;
|
||||||
|
|
||||||
|
if (name == NULL)
|
||||||
|
{
|
||||||
|
/* As per Single Unix Specification V2 we must return an error if
|
||||||
|
either parameter is a null pointer. We extend this to allow
|
||||||
|
the RESOLVED parameter to be NULL in case the we are expected to
|
||||||
|
allocate the room for the return value. */
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name[0] == '\0')
|
||||||
|
{
|
||||||
|
/* As per Single Unix Specification V2 we must return an error if
|
||||||
|
the name argument points to an empty string. */
|
||||||
|
__set_errno (ENOENT);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef PATH_MAX
|
||||||
|
path_max = PATH_MAX;
|
||||||
|
#else
|
||||||
|
path_max = pathconf (name, _PC_PATH_MAX);
|
||||||
|
if (path_max <= 0)
|
||||||
|
path_max = 1024;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (resolved == NULL)
|
||||||
|
{
|
||||||
|
rpath = malloc (path_max);
|
||||||
|
if (rpath == NULL)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
rpath = resolved;
|
||||||
|
rpath_limit = rpath + path_max;
|
||||||
|
|
||||||
|
if (name[0] != '/')
|
||||||
|
{
|
||||||
|
if (!__getcwd (rpath, path_max))
|
||||||
|
{
|
||||||
|
rpath[0] = '\0';
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
dest = strchr (rpath, '\0');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
rpath[0] = '/';
|
||||||
|
dest = rpath + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (start = end = name; *start; start = end)
|
||||||
|
{
|
||||||
|
struct stat64 st;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
/* Skip sequence of multiple path-separators. */
|
||||||
|
while (*start == '/')
|
||||||
|
++start;
|
||||||
|
|
||||||
|
/* Find end of path component. */
|
||||||
|
for (end = start; *end && *end != '/'; ++end)
|
||||||
|
/* Nothing. */;
|
||||||
|
|
||||||
|
if (end - start == 0)
|
||||||
|
break;
|
||||||
|
else if (end - start == 1 && start[0] == '.')
|
||||||
|
/* nothing */;
|
||||||
|
else if (end - start == 2 && start[0] == '.' && start[1] == '.')
|
||||||
|
{
|
||||||
|
/* Back up to previous component, ignore if at root already. */
|
||||||
|
if (dest > rpath + 1)
|
||||||
|
while ((--dest)[-1] != '/');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
size_t new_size;
|
||||||
|
|
||||||
|
if (dest[-1] != '/')
|
||||||
|
*dest++ = '/';
|
||||||
|
|
||||||
|
if (dest + (end - start) >= rpath_limit)
|
||||||
|
{
|
||||||
|
ptrdiff_t dest_offset = dest - rpath;
|
||||||
|
char *new_rpath;
|
||||||
|
|
||||||
|
if (resolved)
|
||||||
|
{
|
||||||
|
__set_errno (ENAMETOOLONG);
|
||||||
|
if (dest > rpath + 1)
|
||||||
|
dest--;
|
||||||
|
*dest = '\0';
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
new_size = rpath_limit - rpath;
|
||||||
|
if (end - start + 1 > path_max)
|
||||||
|
new_size += end - start + 1;
|
||||||
|
else
|
||||||
|
new_size += path_max;
|
||||||
|
new_rpath = (char *) realloc (rpath, new_size);
|
||||||
|
if (new_rpath == NULL)
|
||||||
|
goto error;
|
||||||
|
rpath = new_rpath;
|
||||||
|
rpath_limit = rpath + new_size;
|
||||||
|
|
||||||
|
dest = rpath + dest_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest = __mempcpy (dest, start, end - start);
|
||||||
|
*dest = '\0';
|
||||||
|
|
||||||
|
if (__lxstat64 (_STAT_VER, rpath, &st) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (S_ISLNK (st.st_mode))
|
||||||
|
{
|
||||||
|
char *buf = __alloca (path_max);
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (++num_links > MAXSYMLINKS)
|
||||||
|
{
|
||||||
|
__set_errno (ELOOP);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = __readlink (rpath, buf, path_max);
|
||||||
|
if (n < 0)
|
||||||
|
goto error;
|
||||||
|
buf[n] = '\0';
|
||||||
|
|
||||||
|
if (!extra_buf)
|
||||||
|
extra_buf = __alloca (path_max);
|
||||||
|
|
||||||
|
len = strlen (end);
|
||||||
|
if ((long int) (n + len) >= path_max)
|
||||||
|
{
|
||||||
|
__set_errno (ENAMETOOLONG);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Careful here, end may be a pointer into extra_buf... */
|
||||||
|
memmove (&extra_buf[n], end, len + 1);
|
||||||
|
name = end = memcpy (extra_buf, buf, n);
|
||||||
|
|
||||||
|
if (buf[0] == '/')
|
||||||
|
dest = rpath + 1; /* It's an absolute symlink */
|
||||||
|
else
|
||||||
|
/* Back up to previous component, ignore if at root already: */
|
||||||
|
if (dest > rpath + 1)
|
||||||
|
while ((--dest)[-1] != '/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dest > rpath + 1 && dest[-1] == '/')
|
||||||
|
--dest;
|
||||||
|
*dest = '\0';
|
||||||
|
|
||||||
|
return resolved ? memcpy (resolved, rpath, dest - rpath + 1) : rpath;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (resolved)
|
||||||
|
strcpy (resolved, rpath);
|
||||||
|
else
|
||||||
|
free (rpath);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
versioned_symbol (libc, __realpath, realpath, GLIBC_2_3);
|
||||||
|
|
||||||
|
|
||||||
|
#if SHLIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_3)
|
||||||
|
char *
|
||||||
|
__old_realpath (const char *name, char *resolved)
|
||||||
|
{
|
||||||
|
if (resolved == NULL)
|
||||||
|
{
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return __realpath (name, resolved);
|
||||||
|
}
|
||||||
|
compat_symbol (libc, __old_realpath, realpath, GLIBC_2_0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
__canonicalize_file_name (const char *name)
|
||||||
|
{
|
||||||
|
return __realpath (name, NULL);
|
||||||
|
}
|
||||||
|
weak_alias (__canonicalize_file_name, canonicalize_file_name)
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <bits/libc-lock.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "exit.h"
|
||||||
|
|
||||||
|
#undef __cxa_atexit
|
||||||
|
|
||||||
|
/* Register a function to be called by exit or when a shared library
|
||||||
|
is unloaded. This function is only called from code generated by
|
||||||
|
the C++ compiler. */
|
||||||
|
int
|
||||||
|
__cxa_atexit (void (*func) (void *), void *arg, void *d)
|
||||||
|
{
|
||||||
|
struct exit_function *new = __new_exitfn ();
|
||||||
|
|
||||||
|
if (new == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
new->flavor = ef_cxa;
|
||||||
|
new->func.cxa.fn = (void (*) (void *, int)) func;
|
||||||
|
new->func.cxa.arg = arg;
|
||||||
|
new->func.cxa.dso_handle = d;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
INTDEF(__cxa_atexit)
|
||||||
|
|
||||||
|
|
||||||
|
/* We change global data, so we need locking. */
|
||||||
|
__libc_lock_define_initialized (static, lock)
|
||||||
|
|
||||||
|
|
||||||
|
static struct exit_function_list initial;
|
||||||
|
struct exit_function_list *__exit_funcs = &initial;
|
||||||
|
|
||||||
|
struct exit_function *
|
||||||
|
__new_exitfn (void)
|
||||||
|
{
|
||||||
|
struct exit_function_list *l;
|
||||||
|
size_t i = 0;
|
||||||
|
|
||||||
|
__libc_lock_lock (lock);
|
||||||
|
|
||||||
|
for (l = __exit_funcs; l != NULL; l = l->next)
|
||||||
|
{
|
||||||
|
for (i = 0; i < l->idx; ++i)
|
||||||
|
if (l->fns[i].flavor == ef_free)
|
||||||
|
break;
|
||||||
|
if (i < l->idx)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (l->idx < sizeof (l->fns) / sizeof (l->fns[0]))
|
||||||
|
{
|
||||||
|
i = l->idx++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l == NULL)
|
||||||
|
{
|
||||||
|
l = (struct exit_function_list *)
|
||||||
|
malloc (sizeof (struct exit_function_list));
|
||||||
|
if (l != NULL)
|
||||||
|
{
|
||||||
|
l->next = __exit_funcs;
|
||||||
|
__exit_funcs = l;
|
||||||
|
|
||||||
|
l->idx = 1;
|
||||||
|
i = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Mark entry as used, but we don't know the flavor now. */
|
||||||
|
if (l != NULL)
|
||||||
|
l->fns[i].flavor = ef_us;
|
||||||
|
|
||||||
|
__libc_lock_unlock (lock);
|
||||||
|
|
||||||
|
return l == NULL ? NULL : &l->fns[i];
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/* Copyright (C) 1999, 2001, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <atomicity.h>
|
||||||
|
#include "exit.h"
|
||||||
|
#include <fork.h>
|
||||||
|
|
||||||
|
/* If D is non-NULL, call all functions registered with `__cxa_atexit'
|
||||||
|
with the same dso handle. Otherwise, if D is NULL, do nothing. */
|
||||||
|
void
|
||||||
|
__cxa_finalize (void *d)
|
||||||
|
{
|
||||||
|
struct exit_function_list *funcs;
|
||||||
|
|
||||||
|
for (funcs = __exit_funcs; funcs; funcs = funcs->next)
|
||||||
|
{
|
||||||
|
struct exit_function *f;
|
||||||
|
|
||||||
|
for (f = &funcs->fns[funcs->idx - 1]; f >= &funcs->fns[0]; --f)
|
||||||
|
if ((d == NULL || d == f->func.cxa.dso_handle)
|
||||||
|
/* We don't want to run this cleanup more than once. */
|
||||||
|
&& compare_and_swap (&f->flavor, ef_cxa, ef_free))
|
||||||
|
(*f->func.cxa.fn) (f->func.cxa.arg, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Remove the registered fork handlers. */
|
||||||
|
#ifdef UNREGISTER_ATFORK
|
||||||
|
UNREGISTER_ATFORK (d);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/* Global state for non-reentrant functions. */
|
||||||
|
struct drand48_data __libc_drand48_data;
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
__drand48_iterate (xsubi, buffer)
|
||||||
|
unsigned short int xsubi[3];
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
{
|
||||||
|
uint64_t X;
|
||||||
|
uint64_t result;
|
||||||
|
|
||||||
|
/* Initialize buffer, if not yet done. */
|
||||||
|
if (__builtin_expect (!buffer->__init, 0))
|
||||||
|
{
|
||||||
|
buffer->__a = 0x5deece66dull;
|
||||||
|
buffer->__c = 0xb;
|
||||||
|
buffer->__init = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do the real work. We choose a data type which contains at least
|
||||||
|
48 bits. Because we compute the modulus it does not care how
|
||||||
|
many bits really are computed. */
|
||||||
|
|
||||||
|
X = (uint64_t) xsubi[2] << 32 | (uint32_t) xsubi[1] << 16 | xsubi[0];
|
||||||
|
|
||||||
|
result = X * buffer->__a + buffer->__c;
|
||||||
|
|
||||||
|
xsubi[0] = result & 0xffff;
|
||||||
|
xsubi[1] = (result >> 16) & 0xffff;
|
||||||
|
xsubi[2] = (result >> 32) & 0xffff;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
drand48 ()
|
||||||
|
{
|
||||||
|
double result;
|
||||||
|
|
||||||
|
(void) __erand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 1997, 1998, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
drand48_r (buffer, result)
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
double *result;
|
||||||
|
{
|
||||||
|
return __erand48_r (buffer->__x, buffer, result);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
double
|
||||||
|
erand48 (xsubi)
|
||||||
|
unsigned short int xsubi[3];
|
||||||
|
{
|
||||||
|
double result;
|
||||||
|
|
||||||
|
(void) __erand48_r (xsubi, &__libc_drand48_data, &result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/* Copyright (C) 1995, 1997, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <ieee754.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
__erand48_r (xsubi, buffer, result)
|
||||||
|
unsigned short int xsubi[3];
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
double *result;
|
||||||
|
{
|
||||||
|
union ieee754_double temp;
|
||||||
|
|
||||||
|
/* Compute next state. */
|
||||||
|
if (__drand48_iterate (xsubi, buffer) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Construct a positive double with the 48 random bits distributed over
|
||||||
|
its fractional part so the resulting FP number is [0.0,1.0). */
|
||||||
|
|
||||||
|
temp.ieee.negative = 0;
|
||||||
|
temp.ieee.exponent = IEEE754_DOUBLE_BIAS;
|
||||||
|
temp.ieee.mantissa0 = (xsubi[2] << 4) | (xsubi[1] >> 12);
|
||||||
|
temp.ieee.mantissa1 = ((xsubi[1] & 0xfff) << 20) | (xsubi[0] << 4);
|
||||||
|
|
||||||
|
/* Please note the lower 4 bits of mantissa1 are always 0. */
|
||||||
|
*result = temp.d - 1.0;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
weak_alias (__erand48_r, erand48_r)
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/* Copyright (C) 1991,92,93,94,95,96,97,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ISO C99 Standard: 7.5 Errors <errno.h>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ERRNO_H
|
||||||
|
|
||||||
|
/* The includer defined __need_Emath if he wants only the definitions
|
||||||
|
of EDOM and ERANGE, and not everything else. */
|
||||||
|
#ifndef __need_Emath
|
||||||
|
# define _ERRNO_H 1
|
||||||
|
# include <features.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
/* Get the error number constants from the system-specific file.
|
||||||
|
This file will test __need_Emath and _ERRNO_H. */
|
||||||
|
#include <bits/errno.h>
|
||||||
|
#undef __need_Emath
|
||||||
|
|
||||||
|
#ifdef _ERRNO_H
|
||||||
|
|
||||||
|
/* Declare the `errno' variable, unless it's defined as a macro by
|
||||||
|
bits/errno.h. This is the case in GNU, where it is a per-thread
|
||||||
|
variable. This redeclaration using the macro still works, but it
|
||||||
|
will be a function declaration without a prototype and may trigger
|
||||||
|
a -Wstrict-prototypes warning. */
|
||||||
|
#ifndef errno
|
||||||
|
extern int errno;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __USE_GNU
|
||||||
|
|
||||||
|
/* The full and simple forms of the name with which the program was
|
||||||
|
invoked. These variables are set up automatically at startup based on
|
||||||
|
the value of ARGV[0] (this works only if you use GNU ld). */
|
||||||
|
extern char *program_invocation_name, *program_invocation_short_name;
|
||||||
|
#endif /* __USE_GNU */
|
||||||
|
#endif /* _ERRNO_H */
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* _ERRNO_H */
|
||||||
|
|
||||||
|
/* The Hurd <bits/errno.h> defines `error_t' as an enumerated type so
|
||||||
|
that printing `error_t' values in the debugger shows the names. We
|
||||||
|
might need this definition sometimes even if this file was included
|
||||||
|
before. */
|
||||||
|
#if defined __USE_GNU || defined __need_error_t
|
||||||
|
# ifndef __error_t_defined
|
||||||
|
typedef int error_t;
|
||||||
|
# define __error_t_defined 1
|
||||||
|
# endif
|
||||||
|
# undef __need_error_t
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/* Copyright (C) 1991,95,96,97,99,2001,02 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include "exit.h"
|
||||||
|
|
||||||
|
#ifdef HAVE_GNU_LD
|
||||||
|
#include "set-hooks.h"
|
||||||
|
DEFINE_HOOK (__libc_atexit, (void))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Call all functions registered with `atexit' and `on_exit',
|
||||||
|
in the reverse of the order in which they were registered
|
||||||
|
perform stdio cleanup, and terminate program execution with STATUS. */
|
||||||
|
void
|
||||||
|
exit (int status)
|
||||||
|
{
|
||||||
|
/* We do it this way to handle recursive calls to exit () made by
|
||||||
|
the functions registered with `atexit' and `on_exit'. We call
|
||||||
|
everyone on the list and use the status value in the last
|
||||||
|
exit (). */
|
||||||
|
while (__exit_funcs != NULL)
|
||||||
|
{
|
||||||
|
struct exit_function_list *old;
|
||||||
|
|
||||||
|
while (__exit_funcs->idx > 0)
|
||||||
|
{
|
||||||
|
const struct exit_function *const f =
|
||||||
|
&__exit_funcs->fns[--__exit_funcs->idx];
|
||||||
|
switch (f->flavor)
|
||||||
|
{
|
||||||
|
case ef_free:
|
||||||
|
case ef_us:
|
||||||
|
break;
|
||||||
|
case ef_on:
|
||||||
|
(*f->func.on.fn) (status, f->func.on.arg);
|
||||||
|
break;
|
||||||
|
case ef_at:
|
||||||
|
(*f->func.at) ();
|
||||||
|
break;
|
||||||
|
case ef_cxa:
|
||||||
|
(*f->func.cxa.fn) (f->func.cxa.arg, status);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
old = __exit_funcs;
|
||||||
|
__exit_funcs = __exit_funcs->next;
|
||||||
|
if (__exit_funcs != NULL)
|
||||||
|
/* Don't free the last element in the chain, this is the statically
|
||||||
|
allocate element. */
|
||||||
|
free (old);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_GNU_LD
|
||||||
|
RUN_HOOK (__libc_atexit, ());
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
extern void _cleanup (void);
|
||||||
|
_cleanup ();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
_exit (status);
|
||||||
|
}
|
||||||
|
libc_hidden_def (exit)
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/* Copyright (C) 1991,1996,1997,1999,2001,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef _EXIT_H
|
||||||
|
#define _EXIT_H 1
|
||||||
|
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
ef_free, /* `ef_free' MUST be zero! */
|
||||||
|
ef_us,
|
||||||
|
ef_on,
|
||||||
|
ef_at,
|
||||||
|
ef_cxa
|
||||||
|
};
|
||||||
|
|
||||||
|
struct exit_function
|
||||||
|
{
|
||||||
|
/* `flavour' should be of type of the `enum' above but since we need
|
||||||
|
this element in an atomic operation we have to use `long int'. */
|
||||||
|
long int flavor;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
void (*at) (void);
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
void (*fn) (int status, void *arg);
|
||||||
|
void *arg;
|
||||||
|
} on;
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
void (*fn) (void *arg, int status);
|
||||||
|
void *arg;
|
||||||
|
void *dso_handle;
|
||||||
|
} cxa;
|
||||||
|
} func;
|
||||||
|
};
|
||||||
|
struct exit_function_list
|
||||||
|
{
|
||||||
|
struct exit_function_list *next;
|
||||||
|
size_t idx;
|
||||||
|
struct exit_function fns[32];
|
||||||
|
};
|
||||||
|
extern struct exit_function_list *__exit_funcs attribute_hidden;
|
||||||
|
|
||||||
|
extern struct exit_function *__new_exitfn (void);
|
||||||
|
|
||||||
|
#endif /* exit.h */
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
/* Copyright (C) 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <[email protected]>, 1997.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <fmtmsg.h>
|
||||||
|
#include <bits/libc-lock.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/syslog.h>
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
# include <wchar.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* We have global data, protect the modification. */
|
||||||
|
__libc_lock_define_initialized (static, lock)
|
||||||
|
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
label_mask = 0x01,
|
||||||
|
severity_mask = 0x02,
|
||||||
|
text_mask = 0x04,
|
||||||
|
action_mask = 0x08,
|
||||||
|
tag_mask = 0x10,
|
||||||
|
all_mask = label_mask | severity_mask | text_mask | action_mask | tag_mask
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
/* Adjust the size if new elements are added. */
|
||||||
|
const char name[12];
|
||||||
|
} keywords[] =
|
||||||
|
{
|
||||||
|
{ 5, "label" },
|
||||||
|
{ 8, "severity" },
|
||||||
|
{ 4, "text" },
|
||||||
|
{ 6, "action"},
|
||||||
|
{ 3, "tag" }
|
||||||
|
};
|
||||||
|
#define NKEYWORDS (sizeof( keywords) / sizeof (keywords[0]))
|
||||||
|
|
||||||
|
|
||||||
|
struct severity_info
|
||||||
|
{
|
||||||
|
int severity;
|
||||||
|
const char *string;
|
||||||
|
struct severity_info *next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* List of known severities. */
|
||||||
|
static const struct severity_info nosev =
|
||||||
|
{
|
||||||
|
MM_NOSEV, "", NULL
|
||||||
|
};
|
||||||
|
static const struct severity_info haltsev =
|
||||||
|
{
|
||||||
|
MM_HALT, "HALT", (struct severity_info *) &nosev
|
||||||
|
};
|
||||||
|
static const struct severity_info errorsev =
|
||||||
|
{
|
||||||
|
MM_ERROR, "ERROR", (struct severity_info *) &haltsev
|
||||||
|
};
|
||||||
|
static const struct severity_info warningsev =
|
||||||
|
{
|
||||||
|
MM_WARNING, "WARNING", (struct severity_info *) &errorsev
|
||||||
|
};
|
||||||
|
static const struct severity_info infosev =
|
||||||
|
{
|
||||||
|
MM_INFO, "INFO", (struct severity_info *) &warningsev
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Start of the list. */
|
||||||
|
static struct severity_info *severity_list = (struct severity_info *) &infosev;
|
||||||
|
|
||||||
|
/* Mask of values we will print. */
|
||||||
|
static int print;
|
||||||
|
|
||||||
|
/* Prototypes for local functions. */
|
||||||
|
static void init (void);
|
||||||
|
static int internal_addseverity (int severity, const char *string)
|
||||||
|
internal_function;
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
fmtmsg (long int classification, const char *label, int severity,
|
||||||
|
const char *text, const char *action, const char *tag)
|
||||||
|
{
|
||||||
|
__libc_once_define (static, once);
|
||||||
|
int result = MM_OK;
|
||||||
|
struct severity_info *severity_rec;
|
||||||
|
|
||||||
|
/* make sure everything is initialized. */
|
||||||
|
__libc_once (once, init);
|
||||||
|
|
||||||
|
/* Start the real work. First check whether the input is ok. */
|
||||||
|
if (label != MM_NULLLBL)
|
||||||
|
{
|
||||||
|
/* Must be two fields, separated by a colon. */
|
||||||
|
const char *cp = strchr (label, ':');
|
||||||
|
if (cp == NULL)
|
||||||
|
return MM_NOTOK;
|
||||||
|
|
||||||
|
/* The first field must not contain more then 10 bytes. */
|
||||||
|
if (cp - label > 10
|
||||||
|
/* The second field must not have more then 14 bytes. */
|
||||||
|
|| strlen (cp + 1) > 14)
|
||||||
|
return MM_NOTOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (severity_rec = severity_list; severity_rec != NULL;
|
||||||
|
severity_rec = severity_rec->next)
|
||||||
|
if (severity == severity_rec->severity)
|
||||||
|
/* Bingo. */
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* If we don't know anything about the severity level return an error. */
|
||||||
|
if (severity_rec == NULL)
|
||||||
|
return MM_NOTOK;
|
||||||
|
|
||||||
|
|
||||||
|
/* Now we can print. */
|
||||||
|
if (classification & MM_PRINT)
|
||||||
|
{
|
||||||
|
int do_label = (print & label_mask) && label != MM_NULLLBL;
|
||||||
|
int do_severity = (print & severity_mask) && severity != MM_NULLSEV;
|
||||||
|
int do_text = (print & text_mask) && text != MM_NULLTXT;
|
||||||
|
int do_action = (print & action_mask) && action != MM_NULLACT;
|
||||||
|
int do_tag = (print & tag_mask) && tag != MM_NULLTAG;
|
||||||
|
|
||||||
|
#ifdef USE_IN_LIBIO
|
||||||
|
if (_IO_fwide (stderr, 0) > 0)
|
||||||
|
{
|
||||||
|
if (__fwprintf (stderr, L"%s%s%s%s%s%s%s%s%s%s\n",
|
||||||
|
do_label ? label : "",
|
||||||
|
do_label
|
||||||
|
&& (do_severity | do_text | do_action | do_tag)
|
||||||
|
? ": " : "",
|
||||||
|
do_severity ? severity_rec->string : "",
|
||||||
|
do_severity && (do_text | do_action | do_tag)
|
||||||
|
? ": " : "",
|
||||||
|
do_text ? text : "",
|
||||||
|
do_text && (do_action | do_tag) ? "\n" : "",
|
||||||
|
do_action ? "TO FIX: " : "",
|
||||||
|
do_action ? action : "",
|
||||||
|
do_action && do_tag ? " " : "",
|
||||||
|
do_tag ? tag : "") < 0)
|
||||||
|
/* Oh, oh. An error occurred during the output. */
|
||||||
|
result = MM_NOMSG;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
if (fprintf (stderr, "%s%s%s%s%s%s%s%s%s%s\n",
|
||||||
|
do_label ? label : "",
|
||||||
|
do_label && (do_severity | do_text | do_action | do_tag)
|
||||||
|
? ": " : "",
|
||||||
|
do_severity ? severity_rec->string : "",
|
||||||
|
do_severity && (do_text | do_action | do_tag) ? ": " : "",
|
||||||
|
do_text ? text : "",
|
||||||
|
do_text && (do_action | do_tag) ? "\n" : "",
|
||||||
|
do_action ? "TO FIX: " : "",
|
||||||
|
do_action ? action : "",
|
||||||
|
do_action && do_tag ? " " : "",
|
||||||
|
do_tag ? tag : "") < 0)
|
||||||
|
/* Oh, oh. An error occurred during the output. */
|
||||||
|
result = MM_NOMSG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (classification & MM_CONSOLE)
|
||||||
|
{
|
||||||
|
int do_label = label != MM_NULLLBL;
|
||||||
|
int do_severity = severity != MM_NULLSEV;
|
||||||
|
int do_text = text != MM_NULLTXT;
|
||||||
|
int do_action = action != MM_NULLACT;
|
||||||
|
int do_tag = tag != MM_NULLTAG;
|
||||||
|
|
||||||
|
syslog (LOG_ERR, "%s%s%s%s%s%s%s%s%s%s\n",
|
||||||
|
do_label ? label : "",
|
||||||
|
do_label && (do_severity | do_text | do_action | do_tag)
|
||||||
|
? ": " : "",
|
||||||
|
do_severity ? severity_rec->string : "",
|
||||||
|
do_severity && (do_text | do_action | do_tag) ? ": " : "",
|
||||||
|
do_text ? text : "",
|
||||||
|
do_text && (do_action | do_tag) ? "\n" : "",
|
||||||
|
do_action ? "TO FIX: " : "",
|
||||||
|
do_action ? action : "",
|
||||||
|
do_action && do_tag ? " " : "",
|
||||||
|
do_tag ? tag : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize from environment variable content. */
|
||||||
|
static void
|
||||||
|
init (void)
|
||||||
|
{
|
||||||
|
const char *msgverb_var = getenv ("MSGVERB");
|
||||||
|
const char *sevlevel_var = getenv ("SEV_LEVEL");
|
||||||
|
|
||||||
|
if (msgverb_var != NULL && msgverb_var[0] != '\0')
|
||||||
|
{
|
||||||
|
/* Using this extra variable allows us to work without locking. */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
size_t cnt;
|
||||||
|
|
||||||
|
for (cnt = 0; cnt < NKEYWORDS; ++cnt)
|
||||||
|
if (memcmp (msgverb_var,
|
||||||
|
keywords[cnt].name, keywords[cnt].len) == 0
|
||||||
|
&& (msgverb_var[keywords[cnt].len] == ':'
|
||||||
|
|| msgverb_var[keywords[cnt].len] == '\0'))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (cnt < NKEYWORDS)
|
||||||
|
{
|
||||||
|
print |= 1 << cnt;
|
||||||
|
|
||||||
|
msgverb_var += keywords[cnt].len;
|
||||||
|
if (msgverb_var[0] == ':')
|
||||||
|
++msgverb_var;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* We found an illegal keyword in the environment
|
||||||
|
variable. The specifications say that we print all
|
||||||
|
fields. */
|
||||||
|
print = all_mask;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (msgverb_var[0] != '\0');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
print = all_mask;
|
||||||
|
|
||||||
|
|
||||||
|
if (sevlevel_var != NULL)
|
||||||
|
{
|
||||||
|
__libc_lock_lock (lock);
|
||||||
|
|
||||||
|
while (sevlevel_var[0] != '\0')
|
||||||
|
{
|
||||||
|
const char *end = __strchrnul (sevlevel_var, ':');
|
||||||
|
int level;
|
||||||
|
|
||||||
|
/* First field: keyword. This is not used here but it must be
|
||||||
|
present. */
|
||||||
|
while (sevlevel_var < end)
|
||||||
|
if (*sevlevel_var++ == ',')
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (sevlevel_var < end)
|
||||||
|
{
|
||||||
|
/* Second field: severity level, a number. */
|
||||||
|
char *cp;
|
||||||
|
|
||||||
|
level = strtol (sevlevel_var, &cp, 0);
|
||||||
|
if (cp != sevlevel_var && cp < end && *cp++ == ','
|
||||||
|
&& level > MM_INFO)
|
||||||
|
{
|
||||||
|
const char *new_string;
|
||||||
|
|
||||||
|
new_string = __strndup (cp, end - cp);
|
||||||
|
|
||||||
|
if (new_string != NULL
|
||||||
|
&& (internal_addseverity (level, new_string)
|
||||||
|
!= MM_OK))
|
||||||
|
free ((char *) new_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sevlevel_var = end + (*end == ':' ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Add the new entry to the list. */
|
||||||
|
static int
|
||||||
|
internal_function
|
||||||
|
internal_addseverity (int severity, const char *string)
|
||||||
|
{
|
||||||
|
struct severity_info *runp, *lastp;
|
||||||
|
int result = MM_OK;
|
||||||
|
|
||||||
|
/* First see if there is already a record for the severity level. */
|
||||||
|
for (runp = severity_list, lastp = NULL; runp != NULL; runp = runp-> next)
|
||||||
|
if (runp->severity == severity)
|
||||||
|
break;
|
||||||
|
else
|
||||||
|
lastp = runp;
|
||||||
|
|
||||||
|
if (runp != NULL)
|
||||||
|
{
|
||||||
|
/* Release old string. */
|
||||||
|
free ((char *) runp->string);
|
||||||
|
|
||||||
|
if (string != NULL)
|
||||||
|
/* Change the string. */
|
||||||
|
runp->string = string;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Remove the severity class. */
|
||||||
|
if (lastp == NULL)
|
||||||
|
severity_list = runp->next;
|
||||||
|
else
|
||||||
|
lastp->next = runp->next;
|
||||||
|
|
||||||
|
free (runp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (string != NULL)
|
||||||
|
{
|
||||||
|
runp = malloc (sizeof (*runp));
|
||||||
|
if (runp == NULL)
|
||||||
|
result = MM_NOTOK;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
runp->severity = severity;
|
||||||
|
runp->next = severity_list;
|
||||||
|
runp->string = string;
|
||||||
|
severity_list = runp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
/* We tried to remove a non-existing severity class. */
|
||||||
|
result = MM_NOTOK;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Add new severity level or remove old one. */
|
||||||
|
int
|
||||||
|
addseverity (int severity, const char *string)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
const char *new_string;
|
||||||
|
|
||||||
|
/* Prevent illegal SEVERITY values. */
|
||||||
|
if (severity <= MM_INFO)
|
||||||
|
return MM_NOTOK;
|
||||||
|
|
||||||
|
if (string == NULL)
|
||||||
|
/* We want to remove the severity class. */
|
||||||
|
new_string = NULL;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
new_string = __strdup (string);
|
||||||
|
|
||||||
|
if (new_string == NULL)
|
||||||
|
/* Allocation failed or illegal value. */
|
||||||
|
return MM_NOTOK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Protect the global data. */
|
||||||
|
__libc_lock_lock (lock);
|
||||||
|
|
||||||
|
/* Do the real work. */
|
||||||
|
result = internal_addseverity (severity, string);
|
||||||
|
|
||||||
|
if (result != MM_OK)
|
||||||
|
/* Free the allocated string. */
|
||||||
|
free ((char *) new_string);
|
||||||
|
|
||||||
|
/* Release the lock. */
|
||||||
|
__libc_lock_unlock (lock);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
libc_freeres_fn (free_mem)
|
||||||
|
{
|
||||||
|
struct severity_info *runp = severity_list;
|
||||||
|
|
||||||
|
while (runp != NULL)
|
||||||
|
if (runp->severity > MM_INFO)
|
||||||
|
{
|
||||||
|
/* This is data we have to release. */
|
||||||
|
struct severity_info *here = runp;
|
||||||
|
free ((char *) runp->string);
|
||||||
|
runp = runp->next;
|
||||||
|
free (here);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
runp = runp->next;
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/* Message display handling.
|
||||||
|
Copyright (C) 1997, 1999, 2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef __FMTMSG_H
|
||||||
|
#define __FMTMSG_H 1
|
||||||
|
|
||||||
|
#include <features.h>
|
||||||
|
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
/* Values to control `fmtmsg' function. */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MM_HARD = 0x001, /* Source of the condition is hardware. */
|
||||||
|
#define MM_HARD MM_HARD
|
||||||
|
MM_SOFT = 0x002, /* Source of the condition is software. */
|
||||||
|
#define MM_SOFT MM_SOFT
|
||||||
|
MM_FIRM = 0x004, /* Source of the condition is firmware. */
|
||||||
|
#define MM_FIRM MM_FIRM
|
||||||
|
MM_APPL = 0x008, /* Condition detected by application. */
|
||||||
|
#define MM_APPL MM_APPL
|
||||||
|
MM_UTIL = 0x010, /* Condition detected by utility. */
|
||||||
|
#define MM_UTIL MM_UTIL
|
||||||
|
MM_OPSYS = 0x020, /* Condition detected by operating system. */
|
||||||
|
#define MM_OPSYS MM_OPSYS
|
||||||
|
MM_RECOVER = 0x040, /* Recoverable error. */
|
||||||
|
#define MM_RECOVER MM_RECOVER
|
||||||
|
MM_NRECOV = 0x080, /* Non-recoverable error. */
|
||||||
|
#define MM_NRECOV MM_NRECOV
|
||||||
|
MM_PRINT = 0x100, /* Display message in standard error. */
|
||||||
|
#define MM_PRINT MM_PRINT
|
||||||
|
MM_CONSOLE = 0x200 /* Display message on system console. */
|
||||||
|
#define MM_CONSOLE MM_CONSOLE
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Values to be for SEVERITY parameter of `fmtmsg'. */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MM_NOSEV = 0, /* No severity level provided for the message. */
|
||||||
|
#define MM_NOSEV MM_NOSEV
|
||||||
|
MM_HALT, /* Error causing application to halt. */
|
||||||
|
#define MM_HALT MM_HALT
|
||||||
|
MM_ERROR, /* Application has encountered a non-fatal fault. */
|
||||||
|
#define MM_ERROR MM_ERROR
|
||||||
|
MM_WARNING, /* Application has detected unusual non-error
|
||||||
|
condition. */
|
||||||
|
#define MM_WARNING MM_WARNING
|
||||||
|
MM_INFO /* Informative message. */
|
||||||
|
#define MM_INFO MM_INFO
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Macros which can be used as null values for the arguments of `fmtmsg'. */
|
||||||
|
#define MM_NULLLBL ((char *) 0)
|
||||||
|
#define MM_NULLSEV 0
|
||||||
|
#define MM_NULLMC ((long int) 0)
|
||||||
|
#define MM_NULLTXT ((char *) 0)
|
||||||
|
#define MM_NULLACT ((char *) 0)
|
||||||
|
#define MM_NULLTAG ((char *) 0)
|
||||||
|
|
||||||
|
|
||||||
|
/* Possible return values of `fmtmsg'. */
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MM_NOTOK = -1,
|
||||||
|
#define MM_NOTOK MM_NOTOK
|
||||||
|
MM_OK = 0,
|
||||||
|
#define MM_OK MM_OK
|
||||||
|
MM_NOMSG = 1,
|
||||||
|
#define MM_NOMSG MM_NOMSG
|
||||||
|
MM_NOCON = 4
|
||||||
|
#define MM_NOCON MM_NOCON
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* Print message with given CLASSIFICATION, LABEL, SEVERITY, TEXT, ACTION
|
||||||
|
and TAG to console or standard error. */
|
||||||
|
extern int fmtmsg (long int __classification, __const char *__label,
|
||||||
|
int __severity, __const char *__text,
|
||||||
|
__const char *__action, __const char *__tag) __THROW;
|
||||||
|
|
||||||
|
#ifdef __USE_SVID
|
||||||
|
/* Add or remove severity level. */
|
||||||
|
extern int addseverity (int __severity, __const char *__string) __THROW;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* fmtmsg.h */
|
||||||
@@ -0,0 +1,462 @@
|
|||||||
|
/* Table of MP integer constants 10^(2^i), used for floating point <-> decimal.
|
||||||
|
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2002, 2003
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include "fpioconst.h"
|
||||||
|
#include <gmp-mparam.h> /* This defines BITS_PER_MP_LIMB. */
|
||||||
|
|
||||||
|
/* First page : 32-bit limbs
|
||||||
|
Second page : 64-bit limbs
|
||||||
|
Last page : table of pointers
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if BITS_PER_MP_LIMB == 32
|
||||||
|
|
||||||
|
/* Table with constants of 10^(2^i), i=0..12 for 32-bit limbs. */
|
||||||
|
|
||||||
|
const mp_limb_t __tens[] =
|
||||||
|
{
|
||||||
|
#define TENS_P0_IDX 0
|
||||||
|
#define TENS_P0_SIZE 3
|
||||||
|
[TENS_P0_IDX] = 0x00000000, 0x00000000, 0x0000000a,
|
||||||
|
|
||||||
|
#define TENS_P1_IDX (TENS_P0_IDX + TENS_P0_SIZE)
|
||||||
|
#define TENS_P1_SIZE 3
|
||||||
|
[TENS_P1_IDX] = 0x00000000, 0x00000000, 0x00000064,
|
||||||
|
|
||||||
|
#define TENS_P2_IDX (TENS_P1_IDX + TENS_P1_SIZE)
|
||||||
|
#define TENS_P2_SIZE 3
|
||||||
|
[TENS_P2_IDX] = 0x00000000, 0x00000000, 0x00002710,
|
||||||
|
|
||||||
|
#define TENS_P3_IDX (TENS_P2_IDX + TENS_P2_SIZE)
|
||||||
|
#define TENS_P3_SIZE 3
|
||||||
|
[TENS_P3_IDX] = 0x00000000, 0x00000000, 0x05f5e100,
|
||||||
|
|
||||||
|
#define TENS_P4_IDX (TENS_P3_IDX + TENS_P3_SIZE)
|
||||||
|
#define TENS_P4_SIZE 4
|
||||||
|
[TENS_P4_IDX] = 0x00000000, 0x00000000, 0x6fc10000, 0x002386f2,
|
||||||
|
|
||||||
|
#define TENS_P5_IDX (TENS_P4_IDX + TENS_P4_SIZE)
|
||||||
|
#define TENS_P5_SIZE 6
|
||||||
|
[TENS_P5_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x85acef81, 0x2d6d415b,
|
||||||
|
0x000004ee,
|
||||||
|
|
||||||
|
#define TENS_P6_IDX (TENS_P5_IDX + TENS_P5_SIZE)
|
||||||
|
#define TENS_P6_SIZE 9
|
||||||
|
[TENS_P6_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0xbf6a1f01,
|
||||||
|
0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x00184f03,
|
||||||
|
|
||||||
|
#define TENS_P7_IDX (TENS_P6_IDX + TENS_P6_SIZE)
|
||||||
|
#define TENS_P7_SIZE 16
|
||||||
|
[TENS_P7_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x2e953e01, 0x03df9909, 0x0f1538fd, 0x2374e42f, 0xd3cff5ec,
|
||||||
|
0xc404dc08, 0xbccdb0da, 0xa6337f19, 0xe91f2603, 0x0000024e,
|
||||||
|
|
||||||
|
#define TENS_P8_IDX (TENS_P7_IDX + TENS_P7_SIZE)
|
||||||
|
#define TENS_P8_SIZE 29
|
||||||
|
[TENS_P8_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x982e7c01,
|
||||||
|
0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6, 0xcf4a6e70, 0xd595d80f,
|
||||||
|
0x26b2716e, 0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e, 0xcc5573c0,
|
||||||
|
0x65f9ef17, 0x55bc28f2, 0x80dcc7f7, 0xf46eeddc, 0x5fdcefce, 0x000553f7,
|
||||||
|
|
||||||
|
#ifndef __NO_LONG_DOUBLE_MATH
|
||||||
|
# define TENS_P9_IDX (TENS_P8_IDX + TENS_P8_SIZE)
|
||||||
|
# define TENS_P9_SIZE 56
|
||||||
|
[TENS_P9_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0xfc6cf801, 0x77f27267, 0x8f9546dc, 0x5d96976f, 0xb83a8a97,
|
||||||
|
0xc31e1ad9, 0x46c40513, 0x94e65747, 0xc88976c1, 0x4475b579, 0x28f8733b,
|
||||||
|
0xaa1da1bf, 0x703ed321, 0x1e25cfea, 0xb21a2f22, 0xbc51fb2e, 0x96e14f5d,
|
||||||
|
0xbfa3edac, 0x329c57ae, 0xe7fc7153, 0xc3fc0695, 0x85a91924, 0xf95f635e,
|
||||||
|
0xb2908ee0, 0x93abade4, 0x1366732a, 0x9449775c, 0x69be5b0e, 0x7343afac,
|
||||||
|
0xb099bc81, 0x45a71d46, 0xa2699748, 0x8cb07303, 0x8a0b1f13, 0x8cab8a97,
|
||||||
|
0xc1d238d9, 0x633415d4, 0x0000001c,
|
||||||
|
|
||||||
|
# define TENS_P10_IDX (TENS_P9_IDX + TENS_P9_SIZE)
|
||||||
|
# define TENS_P10_SIZE 109
|
||||||
|
[TENS_P10_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x2919f001,
|
||||||
|
0xf55b2b72, 0x6e7c215b, 0x1ec29f86, 0x991c4e87, 0x15c51a88, 0x140ac535,
|
||||||
|
0x4c7d1e1a, 0xcc2cd819, 0x0ed1440e, 0x896634ee, 0x7de16cfb, 0x1e43f61f,
|
||||||
|
0x9fce837d, 0x231d2b9c, 0x233e55c7, 0x65dc60d7, 0xf451218b, 0x1c5cd134,
|
||||||
|
0xc9635986, 0x922bbb9f, 0xa7e89431, 0x9f9f2a07, 0x62be695a, 0x8e1042c4,
|
||||||
|
0x045b7a74, 0x1abe1de3, 0x8ad822a5, 0xba34c411, 0xd814b505, 0xbf3fdeb3,
|
||||||
|
0x8fc51a16, 0xb1b896bc, 0xf56deeec, 0x31fb6bfd, 0xb6f4654b, 0x101a3616,
|
||||||
|
0x6b7595fb, 0xdc1a47fe, 0x80d98089, 0x80bda5a5, 0x9a202882, 0x31eb0f66,
|
||||||
|
0xfc8f1f90, 0x976a3310, 0xe26a7b7e, 0xdf68368a, 0x3ce3a0b8, 0x8e4262ce,
|
||||||
|
0x75a351a2, 0x6cb0b6c9, 0x44597583, 0x31b5653f, 0xc356e38a, 0x35faaba6,
|
||||||
|
0x0190fba0, 0x9fc4ed52, 0x88bc491b, 0x1640114a, 0x005b8041, 0xf4f3235e,
|
||||||
|
0x1e8d4649, 0x36a8de06, 0x73c55349, 0xa7e6bd2a, 0xc1a6970c, 0x47187094,
|
||||||
|
0xd2db49ef, 0x926c3f5b, 0xae6209d4, 0x2d433949, 0x34f4a3c6, 0xd4305d94,
|
||||||
|
0xd9d61a05, 0x00000325,
|
||||||
|
|
||||||
|
# define TENS_P11_IDX (TENS_P10_IDX + TENS_P10_SIZE)
|
||||||
|
# define TENS_P11_SIZE 215
|
||||||
|
[TENS_P11_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x1333e001, 0xe3096865, 0xb27d4d3f, 0x49e28dcf, 0xec2e4721,
|
||||||
|
0xee87e354, 0xb6067584, 0x368b8abb, 0xa5e5a191, 0x2ed56d55, 0xfd827773,
|
||||||
|
0xea50d142, 0x51b78db2, 0x98342c9e, 0xc850dabc, 0x866ed6f1, 0x19342c12,
|
||||||
|
0x92794987, 0xd2f869c2, 0x66912e4a, 0x71c7fd8f, 0x57a7842d, 0x235552eb,
|
||||||
|
0xfb7fedcc, 0xf3861ce0, 0x38209ce1, 0x9713b449, 0x34c10134, 0x8c6c54de,
|
||||||
|
0xa7a8289c, 0x2dbb6643, 0xe3cb64f3, 0x8074ff01, 0xe3892ee9, 0x10c17f94,
|
||||||
|
0xa8f16f92, 0xa8281ed6, 0x967abbb3, 0x5a151440, 0x9952fbed, 0x13b41e44,
|
||||||
|
0xafe609c3, 0xa2bca416, 0xf111821f, 0xfb1264b4, 0x91bac974, 0xd6c7d6ab,
|
||||||
|
0x8e48ff35, 0x4419bd43, 0xc4a65665, 0x685e5510, 0x33554c36, 0xab498697,
|
||||||
|
0x0dbd21fe, 0x3cfe491d, 0x982da466, 0xcbea4ca7, 0x9e110c7b, 0x79c56b8a,
|
||||||
|
0x5fc5a047, 0x84d80e2e, 0x1aa9f444, 0x730f203c, 0x6a57b1ab, 0xd752f7a6,
|
||||||
|
0x87a7dc62, 0x944545ff, 0x40660460, 0x77c1a42f, 0xc9ac375d, 0xe866d7ef,
|
||||||
|
0x744695f0, 0x81428c85, 0xa1fc6b96, 0xd7917c7b, 0x7bf03c19, 0x5b33eb41,
|
||||||
|
0x5715f791, 0x8f6cae5f, 0xdb0708fd, 0xb125ac8e, 0x785ce6b7, 0x56c6815b,
|
||||||
|
0x6f46eadb, 0x4eeebeee, 0x195355d8, 0xa244de3c, 0x9d7389c0, 0x53761abd,
|
||||||
|
0xcf99d019, 0xde9ec24b, 0x0d76ce39, 0x70beb181, 0x2e55ecee, 0xd5f86079,
|
||||||
|
0xf56d9d4b, 0xfb8886fb, 0x13ef5a83, 0x408f43c5, 0x3f3389a4, 0xfad37943,
|
||||||
|
0x58ccf45c, 0xf82df846, 0x415c7f3e, 0x2915e818, 0x8b3d5cf4, 0x6a445f27,
|
||||||
|
0xf8dbb57a, 0xca8f0070, 0x8ad803ec, 0xb2e87c34, 0x038f9245, 0xbedd8a6c,
|
||||||
|
0xc7c9dee0, 0x0eac7d56, 0x2ad3fa14, 0xe0de0840, 0xf775677c, 0xf1bd0ad5,
|
||||||
|
0x92be221e, 0x87fa1fb9, 0xce9d04a4, 0xd2c36fa9, 0x3f6f7024, 0xb028af62,
|
||||||
|
0x907855ee, 0xd83e49d6, 0x4efac5dc, 0xe7151aab, 0x77cd8c6b, 0x0a753b7d,
|
||||||
|
0x0af908b4, 0x8c983623, 0xe50f3027, 0x94222771, 0x1d08e2d6, 0xf7e928e6,
|
||||||
|
0xf2ee5ca6, 0x1b61b93c, 0x11eb962b, 0x9648b21c, 0xce2bcba1, 0x34f77154,
|
||||||
|
0x7bbebe30, 0xe526a319, 0x8ce329ac, 0xde4a74d2, 0xb5dc53d5, 0x0009e8b3,
|
||||||
|
|
||||||
|
# define TENS_P12_IDX (TENS_P11_IDX + TENS_P11_SIZE)
|
||||||
|
# define TENS_P12_SIZE 428
|
||||||
|
[TENS_P12_IDX] = 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
|
||||||
|
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x2a67c001,
|
||||||
|
0xd4724e8d, 0x8efe7ae7, 0xf89a1e90, 0xef084117, 0x54e05154, 0x13b1bb51,
|
||||||
|
0x506be829, 0xfb29b172, 0xe599574e, 0xf0da6146, 0x806c0ed3, 0xb86ae5be,
|
||||||
|
0x45155e93, 0xc0591cc2, 0x7e1e7c34, 0x7c4823da, 0x1d1f4cce, 0x9b8ba1e8,
|
||||||
|
0xd6bfdf75, 0xe341be10, 0xc2dfae78, 0x016b67b2, 0x0f237f1a, 0x3dbeabcd,
|
||||||
|
0xaf6a2574, 0xcab3e6d7, 0x142e0e80, 0x61959127, 0x2c234811, 0x87009701,
|
||||||
|
0xcb4bf982, 0xf8169c84, 0x88052f8c, 0x68dde6d4, 0xbc131761, 0xff0b0905,
|
||||||
|
0x54ab9c41, 0x7613b224, 0x1a1c304e, 0x3bfe167b, 0x441c2d47, 0x4f6cea9c,
|
||||||
|
0x78f06181, 0xeb659fb8, 0x30c7ae41, 0x947e0d0e, 0xa1ebcad7, 0xd97d9556,
|
||||||
|
0x2130504d, 0x1a8309cb, 0xf2acd507, 0x3f8ec72a, 0xfd82373a, 0x95a842bc,
|
||||||
|
0x280f4d32, 0xf3618ac0, 0x811a4f04, 0x6dc3a5b4, 0xd3967a1b, 0x15b8c898,
|
||||||
|
0xdcfe388f, 0x454eb2a0, 0x8738b909, 0x10c4e996, 0x2bd9cc11, 0x3297cd0c,
|
||||||
|
0x655fec30, 0xae0725b1, 0xf4090ee8, 0x037d19ee, 0x398c6fed, 0x3b9af26b,
|
||||||
|
0xc994a450, 0xb5341743, 0x75a697b2, 0xac50b9c1, 0x3ccb5b92, 0xffe06205,
|
||||||
|
0xa8329761, 0xdfea5242, 0xeb83cadb, 0xe79dadf7, 0x3c20ee69, 0x1e0a6817,
|
||||||
|
0x7021b97a, 0x743074fa, 0x176ca776, 0x77fb8af6, 0xeca19beb, 0x92baf1de,
|
||||||
|
0xaf63b712, 0xde35c88b, 0xa4eb8f8c, 0xe137d5e9, 0x40b464a0, 0x87d1cde8,
|
||||||
|
0x42923bbd, 0xcd8f62ff, 0x2e2690f3, 0x095edc16, 0x59c89f1b, 0x1fa8fd5d,
|
||||||
|
0x5138753d, 0x390a2b29, 0x80152f18, 0x2dd8d925, 0xf984d83e, 0x7a872e74,
|
||||||
|
0xc19e1faf, 0xed4d542d, 0xecf9b5d0, 0x9462ea75, 0xc53c0adf, 0x0caea134,
|
||||||
|
0x37a2d439, 0xc8fa2e8a, 0x2181327e, 0x6e7bb827, 0x2d240820, 0x50be10e0,
|
||||||
|
0x5893d4b8, 0xab312bb9, 0x1f2b2322, 0x440b3f25, 0xbf627ede, 0x72dac789,
|
||||||
|
0xb608b895, 0x78787e2a, 0x86deb3f0, 0x6fee7aab, 0xbb9373f4, 0x27ecf57b,
|
||||||
|
0xf7d8b57e, 0xfca26a9f, 0x3d04e8d2, 0xc9df13cb, 0x3172826a, 0xcd9e8d7c,
|
||||||
|
0xa8fcd8e0, 0xb2c39497, 0x307641d9, 0x1cc939c1, 0x2608c4cf, 0xb6d1c7bf,
|
||||||
|
0x3d326a7e, 0xeeaf19e6, 0x8e13e25f, 0xee63302b, 0x2dfe6d97, 0x25971d58,
|
||||||
|
0xe41d3cc4, 0x0a80627c, 0xab8db59a, 0x9eea37c8, 0xe90afb77, 0x90ca19cf,
|
||||||
|
0x9ee3352c, 0x3613c850, 0xfe78d682, 0x788f6e50, 0x5b060904, 0xb71bd1a4,
|
||||||
|
0x3fecb534, 0xb32c450c, 0x20c33857, 0xa6e9cfda, 0x0239f4ce, 0x48497187,
|
||||||
|
0xa19adb95, 0xb492ed8a, 0x95aca6a8, 0x4dcd6cd9, 0xcf1b2350, 0xfbe8b12a,
|
||||||
|
0x1a67778c, 0x38eb3acc, 0xc32da383, 0xfb126ab1, 0xa03f40a8, 0xed5bf546,
|
||||||
|
0xe9ce4724, 0x4c4a74fd, 0x73a130d8, 0xd9960e2d, 0xa2ebd6c1, 0x94ab6feb,
|
||||||
|
0x6f233b7c, 0x49126080, 0x8e7b9a73, 0x4b8c9091, 0xd298f999, 0x35e836b5,
|
||||||
|
0xa96ddeff, 0x96119b31, 0x6b0dd9bc, 0xc6cc3f8d, 0x282566fb, 0x72b882e7,
|
||||||
|
0xd6769f3b, 0xa674343d, 0x00fc509b, 0xdcbf7789, 0xd6266a3f, 0xae9641fd,
|
||||||
|
0x4e89541b, 0x11953407, 0x53400d03, 0x8e0dd75a, 0xe5b53345, 0x108f19ad,
|
||||||
|
0x108b89bc, 0x41a4c954, 0xe03b2b63, 0x437b3d7f, 0x97aced8e, 0xcbd66670,
|
||||||
|
0x2c5508c2, 0x650ebc69, 0x5c4f2ef0, 0x904ff6bf, 0x9985a2df, 0x9faddd9e,
|
||||||
|
0x5ed8d239, 0x25585832, 0xe3e51cb9, 0x0ff4f1d4, 0x56c02d9a, 0x8c4ef804,
|
||||||
|
0xc1a08a13, 0x13fd01c8, 0xe6d27671, 0xa7c234f4, 0x9d0176cc, 0xd0d73df2,
|
||||||
|
0x4d8bfa89, 0x544f10cd, 0x2b17e0b2, 0xb70a5c7d, 0xfd86fe49, 0xdf373f41,
|
||||||
|
0x214495bb, 0x84e857fd, 0x00d313d5, 0x0496fcbe, 0xa4ba4744, 0xe8cac982,
|
||||||
|
0xaec29e6e, 0x87ec7038, 0x7000a519, 0xaeee333b, 0xff66e42c, 0x8afd6b25,
|
||||||
|
0x03b4f63b, 0xbd7991dc, 0x5ab8d9c7, 0x2ed4684e, 0x48741a6c, 0xaf06940d,
|
||||||
|
0x2fdc6349, 0xb03d7ecd, 0xe974996f, 0xac7867f9, 0x52ec8721, 0xbcdd9d4a,
|
||||||
|
0x8edd2d00, 0x3557de06, 0x41c759f8, 0x3956d4b9, 0xa75409f2, 0x123cd8a1,
|
||||||
|
0xb6100fab, 0x3e7b21e2, 0x2e8d623b, 0x92959da2, 0xbca35f77, 0x200c03a5,
|
||||||
|
0x35fcb457, 0x1bb6c6e4, 0xf74eb928, 0x3d5d0b54, 0x87cc1d21, 0x4964046f,
|
||||||
|
0x18ae4240, 0xd868b275, 0x8bd2b496, 0x1c5563f4, 0xc234d8f5, 0xf868e970,
|
||||||
|
0xf9151fff, 0xae7be4a2, 0x271133ee, 0xbb0fd922, 0x25254932, 0xa60a9fc0,
|
||||||
|
0x104bcd64, 0x30290145, 0x00000062
|
||||||
|
#endif /* !__NO_LONG_DOUBLE_MATH */
|
||||||
|
};
|
||||||
|
|
||||||
|
#elif BITS_PER_MP_LIMB == 64
|
||||||
|
|
||||||
|
/* Table with constants of 10^(2^i), i=0..12 for 64-bit limbs. */
|
||||||
|
|
||||||
|
const mp_limb_t __tens[] =
|
||||||
|
{
|
||||||
|
#define TENS_P0_IDX 0
|
||||||
|
#define TENS_P0_SIZE 2
|
||||||
|
[TENS_P0_IDX] = 0x0000000000000000ull, 0x000000000000000aull,
|
||||||
|
|
||||||
|
#define TENS_P1_IDX (TENS_P0_IDX + TENS_P0_SIZE)
|
||||||
|
#define TENS_P1_SIZE 2
|
||||||
|
[TENS_P1_IDX] = 0x0000000000000000ull, 0x0000000000000064ull,
|
||||||
|
|
||||||
|
#define TENS_P2_IDX (TENS_P1_IDX + TENS_P1_SIZE)
|
||||||
|
#define TENS_P2_SIZE 2
|
||||||
|
[TENS_P2_IDX] = 0x0000000000000000ull, 0x0000000000002710ull,
|
||||||
|
|
||||||
|
#define TENS_P3_IDX (TENS_P2_IDX + TENS_P2_SIZE)
|
||||||
|
#define TENS_P3_SIZE 2
|
||||||
|
[TENS_P3_IDX] = 0x0000000000000000ull, 0x0000000005f5e100ull,
|
||||||
|
|
||||||
|
#define TENS_P4_IDX (TENS_P3_IDX + TENS_P3_SIZE)
|
||||||
|
#define TENS_P4_SIZE 2
|
||||||
|
[TENS_P4_IDX] = 0x0000000000000000ull, 0x002386f26fc10000ull,
|
||||||
|
|
||||||
|
#define TENS_P5_IDX (TENS_P4_IDX + TENS_P4_SIZE)
|
||||||
|
#define TENS_P5_SIZE 3
|
||||||
|
[TENS_P5_IDX] = 0x0000000000000000ull, 0x85acef8100000000ull,
|
||||||
|
0x000004ee2d6d415bull,
|
||||||
|
|
||||||
|
#define TENS_P6_IDX (TENS_P5_IDX + TENS_P5_SIZE)
|
||||||
|
#define TENS_P6_SIZE 5
|
||||||
|
[TENS_P6_IDX] = 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x6e38ed64bf6a1f01ull, 0xe93ff9f4daa797edull, 0x0000000000184f03ull,
|
||||||
|
|
||||||
|
#define TENS_P7_IDX (TENS_P6_IDX + TENS_P6_SIZE)
|
||||||
|
#define TENS_P7_SIZE 8
|
||||||
|
[TENS_P7_IDX] = 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x03df99092e953e01ull, 0x2374e42f0f1538fdull,
|
||||||
|
0xc404dc08d3cff5ecull, 0xa6337f19bccdb0daull, 0x0000024ee91f2603ull,
|
||||||
|
|
||||||
|
#define TENS_P8_IDX (TENS_P7_IDX + TENS_P7_SIZE)
|
||||||
|
#define TENS_P8_SIZE 15
|
||||||
|
[TENS_P8_IDX] = 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0xbed3875b982e7c01ull, 0x12152f87d8d99f72ull, 0xcf4a6e706bde50c6ull,
|
||||||
|
0x26b2716ed595d80full, 0x1d153624adc666b0ull, 0x63ff540e3c42d35aull,
|
||||||
|
0x65f9ef17cc5573c0ull, 0x80dcc7f755bc28f2ull, 0x5fdcefcef46eeddcull,
|
||||||
|
0x00000000000553f7ull,
|
||||||
|
#ifndef __NO_LONG_DOUBLE_MATH
|
||||||
|
# define TENS_P9_IDX (TENS_P8_IDX + TENS_P8_SIZE)
|
||||||
|
# define TENS_P9_SIZE 28
|
||||||
|
[TENS_P9_IDX] = 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x77f27267fc6cf801ull, 0x5d96976f8f9546dcull,
|
||||||
|
0xc31e1ad9b83a8a97ull, 0x94e6574746c40513ull, 0x4475b579c88976c1ull,
|
||||||
|
0xaa1da1bf28f8733bull, 0x1e25cfea703ed321ull, 0xbc51fb2eb21a2f22ull,
|
||||||
|
0xbfa3edac96e14f5dull, 0xe7fc7153329c57aeull, 0x85a91924c3fc0695ull,
|
||||||
|
0xb2908ee0f95f635eull, 0x1366732a93abade4ull, 0x69be5b0e9449775cull,
|
||||||
|
0xb099bc817343afacull, 0xa269974845a71d46ull, 0x8a0b1f138cb07303ull,
|
||||||
|
0xc1d238d98cab8a97ull, 0x0000001c633415d4ull,
|
||||||
|
|
||||||
|
# define TENS_P10_IDX (TENS_P9_IDX + TENS_P9_SIZE)
|
||||||
|
# define TENS_P10_SIZE 55
|
||||||
|
[TENS_P10_IDX] = 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0xf55b2b722919f001ull, 0x1ec29f866e7c215bull, 0x15c51a88991c4e87ull,
|
||||||
|
0x4c7d1e1a140ac535ull, 0x0ed1440ecc2cd819ull, 0x7de16cfb896634eeull,
|
||||||
|
0x9fce837d1e43f61full, 0x233e55c7231d2b9cull, 0xf451218b65dc60d7ull,
|
||||||
|
0xc96359861c5cd134ull, 0xa7e89431922bbb9full, 0x62be695a9f9f2a07ull,
|
||||||
|
0x045b7a748e1042c4ull, 0x8ad822a51abe1de3ull, 0xd814b505ba34c411ull,
|
||||||
|
0x8fc51a16bf3fdeb3ull, 0xf56deeecb1b896bcull, 0xb6f4654b31fb6bfdull,
|
||||||
|
0x6b7595fb101a3616ull, 0x80d98089dc1a47feull, 0x9a20288280bda5a5ull,
|
||||||
|
0xfc8f1f9031eb0f66ull, 0xe26a7b7e976a3310ull, 0x3ce3a0b8df68368aull,
|
||||||
|
0x75a351a28e4262ceull, 0x445975836cb0b6c9ull, 0xc356e38a31b5653full,
|
||||||
|
0x0190fba035faaba6ull, 0x88bc491b9fc4ed52ull, 0x005b80411640114aull,
|
||||||
|
0x1e8d4649f4f3235eull, 0x73c5534936a8de06ull, 0xc1a6970ca7e6bd2aull,
|
||||||
|
0xd2db49ef47187094ull, 0xae6209d4926c3f5bull, 0x34f4a3c62d433949ull,
|
||||||
|
0xd9d61a05d4305d94ull, 0x0000000000000325ull,
|
||||||
|
|
||||||
|
# define TENS_P11_IDX (TENS_P10_IDX + TENS_P10_SIZE)
|
||||||
|
# define TENS_P11_SIZE 108
|
||||||
|
[TENS_P11_IDX] = 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0xe30968651333e001ull, 0x49e28dcfb27d4d3full,
|
||||||
|
0xee87e354ec2e4721ull, 0x368b8abbb6067584ull, 0x2ed56d55a5e5a191ull,
|
||||||
|
0xea50d142fd827773ull, 0x98342c9e51b78db2ull, 0x866ed6f1c850dabcull,
|
||||||
|
0x9279498719342c12ull, 0x66912e4ad2f869c2ull, 0x57a7842d71c7fd8full,
|
||||||
|
0xfb7fedcc235552ebull, 0x38209ce1f3861ce0ull, 0x34c101349713b449ull,
|
||||||
|
0xa7a8289c8c6c54deull, 0xe3cb64f32dbb6643ull, 0xe3892ee98074ff01ull,
|
||||||
|
0xa8f16f9210c17f94ull, 0x967abbb3a8281ed6ull, 0x9952fbed5a151440ull,
|
||||||
|
0xafe609c313b41e44ull, 0xf111821fa2bca416ull, 0x91bac974fb1264b4ull,
|
||||||
|
0x8e48ff35d6c7d6abull, 0xc4a656654419bd43ull, 0x33554c36685e5510ull,
|
||||||
|
0x0dbd21feab498697ull, 0x982da4663cfe491dull, 0x9e110c7bcbea4ca7ull,
|
||||||
|
0x5fc5a04779c56b8aull, 0x1aa9f44484d80e2eull, 0x6a57b1ab730f203cull,
|
||||||
|
0x87a7dc62d752f7a6ull, 0x40660460944545ffull, 0xc9ac375d77c1a42full,
|
||||||
|
0x744695f0e866d7efull, 0xa1fc6b9681428c85ull, 0x7bf03c19d7917c7bull,
|
||||||
|
0x5715f7915b33eb41ull, 0xdb0708fd8f6cae5full, 0x785ce6b7b125ac8eull,
|
||||||
|
0x6f46eadb56c6815bull, 0x195355d84eeebeeeull, 0x9d7389c0a244de3cull,
|
||||||
|
0xcf99d01953761abdull, 0x0d76ce39de9ec24bull, 0x2e55ecee70beb181ull,
|
||||||
|
0xf56d9d4bd5f86079ull, 0x13ef5a83fb8886fbull, 0x3f3389a4408f43c5ull,
|
||||||
|
0x58ccf45cfad37943ull, 0x415c7f3ef82df846ull, 0x8b3d5cf42915e818ull,
|
||||||
|
0xf8dbb57a6a445f27ull, 0x8ad803ecca8f0070ull, 0x038f9245b2e87c34ull,
|
||||||
|
0xc7c9dee0bedd8a6cull, 0x2ad3fa140eac7d56ull, 0xf775677ce0de0840ull,
|
||||||
|
0x92be221ef1bd0ad5ull, 0xce9d04a487fa1fb9ull, 0x3f6f7024d2c36fa9ull,
|
||||||
|
0x907855eeb028af62ull, 0x4efac5dcd83e49d6ull, 0x77cd8c6be7151aabull,
|
||||||
|
0x0af908b40a753b7dull, 0xe50f30278c983623ull, 0x1d08e2d694222771ull,
|
||||||
|
0xf2ee5ca6f7e928e6ull, 0x11eb962b1b61b93cull, 0xce2bcba19648b21cull,
|
||||||
|
0x7bbebe3034f77154ull, 0x8ce329ace526a319ull, 0xb5dc53d5de4a74d2ull,
|
||||||
|
0x000000000009e8b3ull,
|
||||||
|
|
||||||
|
# define TENS_P12_IDX (TENS_P11_IDX + TENS_P11_SIZE)
|
||||||
|
# define TENS_P12_SIZE 214
|
||||||
|
[TENS_P12_IDX] = 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0x0000000000000000ull, 0x0000000000000000ull, 0x0000000000000000ull,
|
||||||
|
0xd4724e8d2a67c001ull, 0xf89a1e908efe7ae7ull, 0x54e05154ef084117ull,
|
||||||
|
0x506be82913b1bb51ull, 0xe599574efb29b172ull, 0x806c0ed3f0da6146ull,
|
||||||
|
0x45155e93b86ae5beull, 0x7e1e7c34c0591cc2ull, 0x1d1f4cce7c4823daull,
|
||||||
|
0xd6bfdf759b8ba1e8ull, 0xc2dfae78e341be10ull, 0x0f237f1a016b67b2ull,
|
||||||
|
0xaf6a25743dbeabcdull, 0x142e0e80cab3e6d7ull, 0x2c23481161959127ull,
|
||||||
|
0xcb4bf98287009701ull, 0x88052f8cf8169c84ull, 0xbc13176168dde6d4ull,
|
||||||
|
0x54ab9c41ff0b0905ull, 0x1a1c304e7613b224ull, 0x441c2d473bfe167bull,
|
||||||
|
0x78f061814f6cea9cull, 0x30c7ae41eb659fb8ull, 0xa1ebcad7947e0d0eull,
|
||||||
|
0x2130504dd97d9556ull, 0xf2acd5071a8309cbull, 0xfd82373a3f8ec72aull,
|
||||||
|
0x280f4d3295a842bcull, 0x811a4f04f3618ac0ull, 0xd3967a1b6dc3a5b4ull,
|
||||||
|
0xdcfe388f15b8c898ull, 0x8738b909454eb2a0ull, 0x2bd9cc1110c4e996ull,
|
||||||
|
0x655fec303297cd0cull, 0xf4090ee8ae0725b1ull, 0x398c6fed037d19eeull,
|
||||||
|
0xc994a4503b9af26bull, 0x75a697b2b5341743ull, 0x3ccb5b92ac50b9c1ull,
|
||||||
|
0xa8329761ffe06205ull, 0xeb83cadbdfea5242ull, 0x3c20ee69e79dadf7ull,
|
||||||
|
0x7021b97a1e0a6817ull, 0x176ca776743074faull, 0xeca19beb77fb8af6ull,
|
||||||
|
0xaf63b71292baf1deull, 0xa4eb8f8cde35c88bull, 0x40b464a0e137d5e9ull,
|
||||||
|
0x42923bbd87d1cde8ull, 0x2e2690f3cd8f62ffull, 0x59c89f1b095edc16ull,
|
||||||
|
0x5138753d1fa8fd5dull, 0x80152f18390a2b29ull, 0xf984d83e2dd8d925ull,
|
||||||
|
0xc19e1faf7a872e74ull, 0xecf9b5d0ed4d542dull, 0xc53c0adf9462ea75ull,
|
||||||
|
0x37a2d4390caea134ull, 0x2181327ec8fa2e8aull, 0x2d2408206e7bb827ull,
|
||||||
|
0x5893d4b850be10e0ull, 0x1f2b2322ab312bb9ull, 0xbf627ede440b3f25ull,
|
||||||
|
0xb608b89572dac789ull, 0x86deb3f078787e2aull, 0xbb9373f46fee7aabull,
|
||||||
|
0xf7d8b57e27ecf57bull, 0x3d04e8d2fca26a9full, 0x3172826ac9df13cbull,
|
||||||
|
0xa8fcd8e0cd9e8d7cull, 0x307641d9b2c39497ull, 0x2608c4cf1cc939c1ull,
|
||||||
|
0x3d326a7eb6d1c7bfull, 0x8e13e25feeaf19e6ull, 0x2dfe6d97ee63302bull,
|
||||||
|
0xe41d3cc425971d58ull, 0xab8db59a0a80627cull, 0xe90afb779eea37c8ull,
|
||||||
|
0x9ee3352c90ca19cfull, 0xfe78d6823613c850ull, 0x5b060904788f6e50ull,
|
||||||
|
0x3fecb534b71bd1a4ull, 0x20c33857b32c450cull, 0x0239f4cea6e9cfdaull,
|
||||||
|
0xa19adb9548497187ull, 0x95aca6a8b492ed8aull, 0xcf1b23504dcd6cd9ull,
|
||||||
|
0x1a67778cfbe8b12aull, 0xc32da38338eb3accull, 0xa03f40a8fb126ab1ull,
|
||||||
|
0xe9ce4724ed5bf546ull, 0x73a130d84c4a74fdull, 0xa2ebd6c1d9960e2dull,
|
||||||
|
0x6f233b7c94ab6febull, 0x8e7b9a7349126080ull, 0xd298f9994b8c9091ull,
|
||||||
|
0xa96ddeff35e836b5ull, 0x6b0dd9bc96119b31ull, 0x282566fbc6cc3f8dull,
|
||||||
|
0xd6769f3b72b882e7ull, 0x00fc509ba674343dull, 0xd6266a3fdcbf7789ull,
|
||||||
|
0x4e89541bae9641fdull, 0x53400d0311953407ull, 0xe5b533458e0dd75aull,
|
||||||
|
0x108b89bc108f19adull, 0xe03b2b6341a4c954ull, 0x97aced8e437b3d7full,
|
||||||
|
0x2c5508c2cbd66670ull, 0x5c4f2ef0650ebc69ull, 0x9985a2df904ff6bfull,
|
||||||
|
0x5ed8d2399faddd9eull, 0xe3e51cb925585832ull, 0x56c02d9a0ff4f1d4ull,
|
||||||
|
0xc1a08a138c4ef804ull, 0xe6d2767113fd01c8ull, 0x9d0176cca7c234f4ull,
|
||||||
|
0x4d8bfa89d0d73df2ull, 0x2b17e0b2544f10cdull, 0xfd86fe49b70a5c7dull,
|
||||||
|
0x214495bbdf373f41ull, 0x00d313d584e857fdull, 0xa4ba47440496fcbeull,
|
||||||
|
0xaec29e6ee8cac982ull, 0x7000a51987ec7038ull, 0xff66e42caeee333bull,
|
||||||
|
0x03b4f63b8afd6b25ull, 0x5ab8d9c7bd7991dcull, 0x48741a6c2ed4684eull,
|
||||||
|
0x2fdc6349af06940dull, 0xe974996fb03d7ecdull, 0x52ec8721ac7867f9ull,
|
||||||
|
0x8edd2d00bcdd9d4aull, 0x41c759f83557de06ull, 0xa75409f23956d4b9ull,
|
||||||
|
0xb6100fab123cd8a1ull, 0x2e8d623b3e7b21e2ull, 0xbca35f7792959da2ull,
|
||||||
|
0x35fcb457200c03a5ull, 0xf74eb9281bb6c6e4ull, 0x87cc1d213d5d0b54ull,
|
||||||
|
0x18ae42404964046full, 0x8bd2b496d868b275ull, 0xc234d8f51c5563f4ull,
|
||||||
|
0xf9151ffff868e970ull, 0x271133eeae7be4a2ull, 0x25254932bb0fd922ull,
|
||||||
|
0x104bcd64a60a9fc0ull, 0x0000006230290145ull
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
# error "mp_limb_t size " BITS_PER_MP_LIMB "not accounted for"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Each of array variable above defines one mpn integer which is a power of 10.
|
||||||
|
This table points to those variables, indexed by the exponent. */
|
||||||
|
|
||||||
|
const struct mp_power _fpioconst_pow10[LDBL_MAX_10_EXP_LOG + 1] =
|
||||||
|
{
|
||||||
|
{ TENS_P0_IDX, TENS_P0_SIZE, 4, },
|
||||||
|
{ TENS_P1_IDX, TENS_P1_SIZE, 7, 4 },
|
||||||
|
{ TENS_P2_IDX, TENS_P2_SIZE, 14, 10 },
|
||||||
|
{ TENS_P3_IDX, TENS_P3_SIZE, 27, 24 },
|
||||||
|
{ TENS_P4_IDX, TENS_P4_SIZE, 54, 50 },
|
||||||
|
{ TENS_P5_IDX, TENS_P5_SIZE, 107, 103 },
|
||||||
|
{ TENS_P6_IDX, TENS_P6_SIZE, 213, 210 },
|
||||||
|
{ TENS_P7_IDX, TENS_P7_SIZE, 426, 422 },
|
||||||
|
{ TENS_P8_IDX, TENS_P8_SIZE, 851, 848 },
|
||||||
|
#ifndef __NO_LONG_DOUBLE_MATH
|
||||||
|
{ TENS_P9_IDX, TENS_P9_SIZE, 1701, 1698 },
|
||||||
|
{ TENS_P10_IDX, TENS_P10_SIZE, 3402, 3399 },
|
||||||
|
{ TENS_P11_IDX, TENS_P11_SIZE, 6804, 6800 },
|
||||||
|
{ TENS_P12_IDX, TENS_P12_SIZE, 13607, 13604 }
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#if LAST_POW10 > _LAST_POW10
|
||||||
|
# error "Need to expand 10^(2^i) table for i up to" LAST_POW10
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/* Header file for constants used in floating point <-> decimal conversions.
|
||||||
|
Copyright (C) 1995, 1996, 1997, 1998, 1999, 2002, 2003
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef _FPIOCONST_H
|
||||||
|
#define _FPIOCONST_H
|
||||||
|
|
||||||
|
#include <float.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <gmp.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* These values are used by __printf_fp, where they are noncritical (if the
|
||||||
|
value is not large enough, it will just be slower); and by
|
||||||
|
strtof/strtod/strtold, where it is critical (it's used for overflow
|
||||||
|
detection).
|
||||||
|
|
||||||
|
XXX These should be defined in <float.h>. For the time being, we have the
|
||||||
|
IEEE754 values here. */
|
||||||
|
|
||||||
|
#ifndef __NO_LONG_DOUBLE_MATH
|
||||||
|
# define LDBL_MAX_10_EXP_LOG 12 /* = floor(log_2(LDBL_MAX_10_EXP)) */
|
||||||
|
#else
|
||||||
|
# define LDBL_MAX_10_EXP_LOG 8 /* = floor(log_2(LDBL_MAX_10_EXP)) */
|
||||||
|
#endif
|
||||||
|
#define DBL_MAX_10_EXP_LOG 8 /* = floor(log_2(DBL_MAX_10_EXP)) */
|
||||||
|
#define FLT_MAX_10_EXP_LOG 5 /* = floor(log_2(FLT_MAX_10_EXP)) */
|
||||||
|
|
||||||
|
|
||||||
|
/* The array with the number representation. */
|
||||||
|
extern const mp_limb_t __tens[] attribute_hidden;
|
||||||
|
|
||||||
|
/* Table of powers of ten. This is used by __printf_fp and by
|
||||||
|
strtof/strtod/strtold. */
|
||||||
|
struct mp_power
|
||||||
|
{
|
||||||
|
size_t arrayoff; /* Offset in `__tens'. */
|
||||||
|
mp_size_t arraysize; /* Size of the array. */
|
||||||
|
int p_expo; /* Exponent of the number 10^(2^i). */
|
||||||
|
int m_expo; /* Exponent of the number 10^-(2^i-1). */
|
||||||
|
};
|
||||||
|
extern const struct mp_power _fpioconst_pow10[LDBL_MAX_10_EXP_LOG + 1]
|
||||||
|
attribute_hidden;
|
||||||
|
|
||||||
|
/* The constants in the array `_fpioconst_pow10' have an offset. */
|
||||||
|
#if BITS_PER_MP_LIMB == 32
|
||||||
|
# define _FPIO_CONST_OFFSET 2
|
||||||
|
#else
|
||||||
|
# define _FPIO_CONST_OFFSET 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* fpioconst.h */
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
translations='
|
||||||
|
sparc64 sparc/sparc64
|
||||||
|
sparc32/v8 sparc/sparc8
|
||||||
|
sparc32 sparc
|
||||||
|
x86/pentium i386/i586
|
||||||
|
x86 i386
|
||||||
|
m68k/mc68000 m68k/m68000
|
||||||
|
m68k/mc68020 m68k/m68020
|
||||||
|
m88k/mc88100 m88k/m88100
|
||||||
|
m88k/mc88110 m88k/m88110
|
||||||
|
mips3 mips/mips3
|
||||||
|
mips2 mips
|
||||||
|
hppa/hppa1_1 hppa/hppa1.1
|
||||||
|
alpha/ev5 alpha/alphaev5
|
||||||
|
power rs6000
|
||||||
|
am29000 a29k
|
||||||
|
'
|
||||||
|
|
||||||
|
set $translations
|
||||||
|
while [ $# -ge 2 ]; do
|
||||||
|
gmp=$1 glibc=$2
|
||||||
|
shift; shift
|
||||||
|
echo 'mpn-found-1 := $(filter $(gmp-srcdir)/mpn/'$gmp'/%,$(mpn-found))
|
||||||
|
mpn-copy-1 := $(patsubst $(gmp-srcdir)/mpn/'$gmp'/%,$(sysdep_dir)/'$glibc\
|
||||||
|
'/%,$(mpn-found-1))
|
||||||
|
mpn-found := $(filter-out $(mpn-found-1),$(mpn-found))
|
||||||
|
mpn-copy-sysdep := $(mpn-copy-sysdep) $(mpn-copy-1)
|
||||||
|
$(mpn-copy-1): $(sysdep_dir)/'$glibc'/%: \
|
||||||
|
$(ignore gmp2glibc.sed) $(gmp-srcdir)/mpn/'$gmp'/%
|
||||||
|
$(gmp2glibc)'
|
||||||
|
done
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/* Parse comma separate list into words.
|
||||||
|
Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Parse comma separated suboption from *OPTIONP and match against
|
||||||
|
strings in TOKENS. If found return index and set *VALUEP to
|
||||||
|
optional value introduced by an equal sign. If the suboption is
|
||||||
|
not part of TOKENS return in *VALUEP beginning of unknown
|
||||||
|
suboption. On exit *OPTIONP is set to the beginning of the next
|
||||||
|
token or at the terminating NUL character. */
|
||||||
|
int
|
||||||
|
getsubopt (optionp, tokens, valuep)
|
||||||
|
char **optionp;
|
||||||
|
char *const *tokens;
|
||||||
|
char **valuep;
|
||||||
|
{
|
||||||
|
char *endp, *vstart;
|
||||||
|
int cnt;
|
||||||
|
|
||||||
|
if (**optionp == '\0')
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Find end of next token. */
|
||||||
|
endp = __strchrnul (*optionp, ',');
|
||||||
|
|
||||||
|
/* Find start of value. */
|
||||||
|
vstart = memchr (*optionp, '=', endp - *optionp);
|
||||||
|
if (vstart == NULL)
|
||||||
|
vstart = endp;
|
||||||
|
|
||||||
|
/* Try to match the characters between *OPTIONP and VSTART against
|
||||||
|
one of the TOKENS. */
|
||||||
|
for (cnt = 0; tokens[cnt] != NULL; ++cnt)
|
||||||
|
if (memcmp (*optionp, tokens[cnt], vstart - *optionp) == 0
|
||||||
|
&& tokens[cnt][vstart - *optionp] == '\0')
|
||||||
|
{
|
||||||
|
/* We found the current option in TOKENS. */
|
||||||
|
*valuep = vstart != endp ? vstart + 1 : NULL;
|
||||||
|
|
||||||
|
if (*endp != '\0')
|
||||||
|
*endp++ = '\0';
|
||||||
|
*optionp = endp;
|
||||||
|
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The current suboption does not match any option. */
|
||||||
|
*valuep = *optionp;
|
||||||
|
|
||||||
|
if (*endp != '\0')
|
||||||
|
*endp++ = '\0';
|
||||||
|
*optionp = endp;
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
/* Include file for internal GNU MP types and definitions.
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is part of the GNU MP Library.
|
||||||
|
|
||||||
|
The GNU MP Library is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
The GNU MP Library is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||||
|
MA 02111-1307, USA. */
|
||||||
|
|
||||||
|
/* When using gcc, make sure to use its builtin alloca. */
|
||||||
|
#if ! defined (alloca) && defined (__GNUC__)
|
||||||
|
#define alloca __builtin_alloca
|
||||||
|
#define HAVE_ALLOCA
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* When using cc, do whatever necessary to allow use of alloca. For many
|
||||||
|
machines, this means including alloca.h. IBM's compilers need a #pragma
|
||||||
|
in "each module that needs to use alloca". */
|
||||||
|
#if ! defined (alloca)
|
||||||
|
/* We need lots of variants for MIPS, to cover all versions and perversions
|
||||||
|
of OSes for MIPS. */
|
||||||
|
#if defined (__mips) || defined (MIPSEL) || defined (MIPSEB) \
|
||||||
|
|| defined (_MIPSEL) || defined (_MIPSEB) || defined (__sgi) \
|
||||||
|
|| defined (__alpha) || defined (__sparc) || defined (sparc) \
|
||||||
|
|| defined (__ksr__)
|
||||||
|
#include <alloca.h>
|
||||||
|
#define HAVE_ALLOCA
|
||||||
|
#endif
|
||||||
|
#if defined (_IBMR2)
|
||||||
|
#pragma alloca
|
||||||
|
#define HAVE_ALLOCA
|
||||||
|
#endif
|
||||||
|
#if defined (__DECC)
|
||||||
|
#define alloca(x) __ALLOCA(x)
|
||||||
|
#define HAVE_ALLOCA
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ! defined (HAVE_ALLOCA) || USE_STACK_ALLOC
|
||||||
|
#include "stack-alloc.h"
|
||||||
|
#else
|
||||||
|
#define TMP_DECL(m)
|
||||||
|
#define TMP_ALLOC(x) alloca(x)
|
||||||
|
#define TMP_MARK(m)
|
||||||
|
#define TMP_FREE(m)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef NULL
|
||||||
|
#define NULL ((void *) 0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if ! defined (__GNUC__)
|
||||||
|
#define inline /* Empty */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ABS(x) (x >= 0 ? x : -x)
|
||||||
|
#ifndef MIN
|
||||||
|
#define MIN(l,o) ((l) < (o) ? (l) : (o))
|
||||||
|
#endif
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(h,i) ((h) > (i) ? (h) : (i))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Field access macros. */
|
||||||
|
#define SIZ(x) ((x)->_mp_size)
|
||||||
|
#define ABSIZ(x) ABS (SIZ (x))
|
||||||
|
#define PTR(x) ((x)->_mp_d)
|
||||||
|
#define EXP(x) ((x)->_mp_exp)
|
||||||
|
#define PREC(x) ((x)->_mp_prec)
|
||||||
|
#define ALLOC(x) ((x)->_mp_alloc)
|
||||||
|
|
||||||
|
#include "gmp-mparam.h"
|
||||||
|
/* #include "longlong.h" */
|
||||||
|
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
void *malloc (size_t);
|
||||||
|
void *realloc (void *, size_t);
|
||||||
|
void free (void *);
|
||||||
|
|
||||||
|
extern void * (*_mp_allocate_func) (size_t);
|
||||||
|
extern void * (*_mp_reallocate_func) (void *, size_t, size_t);
|
||||||
|
extern void (*_mp_free_func) (void *, size_t);
|
||||||
|
|
||||||
|
void *_mp_default_allocate (size_t);
|
||||||
|
void *_mp_default_reallocate (void *, size_t, size_t);
|
||||||
|
void _mp_default_free (void *, size_t);
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define const /* Empty */
|
||||||
|
#define signed /* Empty */
|
||||||
|
|
||||||
|
void *malloc ();
|
||||||
|
void *realloc ();
|
||||||
|
void free ();
|
||||||
|
|
||||||
|
extern void * (*_mp_allocate_func) ();
|
||||||
|
extern void * (*_mp_reallocate_func) ();
|
||||||
|
extern void (*_mp_free_func) ();
|
||||||
|
|
||||||
|
void *_mp_default_allocate ();
|
||||||
|
void *_mp_default_reallocate ();
|
||||||
|
void _mp_default_free ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Copy NLIMBS *limbs* from SRC to DST. */
|
||||||
|
#define MPN_COPY_INCR(DST, SRC, NLIMBS) \
|
||||||
|
do { \
|
||||||
|
mp_size_t __i; \
|
||||||
|
for (__i = 0; __i < (NLIMBS); __i++) \
|
||||||
|
(DST)[__i] = (SRC)[__i]; \
|
||||||
|
} while (0)
|
||||||
|
#define MPN_COPY_DECR(DST, SRC, NLIMBS) \
|
||||||
|
do { \
|
||||||
|
mp_size_t __i; \
|
||||||
|
for (__i = (NLIMBS) - 1; __i >= 0; __i--) \
|
||||||
|
(DST)[__i] = (SRC)[__i]; \
|
||||||
|
} while (0)
|
||||||
|
#define MPN_COPY MPN_COPY_INCR
|
||||||
|
|
||||||
|
/* Zero NLIMBS *limbs* AT DST. */
|
||||||
|
#define MPN_ZERO(DST, NLIMBS) \
|
||||||
|
do { \
|
||||||
|
mp_size_t __i; \
|
||||||
|
for (__i = 0; __i < (NLIMBS); __i++) \
|
||||||
|
(DST)[__i] = 0; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define MPN_NORMALIZE(DST, NLIMBS) \
|
||||||
|
do { \
|
||||||
|
while (NLIMBS > 0) \
|
||||||
|
{ \
|
||||||
|
if ((DST)[(NLIMBS) - 1] != 0) \
|
||||||
|
break; \
|
||||||
|
NLIMBS--; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
#define MPN_NORMALIZE_NOT_ZERO(DST, NLIMBS) \
|
||||||
|
do { \
|
||||||
|
while (1) \
|
||||||
|
{ \
|
||||||
|
if ((DST)[(NLIMBS) - 1] != 0) \
|
||||||
|
break; \
|
||||||
|
NLIMBS--; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Initialize the MP_INT X with space for NLIMBS limbs.
|
||||||
|
X should be a temporary variable, and it will be automatically
|
||||||
|
cleared out when the running function returns.
|
||||||
|
We use __x here to make it possible to accept both mpz_ptr and mpz_t
|
||||||
|
arguments. */
|
||||||
|
#define MPZ_TMP_INIT(X, NLIMBS) \
|
||||||
|
do { \
|
||||||
|
mpz_ptr __x = (X); \
|
||||||
|
__x->_mp_alloc = (NLIMBS); \
|
||||||
|
__x->_mp_d = (mp_ptr) TMP_ALLOC ((NLIMBS) * BYTES_PER_MP_LIMB); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \
|
||||||
|
do { \
|
||||||
|
if ((size) < KARATSUBA_THRESHOLD) \
|
||||||
|
impn_mul_n_basecase (prodp, up, vp, size); \
|
||||||
|
else \
|
||||||
|
impn_mul_n (prodp, up, vp, size, tspace); \
|
||||||
|
} while (0);
|
||||||
|
#define MPN_SQR_N_RECURSE(prodp, up, size, tspace) \
|
||||||
|
do { \
|
||||||
|
if ((size) < KARATSUBA_THRESHOLD) \
|
||||||
|
impn_sqr_n_basecase (prodp, up, size); \
|
||||||
|
else \
|
||||||
|
impn_sqr_n (prodp, up, size, tspace); \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
/* Structure for conversion between internal binary format and
|
||||||
|
strings in base 2..36. */
|
||||||
|
struct bases
|
||||||
|
{
|
||||||
|
/* Number of digits in the conversion base that always fits in an mp_limb_t.
|
||||||
|
For example, for base 10 on a machine where a mp_limb_t has 32 bits this
|
||||||
|
is 9, since 10**9 is the largest number that fits into a mp_limb_t. */
|
||||||
|
int chars_per_limb;
|
||||||
|
|
||||||
|
/* log(2)/log(conversion_base) */
|
||||||
|
float chars_per_bit_exactly;
|
||||||
|
|
||||||
|
/* base**chars_per_limb, i.e. the biggest number that fits a word, built by
|
||||||
|
factors of base. Exception: For 2, 4, 8, etc, big_base is log2(base),
|
||||||
|
i.e. the number of bits used to represent each digit in the base. */
|
||||||
|
mp_limb_t big_base;
|
||||||
|
|
||||||
|
/* A BITS_PER_MP_LIMB bit approximation to 1/big_base, represented as a
|
||||||
|
fixed-point number. Instead of dividing by big_base an application can
|
||||||
|
choose to multiply by big_base_inverted. */
|
||||||
|
mp_limb_t big_base_inverted;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const struct bases __mp_bases[];
|
||||||
|
extern mp_size_t __gmp_default_fp_limb_precision;
|
||||||
|
|
||||||
|
/* Divide the two-limb number in (NH,,NL) by D, with DI being the largest
|
||||||
|
limb not larger than (2**(2*BITS_PER_MP_LIMB))/D - (2**BITS_PER_MP_LIMB).
|
||||||
|
If this would yield overflow, DI should be the largest possible number
|
||||||
|
(i.e., only ones). For correct operation, the most significant bit of D
|
||||||
|
has to be set. Put the quotient in Q and the remainder in R. */
|
||||||
|
#define udiv_qrnnd_preinv(q, r, nh, nl, d, di) \
|
||||||
|
do { \
|
||||||
|
mp_limb_t _q, _ql, _r; \
|
||||||
|
mp_limb_t _xh, _xl; \
|
||||||
|
umul_ppmm (_q, _ql, (nh), (di)); \
|
||||||
|
_q += (nh); /* DI is 2**BITS_PER_MP_LIMB too small */\
|
||||||
|
umul_ppmm (_xh, _xl, _q, (d)); \
|
||||||
|
sub_ddmmss (_xh, _r, (nh), (nl), _xh, _xl); \
|
||||||
|
if (_xh != 0) \
|
||||||
|
{ \
|
||||||
|
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
|
||||||
|
_q += 1; \
|
||||||
|
if (_xh != 0) \
|
||||||
|
{ \
|
||||||
|
sub_ddmmss (_xh, _r, _xh, _r, 0, (d)); \
|
||||||
|
_q += 1; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
if (_r >= (d)) \
|
||||||
|
{ \
|
||||||
|
_r -= (d); \
|
||||||
|
_q += 1; \
|
||||||
|
} \
|
||||||
|
(r) = _r; \
|
||||||
|
(q) = _q; \
|
||||||
|
} while (0)
|
||||||
|
/* Like udiv_qrnnd_preinv, but for for any value D. DNORM is D shifted left
|
||||||
|
so that its most significant bit is set. LGUP is ceil(log2(D)). */
|
||||||
|
#define udiv_qrnnd_preinv2gen(q, r, nh, nl, d, di, dnorm, lgup) \
|
||||||
|
do { \
|
||||||
|
mp_limb_t n2, n10, n1, nadj, q1; \
|
||||||
|
mp_limb_t _xh, _xl; \
|
||||||
|
n2 = ((nh) << (BITS_PER_MP_LIMB - (lgup))) + ((nl) >> 1 >> (l - 1));\
|
||||||
|
n10 = (nl) << (BITS_PER_MP_LIMB - (lgup)); \
|
||||||
|
n1 = ((mp_limb_signed_t) n10 >> (BITS_PER_MP_LIMB - 1)); \
|
||||||
|
nadj = n10 + (n1 & (dnorm)); \
|
||||||
|
umul_ppmm (_xh, _xl, di, n2 - n1); \
|
||||||
|
add_ssaaaa (_xh, _xl, _xh, _xl, 0, nadj); \
|
||||||
|
q1 = ~(n2 + _xh); \
|
||||||
|
umul_ppmm (_xh, _xl, q1, d); \
|
||||||
|
add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
|
||||||
|
_xh -= (d); \
|
||||||
|
(r) = _xl + ((d) & _xh); \
|
||||||
|
(q) = _xh - q1; \
|
||||||
|
} while (0)
|
||||||
|
/* Exactly like udiv_qrnnd_preinv, but branch-free. It is not clear which
|
||||||
|
version to use. */
|
||||||
|
#define udiv_qrnnd_preinv2norm(q, r, nh, nl, d, di) \
|
||||||
|
do { \
|
||||||
|
mp_limb_t n2, n10, n1, nadj, q1; \
|
||||||
|
mp_limb_t _xh, _xl; \
|
||||||
|
n2 = (nh); \
|
||||||
|
n10 = (nl); \
|
||||||
|
n1 = ((mp_limb_signed_t) n10 >> (BITS_PER_MP_LIMB - 1)); \
|
||||||
|
nadj = n10 + (n1 & (d)); \
|
||||||
|
umul_ppmm (_xh, _xl, di, n2 - n1); \
|
||||||
|
add_ssaaaa (_xh, _xl, _xh, _xl, 0, nadj); \
|
||||||
|
q1 = ~(n2 + _xh); \
|
||||||
|
umul_ppmm (_xh, _xl, q1, d); \
|
||||||
|
add_ssaaaa (_xh, _xl, _xh, _xl, nh, nl); \
|
||||||
|
_xh -= (d); \
|
||||||
|
(r) = _xl + ((d) & _xh); \
|
||||||
|
(q) = _xh - q1; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#if defined (__GNUC__)
|
||||||
|
/* Define stuff for longlong.h. */
|
||||||
|
typedef unsigned int UQItype __attribute__ ((mode (QI)));
|
||||||
|
typedef int SItype __attribute__ ((mode (SI)));
|
||||||
|
typedef unsigned int USItype __attribute__ ((mode (SI)));
|
||||||
|
typedef int DItype __attribute__ ((mode (DI)));
|
||||||
|
typedef unsigned int UDItype __attribute__ ((mode (DI)));
|
||||||
|
#else
|
||||||
|
typedef unsigned char UQItype;
|
||||||
|
typedef long SItype;
|
||||||
|
typedef unsigned long USItype;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef mp_limb_t UWtype;
|
||||||
|
typedef unsigned int UHWtype;
|
||||||
|
#define W_TYPE_SIZE BITS_PER_MP_LIMB
|
||||||
|
|
||||||
|
/* Internal mpn calls */
|
||||||
|
#define impn_mul_n_basecase __MPN(impn_mul_n_basecase)
|
||||||
|
#define impn_mul_n __MPN(impn_mul_n)
|
||||||
|
#define impn_sqr_n_basecase __MPN(impn_sqr_n_basecase)
|
||||||
|
#define impn_sqr_n __MPN(impn_sqr_n)
|
||||||
|
|
||||||
|
#ifndef _PROTO
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
#define _PROTO(x) x
|
||||||
|
#else
|
||||||
|
#define _PROTO(x) ()
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Prototypes for internal mpn calls. */
|
||||||
|
extern void impn_mul_n_basecase _PROTO ((mp_ptr prodp, mp_srcptr up,
|
||||||
|
mp_srcptr vp, mp_size_t size));
|
||||||
|
extern void impn_mul_n _PROTO ((mp_ptr prodp, mp_srcptr up, mp_srcptr vp,
|
||||||
|
mp_size_t size, mp_ptr tspace));
|
||||||
|
extern void impn_sqr_n_basecase _PROTO ((mp_ptr prodp, mp_srcptr up,
|
||||||
|
mp_size_t size));
|
||||||
|
extern void impn_sqr_n _PROTO ((mp_ptr prodp, mp_srcptr up, mp_size_t size,
|
||||||
|
mp_ptr tspace));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef IEEE_DOUBLE_BIG_ENDIAN
|
||||||
|
#define IEEE_DOUBLE_BIG_ENDIAN 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef IEEE_DOUBLE_MIXED_ENDIAN
|
||||||
|
#define IEEE_DOUBLE_MIXED_ENDIAN 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if IEEE_DOUBLE_MIXED_ENDIAN
|
||||||
|
union ieee_double_extract
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
unsigned int manh:20;
|
||||||
|
unsigned int exp:11;
|
||||||
|
unsigned int sig:1;
|
||||||
|
unsigned int manl:32;
|
||||||
|
} s;
|
||||||
|
double d;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
#if IEEE_DOUBLE_BIG_ENDIAN
|
||||||
|
union ieee_double_extract
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
unsigned int sig:1;
|
||||||
|
unsigned int exp:11;
|
||||||
|
unsigned int manh:20;
|
||||||
|
unsigned int manl:32;
|
||||||
|
} s;
|
||||||
|
double d;
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
union ieee_double_extract
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
unsigned int manl:32;
|
||||||
|
unsigned int manh:20;
|
||||||
|
unsigned int exp:11;
|
||||||
|
unsigned int sig:1;
|
||||||
|
} s;
|
||||||
|
double d;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,622 @@
|
|||||||
|
/* gmp.h -- Definitions for GNU multiple precision functions.
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
This file is part of the GNU MP Library.
|
||||||
|
|
||||||
|
The GNU MP Library is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
The GNU MP Library is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||||
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
||||||
|
License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
|
||||||
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
|
||||||
|
MA 02111-1307, USA. */
|
||||||
|
|
||||||
|
#ifndef __GMP_H__
|
||||||
|
|
||||||
|
#ifndef __GNU_MP__
|
||||||
|
#define __GNU_MP__ 2
|
||||||
|
#define __need_size_t
|
||||||
|
#include <stddef.h>
|
||||||
|
#undef __need_size_t
|
||||||
|
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
#define __gmp_const const
|
||||||
|
#else
|
||||||
|
#define __gmp_const
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (__GNUC__)
|
||||||
|
#define __gmp_inline __inline__
|
||||||
|
#else
|
||||||
|
#define __gmp_inline
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef _EXTERN_INLINE
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define _EXTERN_INLINE extern __inline__
|
||||||
|
#else
|
||||||
|
#define _EXTERN_INLINE static
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _SHORT_LIMB
|
||||||
|
typedef unsigned int mp_limb_t;
|
||||||
|
typedef int mp_limb_signed_t;
|
||||||
|
#else
|
||||||
|
#ifdef _LONG_LONG_LIMB
|
||||||
|
typedef unsigned long long int mp_limb_t;
|
||||||
|
typedef long long int mp_limb_signed_t;
|
||||||
|
#else
|
||||||
|
typedef unsigned long int mp_limb_t;
|
||||||
|
typedef long int mp_limb_signed_t;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef mp_limb_t * mp_ptr;
|
||||||
|
typedef __gmp_const mp_limb_t * mp_srcptr;
|
||||||
|
typedef long int mp_size_t;
|
||||||
|
typedef long int mp_exp_t;
|
||||||
|
|
||||||
|
#ifndef __MP_SMALL__
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int _mp_alloc; /* Number of *limbs* allocated and pointed
|
||||||
|
to by the D field. */
|
||||||
|
int _mp_size; /* abs(SIZE) is the number of limbs
|
||||||
|
the last field points to. If SIZE
|
||||||
|
is negative this is a negative
|
||||||
|
number. */
|
||||||
|
mp_limb_t *_mp_d; /* Pointer to the limbs. */
|
||||||
|
} __mpz_struct;
|
||||||
|
#else
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
short int _mp_alloc; /* Number of *limbs* allocated and pointed
|
||||||
|
to by the D field. */
|
||||||
|
short int _mp_size; /* abs(SIZE) is the number of limbs
|
||||||
|
the last field points to. If SIZE
|
||||||
|
is negative this is a negative
|
||||||
|
number. */
|
||||||
|
mp_limb_t *_mp_d; /* Pointer to the limbs. */
|
||||||
|
} __mpz_struct;
|
||||||
|
#endif
|
||||||
|
#endif /* __GNU_MP__ */
|
||||||
|
|
||||||
|
/* User-visible types. */
|
||||||
|
typedef __mpz_struct MP_INT;
|
||||||
|
typedef __mpz_struct mpz_t[1];
|
||||||
|
|
||||||
|
/* Structure for rational numbers. Zero is represented as 0/any, i.e.
|
||||||
|
the denominator is ignored. Negative numbers have the sign in
|
||||||
|
the numerator. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
__mpz_struct _mp_num;
|
||||||
|
__mpz_struct _mp_den;
|
||||||
|
#if 0
|
||||||
|
int _mp_num_alloc; /* Number of limbs allocated
|
||||||
|
for the numerator. */
|
||||||
|
int _mp_num_size; /* The absolute value of this field is the
|
||||||
|
length of the numerator; the sign is the
|
||||||
|
sign of the entire rational number. */
|
||||||
|
mp_ptr _mp_num; /* Pointer to the numerator limbs. */
|
||||||
|
int _mp_den_alloc; /* Number of limbs allocated
|
||||||
|
for the denominator. */
|
||||||
|
int _mp_den_size; /* Length of the denominator. (This field
|
||||||
|
should always be positive.) */
|
||||||
|
mp_ptr _mp_den; /* Pointer to the denominator limbs. */
|
||||||
|
#endif
|
||||||
|
} __mpq_struct;
|
||||||
|
|
||||||
|
typedef __mpq_struct MP_RAT;
|
||||||
|
typedef __mpq_struct mpq_t[1];
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
int _mp_prec; /* Max precision, in number of `mp_limb_t's.
|
||||||
|
Set by mpf_init and modified by
|
||||||
|
mpf_set_prec. The area pointed to
|
||||||
|
by the `d' field contains `prec' + 1
|
||||||
|
limbs. */
|
||||||
|
int _mp_size; /* abs(SIZE) is the number of limbs
|
||||||
|
the last field points to. If SIZE
|
||||||
|
is negative this is a negative
|
||||||
|
number. */
|
||||||
|
mp_exp_t _mp_exp; /* Exponent, in the base of `mp_limb_t'. */
|
||||||
|
mp_limb_t *_mp_d; /* Pointer to the limbs. */
|
||||||
|
} __mpf_struct;
|
||||||
|
|
||||||
|
/* typedef __mpf_struct MP_FLOAT; */
|
||||||
|
typedef __mpf_struct mpf_t[1];
|
||||||
|
|
||||||
|
/* Types for function declarations in gmp files. */
|
||||||
|
/* ??? Should not pollute user name space with these ??? */
|
||||||
|
typedef __gmp_const __mpz_struct *mpz_srcptr;
|
||||||
|
typedef __mpz_struct *mpz_ptr;
|
||||||
|
typedef __gmp_const __mpf_struct *mpf_srcptr;
|
||||||
|
typedef __mpf_struct *mpf_ptr;
|
||||||
|
typedef __gmp_const __mpq_struct *mpq_srcptr;
|
||||||
|
typedef __mpq_struct *mpq_ptr;
|
||||||
|
|
||||||
|
#ifndef _PROTO
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
#define _PROTO(x) x
|
||||||
|
#else
|
||||||
|
#define _PROTO(x) ()
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __MPN
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
#define __MPN(x) __mpn_##x
|
||||||
|
#else
|
||||||
|
#define __MPN(x) __mpn_/**/x
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (FILE) || defined (_STDIO_H_) || defined (__STDIO_H__) || defined (H_STDIO)
|
||||||
|
#define _GMP_H_HAVE_FILE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void mp_set_memory_functions _PROTO ((void *(*) (size_t),
|
||||||
|
void *(*) (void *, size_t, size_t),
|
||||||
|
void (*) (void *, size_t)));
|
||||||
|
extern const int mp_bits_per_limb;
|
||||||
|
|
||||||
|
/**************** Integer (i.e. Z) routines. ****************/
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
void *_mpz_realloc _PROTO ((mpz_ptr, mp_size_t));
|
||||||
|
|
||||||
|
void mpz_abs _PROTO ((mpz_ptr, mpz_srcptr));
|
||||||
|
void mpz_add _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_add_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_and _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_array_init _PROTO ((mpz_ptr, mp_size_t, mp_size_t));
|
||||||
|
void mpz_cdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
unsigned long int mpz_cdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_cdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
unsigned long int mpz_cdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_cdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
unsigned long int mpz_cdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
unsigned long int mpz_cdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_clear _PROTO ((mpz_ptr));
|
||||||
|
void mpz_clrbit _PROTO ((mpz_ptr, unsigned long int));
|
||||||
|
int mpz_cmp _PROTO ((mpz_srcptr, mpz_srcptr));
|
||||||
|
int mpz_cmp_si _PROTO ((mpz_srcptr, signed long int));
|
||||||
|
int mpz_cmp_ui _PROTO ((mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_com _PROTO ((mpz_ptr, mpz_srcptr));
|
||||||
|
void mpz_divexact _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_fac_ui _PROTO ((mpz_ptr, unsigned long int));
|
||||||
|
void mpz_fdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_fdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
unsigned long int mpz_fdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_fdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
unsigned long int mpz_fdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_fdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_fdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
unsigned long int mpz_fdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
unsigned long int mpz_fdiv_ui _PROTO ((mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_gcd _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
unsigned long int mpz_gcd_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_gcdext _PROTO ((mpz_ptr, mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
/* signed */ long int mpz_get_si _PROTO ((mpz_srcptr));
|
||||||
|
char *mpz_get_str _PROTO ((char *, int, mpz_srcptr));
|
||||||
|
unsigned long int mpz_get_ui _PROTO ((mpz_srcptr));
|
||||||
|
mp_limb_t mpz_getlimbn _PROTO ((mpz_srcptr, mp_size_t));
|
||||||
|
unsigned long int mpz_hamdist _PROTO ((mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_init _PROTO ((mpz_ptr));
|
||||||
|
#ifdef _GMP_H_HAVE_FILE
|
||||||
|
size_t mpz_inp_binary _PROTO ((mpz_ptr, FILE *));
|
||||||
|
size_t mpz_inp_raw _PROTO ((mpz_ptr, FILE *));
|
||||||
|
size_t mpz_inp_str _PROTO ((mpz_ptr, FILE *, int));
|
||||||
|
#endif
|
||||||
|
void mpz_init_set _PROTO ((mpz_ptr, mpz_srcptr));
|
||||||
|
void mpz_init_set_d _PROTO ((mpz_ptr, double));
|
||||||
|
void mpz_init_set_si _PROTO ((mpz_ptr, signed long int));
|
||||||
|
int mpz_init_set_str _PROTO ((mpz_ptr, const char *, int));
|
||||||
|
void mpz_init_set_ui _PROTO ((mpz_ptr, unsigned long int));
|
||||||
|
int mpz_invert _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_ior _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
int mpz_jacobi _PROTO ((mpz_srcptr, mpz_srcptr));
|
||||||
|
int mpz_legendre _PROTO ((mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_mod _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_mul _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_mul_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_mul_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_neg _PROTO ((mpz_ptr, mpz_srcptr));
|
||||||
|
#ifdef _GMP_H_HAVE_FILE
|
||||||
|
size_t mpz_out_binary _PROTO ((FILE *, mpz_srcptr));
|
||||||
|
size_t mpz_out_raw _PROTO ((FILE *, mpz_srcptr));
|
||||||
|
size_t mpz_out_str _PROTO ((FILE *, int, mpz_srcptr));
|
||||||
|
#endif
|
||||||
|
int mpz_perfect_square_p _PROTO ((mpz_srcptr));
|
||||||
|
unsigned long int mpz_popcount _PROTO ((mpz_srcptr));
|
||||||
|
void mpz_pow_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_powm _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_powm_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int, mpz_srcptr));
|
||||||
|
int mpz_probab_prime_p _PROTO ((mpz_srcptr, int));
|
||||||
|
void mpz_random _PROTO ((mpz_ptr, mp_size_t));
|
||||||
|
void mpz_random2 _PROTO ((mpz_ptr, mp_size_t));
|
||||||
|
unsigned long int mpz_scan0 _PROTO ((mpz_srcptr, unsigned long int));
|
||||||
|
unsigned long int mpz_scan1 _PROTO ((mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_set _PROTO ((mpz_ptr, mpz_srcptr));
|
||||||
|
void mpz_set_d _PROTO ((mpz_ptr, double));
|
||||||
|
void mpz_set_si _PROTO ((mpz_ptr, signed long int));
|
||||||
|
int mpz_set_str _PROTO ((mpz_ptr, const char *, int));
|
||||||
|
void mpz_set_ui _PROTO ((mpz_ptr, unsigned long int));
|
||||||
|
void mpz_setbit _PROTO ((mpz_ptr, unsigned long int));
|
||||||
|
size_t mpz_size _PROTO ((mpz_srcptr));
|
||||||
|
size_t mpz_sizeinbase _PROTO ((mpz_srcptr, int));
|
||||||
|
void mpz_sqrt _PROTO ((mpz_ptr, mpz_srcptr));
|
||||||
|
void mpz_sqrtrem _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr));
|
||||||
|
void mpz_sub _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_sub_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_tdiv_q _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_tdiv_q_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_tdiv_q_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_tdiv_qr _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_tdiv_qr_ui _PROTO ((mpz_ptr, mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_tdiv_r _PROTO ((mpz_ptr, mpz_srcptr, mpz_srcptr));
|
||||||
|
void mpz_tdiv_r_2exp _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_tdiv_r_ui _PROTO ((mpz_ptr, mpz_srcptr, unsigned long int));
|
||||||
|
void mpz_ui_pow_ui _PROTO ((mpz_ptr, unsigned long int, unsigned long int));
|
||||||
|
|
||||||
|
/**************** Rational (i.e. Q) routines. ****************/
|
||||||
|
|
||||||
|
void mpq_init _PROTO ((mpq_ptr));
|
||||||
|
void mpq_clear _PROTO ((mpq_ptr));
|
||||||
|
void mpq_set _PROTO ((mpq_ptr, mpq_srcptr));
|
||||||
|
void mpq_set_ui _PROTO ((mpq_ptr, unsigned long int, unsigned long int));
|
||||||
|
void mpq_set_si _PROTO ((mpq_ptr, signed long int, unsigned long int));
|
||||||
|
void mpq_add _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
|
||||||
|
void mpq_sub _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
|
||||||
|
void mpq_mul _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
|
||||||
|
void mpq_div _PROTO ((mpq_ptr, mpq_srcptr, mpq_srcptr));
|
||||||
|
void mpq_neg _PROTO ((mpq_ptr, mpq_srcptr));
|
||||||
|
int mpq_cmp _PROTO ((mpq_srcptr, mpq_srcptr));
|
||||||
|
int mpq_cmp_ui _PROTO ((mpq_srcptr, unsigned long int, unsigned long int));
|
||||||
|
void mpq_inv _PROTO ((mpq_ptr, mpq_srcptr));
|
||||||
|
void mpq_set_num _PROTO ((mpq_ptr, mpz_srcptr));
|
||||||
|
void mpq_set_den _PROTO ((mpq_ptr, mpz_srcptr));
|
||||||
|
void mpq_get_num _PROTO ((mpz_ptr, mpq_srcptr));
|
||||||
|
void mpq_get_den _PROTO ((mpz_ptr, mpq_srcptr));
|
||||||
|
double mpq_get_d _PROTO ((mpq_srcptr));
|
||||||
|
void mpq_canonicalize _PROTO ((mpq_ptr));
|
||||||
|
|
||||||
|
/**************** Float (i.e. F) routines. ****************/
|
||||||
|
|
||||||
|
void mpf_abs _PROTO ((mpf_ptr, mpf_srcptr));
|
||||||
|
void mpf_add _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
|
||||||
|
void mpf_add_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
|
||||||
|
void mpf_clear _PROTO ((mpf_ptr));
|
||||||
|
int mpf_cmp _PROTO ((mpf_srcptr, mpf_srcptr));
|
||||||
|
int mpf_cmp_si _PROTO ((mpf_srcptr, signed long int));
|
||||||
|
int mpf_cmp_ui _PROTO ((mpf_srcptr, unsigned long int));
|
||||||
|
void mpf_div _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
|
||||||
|
void mpf_div_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
|
||||||
|
void mpf_div_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
|
||||||
|
void mpf_dump _PROTO ((mpf_srcptr));
|
||||||
|
int mpf_eq _PROTO ((mpf_srcptr, mpf_srcptr, unsigned long int));
|
||||||
|
unsigned long int mpf_get_prec _PROTO ((mpf_srcptr));
|
||||||
|
char *mpf_get_str _PROTO ((char *, mp_exp_t *, int, size_t, mpf_srcptr));
|
||||||
|
void mpf_init _PROTO ((mpf_ptr));
|
||||||
|
void mpf_init2 _PROTO ((mpf_ptr, unsigned long int));
|
||||||
|
#ifdef _GMP_H_HAVE_FILE
|
||||||
|
size_t mpf_inp_str _PROTO ((mpf_ptr, FILE *, int));
|
||||||
|
#endif
|
||||||
|
void mpf_init_set _PROTO ((mpf_ptr, mpf_srcptr));
|
||||||
|
void mpf_init_set_d _PROTO ((mpf_ptr, double));
|
||||||
|
void mpf_init_set_si _PROTO ((mpf_ptr, signed long int));
|
||||||
|
int mpf_init_set_str _PROTO ((mpf_ptr, char *, int));
|
||||||
|
void mpf_init_set_ui _PROTO ((mpf_ptr, unsigned long int));
|
||||||
|
void mpf_mul _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
|
||||||
|
void mpf_mul_2exp _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
|
||||||
|
void mpf_mul_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
|
||||||
|
void mpf_neg _PROTO ((mpf_ptr, mpf_srcptr));
|
||||||
|
#ifdef _GMP_H_HAVE_FILE
|
||||||
|
size_t mpf_out_str _PROTO ((FILE *, int, size_t, mpf_srcptr));
|
||||||
|
#endif
|
||||||
|
void mpf_random2 _PROTO ((mpf_ptr, mp_size_t, mp_exp_t));
|
||||||
|
void mpf_reldiff _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
|
||||||
|
void mpf_set _PROTO ((mpf_ptr, mpf_srcptr));
|
||||||
|
void mpf_set_d _PROTO ((mpf_ptr, double));
|
||||||
|
void mpf_set_default_prec _PROTO ((unsigned long int));
|
||||||
|
void mpf_set_prec _PROTO ((mpf_ptr, unsigned long int));
|
||||||
|
void mpf_set_prec_raw _PROTO ((mpf_ptr, unsigned long int));
|
||||||
|
void mpf_set_si _PROTO ((mpf_ptr, signed long int));
|
||||||
|
int mpf_set_str _PROTO ((mpf_ptr, const char *, int));
|
||||||
|
void mpf_set_ui _PROTO ((mpf_ptr, unsigned long int));
|
||||||
|
size_t mpf_size _PROTO ((mpf_srcptr));
|
||||||
|
void mpf_sqrt _PROTO ((mpf_ptr, mpf_srcptr));
|
||||||
|
void mpf_sqrt_ui _PROTO ((mpf_ptr, unsigned long int));
|
||||||
|
void mpf_sub _PROTO ((mpf_ptr, mpf_srcptr, mpf_srcptr));
|
||||||
|
void mpf_sub_ui _PROTO ((mpf_ptr, mpf_srcptr, unsigned long int));
|
||||||
|
void mpf_ui_div _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
|
||||||
|
void mpf_ui_sub _PROTO ((mpf_ptr, unsigned long int, mpf_srcptr));
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
/************ Low level positive-integer (i.e. N) routines. ************/
|
||||||
|
|
||||||
|
/* This is ugly, but we need to make usr calls reach the prefixed function. */
|
||||||
|
#define mpn_add __MPN(add)
|
||||||
|
#define mpn_add_1 __MPN(add_1)
|
||||||
|
#define mpn_add_n __MPN(add_n)
|
||||||
|
#define mpn_addmul_1 __MPN(addmul_1)
|
||||||
|
#define mpn_bdivmod __MPN(bdivmod)
|
||||||
|
#define mpn_cmp __MPN(cmp)
|
||||||
|
#define mpn_divmod_1 __MPN(divmod_1)
|
||||||
|
#define mpn_divrem __MPN(divrem)
|
||||||
|
#define mpn_divrem_1 __MPN(divrem_1)
|
||||||
|
#define mpn_dump __MPN(dump)
|
||||||
|
#define mpn_gcd __MPN(gcd)
|
||||||
|
#define mpn_gcd_1 __MPN(gcd_1)
|
||||||
|
#define mpn_gcdext __MPN(gcdext)
|
||||||
|
#define mpn_get_str __MPN(get_str)
|
||||||
|
#define mpn_hamdist __MPN(hamdist)
|
||||||
|
#define mpn_lshift __MPN(lshift)
|
||||||
|
#define mpn_mod_1 __MPN(mod_1)
|
||||||
|
#define mpn_mul __MPN(mul)
|
||||||
|
#define mpn_mul_1 __MPN(mul_1)
|
||||||
|
#define mpn_mul_n __MPN(mul_n)
|
||||||
|
#define mpn_perfect_square_p __MPN(perfect_square_p)
|
||||||
|
#define mpn_popcount __MPN(popcount)
|
||||||
|
#define mpn_preinv_mod_1 __MPN(preinv_mod_1)
|
||||||
|
#define mpn_random2 __MPN(random2)
|
||||||
|
#define mpn_rshift __MPN(rshift)
|
||||||
|
#define mpn_scan0 __MPN(scan0)
|
||||||
|
#define mpn_scan1 __MPN(scan1)
|
||||||
|
#define mpn_set_str __MPN(set_str)
|
||||||
|
#define mpn_sqrtrem __MPN(sqrtrem)
|
||||||
|
#define mpn_sub __MPN(sub)
|
||||||
|
#define mpn_sub_1 __MPN(sub_1)
|
||||||
|
#define mpn_sub_n __MPN(sub_n)
|
||||||
|
#define mpn_submul_1 __MPN(submul_1)
|
||||||
|
#define mpn_udiv_w_sdiv __MPN(udiv_w_sdiv)
|
||||||
|
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
mp_limb_t mpn_add _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
|
||||||
|
mp_limb_t mpn_add_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
mp_limb_t mpn_add_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_addmul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
mp_limb_t mpn_bdivmod _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_srcptr, mp_size_t, unsigned long int));
|
||||||
|
int mpn_cmp _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_divmod_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
mp_limb_t mpn_divrem _PROTO ((mp_ptr, mp_size_t, mp_ptr, mp_size_t, mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_divrem_1 _PROTO ((mp_ptr, mp_size_t, mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
void mpn_dump _PROTO ((mp_srcptr, mp_size_t));
|
||||||
|
mp_size_t mpn_gcd _PROTO ((mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_gcd_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
mp_size_t mpn_gcdext _PROTO ((mp_ptr, mp_ptr, mp_ptr, mp_size_t, mp_ptr, mp_size_t));
|
||||||
|
size_t mpn_get_str _PROTO ((unsigned char *, int, mp_ptr, mp_size_t));
|
||||||
|
unsigned long int mpn_hamdist _PROTO ((mp_srcptr, mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_lshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
|
||||||
|
mp_limb_t mpn_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
mp_limb_t mpn_mul _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_mul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
void mpn_mul_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
|
||||||
|
int mpn_perfect_square_p _PROTO ((mp_srcptr, mp_size_t));
|
||||||
|
unsigned long int mpn_popcount _PROTO ((mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_preinv_mod_1 _PROTO ((mp_srcptr, mp_size_t, mp_limb_t, mp_limb_t));
|
||||||
|
void mpn_random2 _PROTO ((mp_ptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_rshift _PROTO ((mp_ptr, mp_srcptr, mp_size_t, unsigned int));
|
||||||
|
unsigned long int mpn_scan0 _PROTO ((mp_srcptr, unsigned long int));
|
||||||
|
unsigned long int mpn_scan1 _PROTO ((mp_srcptr, unsigned long int));
|
||||||
|
mp_size_t mpn_set_str _PROTO ((mp_ptr, const unsigned char *, size_t, int));
|
||||||
|
mp_size_t mpn_sqrtrem _PROTO ((mp_ptr, mp_ptr, mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_sub _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_srcptr,mp_size_t));
|
||||||
|
mp_limb_t mpn_sub_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
mp_limb_t mpn_sub_n _PROTO ((mp_ptr, mp_srcptr, mp_srcptr, mp_size_t));
|
||||||
|
mp_limb_t mpn_submul_1 _PROTO ((mp_ptr, mp_srcptr, mp_size_t, mp_limb_t));
|
||||||
|
#if defined (__cplusplus)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined (__GNUC__) || defined (_FORCE_INLINES)
|
||||||
|
_EXTERN_INLINE mp_limb_t
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
mpn_add_1 (register mp_ptr res_ptr,
|
||||||
|
register mp_srcptr s1_ptr,
|
||||||
|
register mp_size_t s1_size,
|
||||||
|
register mp_limb_t s2_limb)
|
||||||
|
#else
|
||||||
|
mpn_add_1 (res_ptr, s1_ptr, s1_size, s2_limb)
|
||||||
|
register mp_ptr res_ptr;
|
||||||
|
register mp_srcptr s1_ptr;
|
||||||
|
register mp_size_t s1_size;
|
||||||
|
register mp_limb_t s2_limb;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
register mp_limb_t x;
|
||||||
|
|
||||||
|
x = *s1_ptr++;
|
||||||
|
s2_limb = x + s2_limb;
|
||||||
|
*res_ptr++ = s2_limb;
|
||||||
|
if (s2_limb < x)
|
||||||
|
{
|
||||||
|
while (--s1_size != 0)
|
||||||
|
{
|
||||||
|
x = *s1_ptr++ + 1;
|
||||||
|
*res_ptr++ = x;
|
||||||
|
if (x != 0)
|
||||||
|
goto fin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fin:
|
||||||
|
if (res_ptr != s1_ptr)
|
||||||
|
{
|
||||||
|
mp_size_t i;
|
||||||
|
for (i = 0; i < s1_size - 1; i++)
|
||||||
|
res_ptr[i] = s1_ptr[i];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_EXTERN_INLINE mp_limb_t
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
mpn_add (register mp_ptr res_ptr,
|
||||||
|
register mp_srcptr s1_ptr,
|
||||||
|
register mp_size_t s1_size,
|
||||||
|
register mp_srcptr s2_ptr,
|
||||||
|
register mp_size_t s2_size)
|
||||||
|
#else
|
||||||
|
mpn_add (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
|
||||||
|
register mp_ptr res_ptr;
|
||||||
|
register mp_srcptr s1_ptr;
|
||||||
|
register mp_size_t s1_size;
|
||||||
|
register mp_srcptr s2_ptr;
|
||||||
|
register mp_size_t s2_size;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
mp_limb_t cy_limb = 0;
|
||||||
|
|
||||||
|
if (s2_size != 0)
|
||||||
|
cy_limb = mpn_add_n (res_ptr, s1_ptr, s2_ptr, s2_size);
|
||||||
|
|
||||||
|
if (s1_size - s2_size != 0)
|
||||||
|
cy_limb = mpn_add_1 (res_ptr + s2_size,
|
||||||
|
s1_ptr + s2_size,
|
||||||
|
s1_size - s2_size,
|
||||||
|
cy_limb);
|
||||||
|
return cy_limb;
|
||||||
|
}
|
||||||
|
|
||||||
|
_EXTERN_INLINE mp_limb_t
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
mpn_sub_1 (register mp_ptr res_ptr,
|
||||||
|
register mp_srcptr s1_ptr,
|
||||||
|
register mp_size_t s1_size,
|
||||||
|
register mp_limb_t s2_limb)
|
||||||
|
#else
|
||||||
|
mpn_sub_1 (res_ptr, s1_ptr, s1_size, s2_limb)
|
||||||
|
register mp_ptr res_ptr;
|
||||||
|
register mp_srcptr s1_ptr;
|
||||||
|
register mp_size_t s1_size;
|
||||||
|
register mp_limb_t s2_limb;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
register mp_limb_t x;
|
||||||
|
|
||||||
|
x = *s1_ptr++;
|
||||||
|
s2_limb = x - s2_limb;
|
||||||
|
*res_ptr++ = s2_limb;
|
||||||
|
if (s2_limb > x)
|
||||||
|
{
|
||||||
|
while (--s1_size != 0)
|
||||||
|
{
|
||||||
|
x = *s1_ptr++;
|
||||||
|
*res_ptr++ = x - 1;
|
||||||
|
if (x != 0)
|
||||||
|
goto fin;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fin:
|
||||||
|
if (res_ptr != s1_ptr)
|
||||||
|
{
|
||||||
|
mp_size_t i;
|
||||||
|
for (i = 0; i < s1_size - 1; i++)
|
||||||
|
res_ptr[i] = s1_ptr[i];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_EXTERN_INLINE mp_limb_t
|
||||||
|
#if defined (__STDC__) || defined (__cplusplus)
|
||||||
|
mpn_sub (register mp_ptr res_ptr,
|
||||||
|
register mp_srcptr s1_ptr,
|
||||||
|
register mp_size_t s1_size,
|
||||||
|
register mp_srcptr s2_ptr,
|
||||||
|
register mp_size_t s2_size)
|
||||||
|
#else
|
||||||
|
mpn_sub (res_ptr, s1_ptr, s1_size, s2_ptr, s2_size)
|
||||||
|
register mp_ptr res_ptr;
|
||||||
|
register mp_srcptr s1_ptr;
|
||||||
|
register mp_size_t s1_size;
|
||||||
|
register mp_srcptr s2_ptr;
|
||||||
|
register mp_size_t s2_size;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
mp_limb_t cy_limb = 0;
|
||||||
|
|
||||||
|
if (s2_size != 0)
|
||||||
|
cy_limb = mpn_sub_n (res_ptr, s1_ptr, s2_ptr, s2_size);
|
||||||
|
|
||||||
|
if (s1_size - s2_size != 0)
|
||||||
|
cy_limb = mpn_sub_1 (res_ptr + s2_size,
|
||||||
|
s1_ptr + s2_size,
|
||||||
|
s1_size - s2_size,
|
||||||
|
cy_limb);
|
||||||
|
return cy_limb;
|
||||||
|
}
|
||||||
|
#endif /* __GNUC__ */
|
||||||
|
|
||||||
|
/* Allow faster testing for negative, zero, and positive. */
|
||||||
|
#define mpz_sgn(Z) ((Z)->_mp_size < 0 ? -1 : (Z)->_mp_size > 0)
|
||||||
|
#define mpf_sgn(F) ((F)->_mp_size < 0 ? -1 : (F)->_mp_size > 0)
|
||||||
|
#define mpq_sgn(Q) ((Q)->_mp_num._mp_size < 0 ? -1 : (Q)->_mp_num._mp_size > 0)
|
||||||
|
|
||||||
|
/* Allow direct user access to numerator and denominator of a mpq_t object. */
|
||||||
|
#define mpq_numref(Q) (&((Q)->_mp_num))
|
||||||
|
#define mpq_denref(Q) (&((Q)->_mp_den))
|
||||||
|
|
||||||
|
/* When using GCC, optimize certain common comparisons. */
|
||||||
|
#if defined (__GNUC__)
|
||||||
|
#define mpz_cmp_ui(Z,UI) \
|
||||||
|
(__builtin_constant_p (UI) && (UI) == 0 \
|
||||||
|
? mpz_sgn (Z) : mpz_cmp_ui (Z,UI))
|
||||||
|
#define mpz_cmp_si(Z,UI) \
|
||||||
|
(__builtin_constant_p (UI) && (UI) == 0 ? mpz_sgn (Z) \
|
||||||
|
: __builtin_constant_p (UI) && (UI) > 0 ? mpz_cmp_ui (Z,UI) \
|
||||||
|
: mpz_cmp_si (Z,UI))
|
||||||
|
#define mpq_cmp_ui(Q,NUI,DUI) \
|
||||||
|
(__builtin_constant_p (NUI) && (NUI) == 0 \
|
||||||
|
? mpq_sgn (Q) : mpq_cmp_ui (Q,NUI,DUI))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define mpn_divmod(qp,np,nsize,dp,dsize) mpn_divrem (qp,0,np,nsize,dp,dsize)
|
||||||
|
#if 0
|
||||||
|
#define mpn_divmod_1(qp,np,nsize,dlimb) mpn_divrem_1 (qp,0,np,nsize,dlimb)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Compatibility with GMP 1. */
|
||||||
|
#define mpz_mdiv mpz_fdiv_q
|
||||||
|
#define mpz_mdivmod mpz_fdiv_qr
|
||||||
|
#define mpz_mmod mpz_fdiv_r
|
||||||
|
#define mpz_mdiv_ui mpz_fdiv_q_ui
|
||||||
|
#define mpz_mdivmod_ui(q,r,n,d) \
|
||||||
|
((r == 0) ? mpz_fdiv_q_ui (q,n,d) : mpz_fdiv_qr_ui (q,r,n,d))
|
||||||
|
#define mpz_mmod_ui(r,n,d) \
|
||||||
|
((r == 0) ? mpz_fdiv_ui (n,d) : mpz_fdiv_r_ui (r,n,d))
|
||||||
|
|
||||||
|
/* Useful synonyms, but not quite compatible with GMP 1. */
|
||||||
|
#define mpz_div mpz_fdiv_q
|
||||||
|
#define mpz_divmod mpz_fdiv_qr
|
||||||
|
#define mpz_div_ui mpz_fdiv_q_ui
|
||||||
|
#define mpz_divmod_ui mpz_fdiv_qr_ui
|
||||||
|
#define mpz_mod_ui mpz_fdiv_r_ui
|
||||||
|
#define mpz_div_2exp mpz_fdiv_q_2exp
|
||||||
|
#define mpz_mod_2exp mpz_fdiv_r_2exp
|
||||||
|
|
||||||
|
#define __GNU_MP_VERSION 2
|
||||||
|
#define __GNU_MP_VERSION_MINOR 0
|
||||||
|
#define __GMP_H__
|
||||||
|
#endif /* __GMP_H__ */
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
/* Internal header for proving correct grouping in strings of numbers.
|
||||||
|
Copyright (C) 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#ifndef MAX
|
||||||
|
#define MAX(a,b) ({ typeof(a) _a = (a); typeof(b) _b = (b); \
|
||||||
|
_a > _b ? _a : _b; })
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Find the maximum prefix of the string between BEGIN and END which
|
||||||
|
satisfies the grouping rules. It is assumed that at least one digit
|
||||||
|
follows BEGIN directly. */
|
||||||
|
|
||||||
|
static inline const STRING_TYPE *
|
||||||
|
correctly_grouped_prefix (const STRING_TYPE *begin, const STRING_TYPE *end,
|
||||||
|
#ifdef USE_WIDE_CHAR
|
||||||
|
wchar_t thousands,
|
||||||
|
#else
|
||||||
|
const char *thousands,
|
||||||
|
#endif
|
||||||
|
const char *grouping)
|
||||||
|
{
|
||||||
|
#ifndef USE_WIDE_CHAR
|
||||||
|
size_t thousands_len;
|
||||||
|
int cnt;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (grouping == NULL)
|
||||||
|
return end;
|
||||||
|
|
||||||
|
#ifndef USE_WIDE_CHAR
|
||||||
|
thousands_len = strlen (thousands);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while (end > begin)
|
||||||
|
{
|
||||||
|
const STRING_TYPE *cp = end - 1;
|
||||||
|
const char *gp = grouping;
|
||||||
|
|
||||||
|
/* Check first group. */
|
||||||
|
while (cp >= begin)
|
||||||
|
{
|
||||||
|
#ifdef USE_WIDE_CHAR
|
||||||
|
if (*cp == thousands)
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
if (cp[thousands_len - 1] == *thousands)
|
||||||
|
{
|
||||||
|
for (cnt = 1; thousands[cnt] != '\0'; ++cnt)
|
||||||
|
if (thousands[cnt] != cp[thousands_len - 1 - cnt])
|
||||||
|
break;
|
||||||
|
if (thousands[cnt] == '\0')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
--cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We allow the representation to contain no grouping at all even if
|
||||||
|
the locale specifies we can have grouping. */
|
||||||
|
if (cp < begin)
|
||||||
|
return end;
|
||||||
|
|
||||||
|
if (end - cp == (int) *gp + 1)
|
||||||
|
{
|
||||||
|
/* This group matches the specification. */
|
||||||
|
|
||||||
|
const STRING_TYPE *new_end;
|
||||||
|
|
||||||
|
if (cp < begin)
|
||||||
|
/* There is just one complete group. We are done. */
|
||||||
|
return end;
|
||||||
|
|
||||||
|
/* CP points to a thousands separator character. The preceding
|
||||||
|
remainder of the string from BEGIN to NEW_END is the part we
|
||||||
|
will consider if there is a grouping error in this trailing
|
||||||
|
portion from CP to END. */
|
||||||
|
new_end = cp - 1;
|
||||||
|
|
||||||
|
/* Loop while the grouping is correct. */
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
/* Get the next grouping rule. */
|
||||||
|
++gp;
|
||||||
|
if (*gp == 0)
|
||||||
|
/* If end is reached use last rule. */
|
||||||
|
--gp;
|
||||||
|
|
||||||
|
/* Skip the thousands separator. */
|
||||||
|
--cp;
|
||||||
|
|
||||||
|
if (*gp == CHAR_MAX
|
||||||
|
#if CHAR_MIN < 0
|
||||||
|
|| *gp < 0
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
{
|
||||||
|
/* No more thousands separators are allowed to follow. */
|
||||||
|
while (cp >= begin)
|
||||||
|
{
|
||||||
|
#ifdef USE_WIDE_CHAR
|
||||||
|
if (*cp == thousands)
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
|
||||||
|
if (thousands[cnt] != cp[thousands_len - cnt - 1])
|
||||||
|
break;
|
||||||
|
if (thousands[cnt] == '\0')
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
--cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cp < begin)
|
||||||
|
/* OK, only digits followed. */
|
||||||
|
return end;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Check the next group. */
|
||||||
|
const STRING_TYPE *group_end = cp;
|
||||||
|
|
||||||
|
while (cp >= begin)
|
||||||
|
{
|
||||||
|
#ifdef USE_WIDE_CHAR
|
||||||
|
if (*cp == thousands)
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
for (cnt = 0; thousands[cnt] != '\0'; ++cnt)
|
||||||
|
if (thousands[cnt] != cp[thousands_len - cnt - 1])
|
||||||
|
break;
|
||||||
|
if (thousands[cnt] == '\0')
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
--cp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cp < begin && group_end - cp <= (int) *gp)
|
||||||
|
/* Final group is correct. */
|
||||||
|
return end;
|
||||||
|
|
||||||
|
if (cp < begin || group_end - cp != (int) *gp)
|
||||||
|
/* Incorrect group. Punt. */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The trailing portion of the string starting at NEW_END
|
||||||
|
contains a grouping error. So we will look for a correctly
|
||||||
|
grouped number in the preceding portion instead. */
|
||||||
|
end = new_end;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Even the first group was wrong; determine maximum shift. */
|
||||||
|
if (end - cp > (int) *gp + 1)
|
||||||
|
end = cp + (int) *gp + 1;
|
||||||
|
else if (cp < begin)
|
||||||
|
/* This number does not fill the first group, but is correct. */
|
||||||
|
return end;
|
||||||
|
else
|
||||||
|
/* CP points to a thousands separator character. */
|
||||||
|
end = cp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return MAX (begin, end);
|
||||||
|
}
|
||||||
@@ -0,0 +1,445 @@
|
|||||||
|
/* Check system header files for ISO 9899:1990 (ISO C) compliance.
|
||||||
|
Copyright (C) 1996,97,98,99,2001,02 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Jens Schweikhardt <schweikh@noc.dfn.de>, 1996.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/* This is a simple minded program that tries to find illegal macro
|
||||||
|
definitions in system header files. Illegal macro definitions are
|
||||||
|
those not from the implementation namespace (i.e. not starting with
|
||||||
|
an underscore) or not matching any identifier mandated by The
|
||||||
|
Standard. Some common macro names are considered okay, e.g. all those
|
||||||
|
beginning with E (which may be defined in <errno.h>) or ending in
|
||||||
|
_MAX. See the arrays prefix[] and suffix[] below for details.
|
||||||
|
|
||||||
|
In a compliant implementation no other macros can be defined, because
|
||||||
|
you could write strictly conforming programs that may fail to compile
|
||||||
|
due to syntax errors: suppose <stdio.h> defines PIPE_BUF, then the
|
||||||
|
conforming
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdio.h> <- or where the bogus macro is defined
|
||||||
|
#include <string.h>
|
||||||
|
#define STR(x) #x
|
||||||
|
#define XSTR(x) STR(x)
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
int PIPE_BUF = 0;
|
||||||
|
assert (strcmp ("PIPE_BUF", XSTR (PIPE_BUF)) == 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
is expected to compile and meet the assertion. If it does not, your
|
||||||
|
compiler compiles some other language than Standard C.
|
||||||
|
|
||||||
|
REQUIREMENTS:
|
||||||
|
This program calls gcc to get the list of defined macros. If you
|
||||||
|
don't have gcc you're probably out of luck unless your compiler or
|
||||||
|
preprocessor has something similar to gcc's -dM option. Tune
|
||||||
|
PRINT_MACROS in this case. This program assumes headers are found
|
||||||
|
under /usr/include and that there is a writable /tmp directory.
|
||||||
|
Tune SYSTEM_INCLUDE if your system differs.
|
||||||
|
#define BROKEN_SYSTEM if system(NULL) bombs -- one more violation
|
||||||
|
of ISO C, by the way.
|
||||||
|
|
||||||
|
OUTPUT:
|
||||||
|
Each header file name is printed, followed by illegal macro names
|
||||||
|
and their definition. For the above example, you would see
|
||||||
|
...
|
||||||
|
/usr/include/stdio.h
|
||||||
|
#define PIPE_BUF 5120
|
||||||
|
...
|
||||||
|
If your implementation does not yet incorporate Amendment 1 you
|
||||||
|
will see messages about iso646.h, wctype.h and wchar.h not being
|
||||||
|
found. */
|
||||||
|
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
# define _GNU_SOURCE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define HEADER_MAX 256
|
||||||
|
|
||||||
|
static const char *macrofile;
|
||||||
|
|
||||||
|
/* ISO C header names including Amendment 1 (without ".h" suffix). */
|
||||||
|
static char *header[] =
|
||||||
|
{
|
||||||
|
"assert", "ctype", "errno", "float", "iso646", "limits", "locale",
|
||||||
|
"math", "setjmp", "signal", "stdarg", "stddef", "stdio", "stdlib",
|
||||||
|
"string", "time", "wchar", "wctype"
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Macros with these prefixes are considered okay. */
|
||||||
|
static char *prefix[] =
|
||||||
|
{
|
||||||
|
"_", "E", "is", "str", "mem", "SIG", "FLT_", "DBL_", "LDBL_",
|
||||||
|
"LC_", "wmem", "wcs"
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Macros with these suffixes are considered okay. Will not work for
|
||||||
|
parametrized macros with arguments. */
|
||||||
|
static char *suffix[] =
|
||||||
|
{
|
||||||
|
"_MAX", "_MIN"
|
||||||
|
};
|
||||||
|
|
||||||
|
/* These macros are considered okay. In fact, these are just more prefixes. */
|
||||||
|
static char *macros[] =
|
||||||
|
{
|
||||||
|
"BUFSIZ", "CHAR_BIT", "CHAR_MAX", "CHAR_MIN", "CLOCKS_PER_SEC",
|
||||||
|
"DBL_DIG", "DBL_EPSILON", "DBL_MANT_DIG", "DBL_MAX",
|
||||||
|
"DBL_MAX_10_EXP", "DBL_MAX_EXP", "DBL_MIN", "DBL_MIN_10_EXP",
|
||||||
|
"DBL_MIN_EXP", "EDOM", "EILSEQ", "EOF", "ERANGE", "EXIT_FAILURE",
|
||||||
|
"EXIT_SUCCESS", "FILENAME_MAX", "FLT_DIG", "FLT_EPSILON",
|
||||||
|
"FLT_MANT_DIG", "FLT_MAX", "FLT_MAX_10_EXP", "FLT_MAX_EXP",
|
||||||
|
"FLT_MIN", "FLT_MIN_10_EXP", "FLT_MIN_EXP", "FLT_RADIX",
|
||||||
|
"FLT_ROUNDS", "FOPEN_MAX", "HUGE_VAL", "INT_MAX", "INT_MIN",
|
||||||
|
"LC_ALL", "LC_COLLATE", "LC_CTYPE", "LC_MONETARY", "LC_NUMERIC",
|
||||||
|
"LC_TIME", "LDBL_DIG", "LDBL_EPSILON", "LDBL_MANT_DIG", "LDBL_MAX",
|
||||||
|
"LDBL_MAX_10_EXP", "LDBL_MAX_EXP", "LDBL_MIN", "LDBL_MIN_10_EXP",
|
||||||
|
"LDBL_MIN_EXP", "LONG_MAX", "LONG_MIN", "L_tmpnam", "MB_CUR_MAX",
|
||||||
|
"MB_LEN_MAX", "NDEBUG", "NULL", "RAND_MAX", "SCHAR_MAX",
|
||||||
|
"SCHAR_MIN", "SEEK_CUR", "SEEK_END", "SEEK_SET", "SHRT_MAX",
|
||||||
|
"SHRT_MIN", "SIGABRT", "SIGFPE", "SIGILL", "SIGINT", "SIGSEGV",
|
||||||
|
"SIGTERM", "SIG_DFL", "SIG_ERR", "SIG_IGN", "TMP_MAX", "UCHAR_MAX",
|
||||||
|
"UINT_MAX", "ULONG_MAX", "USHRT_MAX", "WCHAR_MAX", "WCHAR_MIN",
|
||||||
|
"WEOF", "_IOFBF", "_IOLBF", "_IONBF", "abort", "abs", "acos",
|
||||||
|
"acosf", "acosl", "and", "and_eq", "asctime", "asin", "asinf",
|
||||||
|
"asinl", "assert", "atan", "atan2", "atan2f", "atan2l", "atanf",
|
||||||
|
"atanl", "atexit", "atof", "atoi", "atol", "bitand", "bitor",
|
||||||
|
"bsearch", "btowc", "calloc", "ceil", "ceilf", "ceill", "clearerr",
|
||||||
|
"clock", "clock_t", "compl", "cos", "cosf", "cosh", "coshf",
|
||||||
|
"coshl", "cosl", "ctime", "difftime", "div", "div_t", "errno",
|
||||||
|
"exit", "exp", "expf", "expl", "fabs", "fabsf", "fabsl", "fclose",
|
||||||
|
"feof", "ferror", "fflush", "fgetc", "fgetpos", "fgets", "fgetwc",
|
||||||
|
"fgetws", "floor", "floorf", "floorl", "fmod", "fmodf", "fmodl",
|
||||||
|
"fopen", "fprintf", "fputc", "fputs", "fputwc", "fputws", "fread",
|
||||||
|
"free", "freopen", "frexp", "frexpf", "frexpl", "fscanf", "fseek",
|
||||||
|
"fsetpos", "ftell", "fwide", "fwprintf", "fwrite", "fwscanf",
|
||||||
|
"getc", "getchar", "getenv", "gets", "getwc", "getwchar", "gmtime",
|
||||||
|
"isalnum", "isalpha", "iscntrl", "isdigit", "isgraph", "islower",
|
||||||
|
"isprint", "ispunct", "isspace", "isupper", "iswalnum", "iswalpha",
|
||||||
|
"iswcntrl", "iswctype", "iswdigit", "iswgraph", "iswlower",
|
||||||
|
"iswprint", "iswpunct", "iswspace", "iswupper", "iswxdigit",
|
||||||
|
"isxdigit", "labs", "ldexp", "ldexpf", "ldexpl", "ldiv", "ldiv_t",
|
||||||
|
"localeconv", "localtime", "log", "log10", "log10f", "log10l",
|
||||||
|
"logf", "logl", "longjmp", "malloc", "mblen", "mbrlen", "mbrtowc",
|
||||||
|
"mbsinit", "mbsrtowcs", "mbstate_t", "mbstowcs", "mbtowc", "memchr",
|
||||||
|
"memcmp", "memcpy", "memmove", "memset", "mktime", "modf", "modff",
|
||||||
|
"modfl", "not", "not_eq", "offsetof", "or", "or_eq", "perror",
|
||||||
|
"pow", "powf", "powl", "printf", "ptrdiff_t", "putc", "putchar",
|
||||||
|
"puts", "putwc", "putwchar", "qsort", "raise", "rand", "realloc",
|
||||||
|
"remove", "rename", "rewind", "scanf", "setbuf", "setjmp",
|
||||||
|
"setlocale", "setvbuf", "sig_atomic_t", "signal", "sin", "sinf",
|
||||||
|
"sinh", "sinhf", "sinhl", "sinl", "size_t", "sprintf", "sqrt",
|
||||||
|
"sqrtf", "sqrtl", "srand", "sscanf", "stderr", "stdin", "stdout",
|
||||||
|
"strcat", "strchr", "strcmp", "strcoll", "strcpy", "strcspn",
|
||||||
|
"strerror", "strftime", "strlen", "strncat", "strncmp", "strncpy",
|
||||||
|
"strpbrk", "strrchr", "strspn", "strstr", "strtod", "strtok",
|
||||||
|
"strtol", "strtoul", "strxfrm", "swprintf", "swscanf", "system",
|
||||||
|
"tan", "tanf", "tanh", "tanhf", "tanhl", "tanl", "time", "time_t",
|
||||||
|
"tmpfile", "tmpnam", "tolower", "toupper", "towctrans", "towlower",
|
||||||
|
"towupper", "ungetc", "ungetwc", "va_arg", "va_copy", "va_end", "va_start",
|
||||||
|
"vfprintf", "vfwprintf", "vprintf", "vsprintf", "vswprintf",
|
||||||
|
"vwprintf", "wchar_t", "wcrtomb", "wcscat", "wcschr", "wcscmp",
|
||||||
|
"wcscoll", "wcscpy", "wcscspn", "wcsftime", "wcslen", "wcsncat",
|
||||||
|
"wcsncmp", "wcsncpy", "wcspbrk", "wcsrchr", "wcsrtombs", "wcsspn",
|
||||||
|
"wcsstr", "wcstod", "wcstok", "wcstol", "wcstombs", "wcstoul",
|
||||||
|
"wcsxfrm", "wctob", "wctomb", "wctrans", "wctrans_t", "wctype",
|
||||||
|
"wctype_t", "wint_t", "wmemchr", "wmemcmp", "wmemcpy", "wmemmove",
|
||||||
|
"wmemset", "wprintf", "wscanf", "xor", "xor_eq"
|
||||||
|
};
|
||||||
|
|
||||||
|
#define NUMBER_OF_HEADERS (sizeof header / sizeof *header)
|
||||||
|
#define NUMBER_OF_PREFIXES (sizeof prefix / sizeof *prefix)
|
||||||
|
#define NUMBER_OF_SUFFIXES (sizeof suffix / sizeof *suffix)
|
||||||
|
#define NUMBER_OF_MACROS (sizeof macros / sizeof *macros)
|
||||||
|
|
||||||
|
|
||||||
|
/* Format string to build command to invoke compiler. */
|
||||||
|
static const char fmt[] = "\
|
||||||
|
echo \"#include <%s>\" |\
|
||||||
|
%s -E -dM -ansi -pedantic %s -D_LIBC -D_ISOMAC -DNOT_IN_libc -I. \
|
||||||
|
-isystem `%s --print-prog-name=include` - 2> /dev/null > %s";
|
||||||
|
|
||||||
|
|
||||||
|
/* The compiler we use (given on the command line). */
|
||||||
|
char *CC;
|
||||||
|
/* The -I parameters for CC to find all headers. */
|
||||||
|
char *INC;
|
||||||
|
|
||||||
|
static char *xstrndup (const char *, size_t);
|
||||||
|
static const char **get_null_defines (void);
|
||||||
|
static int check_header (const char *, const char **);
|
||||||
|
|
||||||
|
int
|
||||||
|
main (int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int h;
|
||||||
|
int result = 0;
|
||||||
|
const char **ignore_list;
|
||||||
|
|
||||||
|
CC = argc > 1 ? argv[1] : "gcc";
|
||||||
|
INC = argc > 2 ? argv[2] : "";
|
||||||
|
|
||||||
|
if (system (NULL) == 0)
|
||||||
|
{
|
||||||
|
puts ("Sorry, no command processor.");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* First get list of symbols which are defined by the compiler. */
|
||||||
|
ignore_list = get_null_defines ();
|
||||||
|
|
||||||
|
fputs ("Tested files:\n", stdout);
|
||||||
|
|
||||||
|
for (h = 0; h < NUMBER_OF_HEADERS; ++h)
|
||||||
|
{
|
||||||
|
char file_name[HEADER_MAX];
|
||||||
|
sprintf (file_name, "%s.h", header[h]);
|
||||||
|
result |= check_header (file_name, ignore_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The test suite should return errors but for now this is not
|
||||||
|
practical. Give a warning and ask the user to correct the bugs. */
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
xstrndup (const char *s, size_t n)
|
||||||
|
{
|
||||||
|
size_t len = n;
|
||||||
|
char *new = malloc (len + 1);
|
||||||
|
|
||||||
|
if (new == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
new[len] = '\0';
|
||||||
|
return memcpy (new, s, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const char **
|
||||||
|
get_null_defines (void)
|
||||||
|
{
|
||||||
|
char line[BUFSIZ], *command;
|
||||||
|
char **result = NULL;
|
||||||
|
size_t result_len = 0;
|
||||||
|
size_t result_max = 0;
|
||||||
|
FILE *input;
|
||||||
|
int first = 1;
|
||||||
|
|
||||||
|
macrofile = tmpnam (NULL);
|
||||||
|
|
||||||
|
command = malloc (sizeof fmt + sizeof "/dev/null" + 2 * strlen (CC)
|
||||||
|
+ strlen (INC) + strlen (macrofile));
|
||||||
|
|
||||||
|
if (command == NULL)
|
||||||
|
{
|
||||||
|
puts ("No more memory.");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf (command, fmt, "/dev/null", CC, INC, CC, macrofile);
|
||||||
|
|
||||||
|
if (system (command))
|
||||||
|
{
|
||||||
|
puts ("system() returned nonzero");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
free (command);
|
||||||
|
input = fopen (macrofile, "r");
|
||||||
|
|
||||||
|
if (input == NULL)
|
||||||
|
{
|
||||||
|
printf ("Could not read %s: ", macrofile);
|
||||||
|
perror (NULL);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fgets (line, sizeof line, input) != NULL)
|
||||||
|
{
|
||||||
|
int i, okay = 0;
|
||||||
|
size_t endmac;
|
||||||
|
char *start, *end;
|
||||||
|
if (strlen (line) < 9 || line[7] != ' ')
|
||||||
|
{ /* "#define A" */
|
||||||
|
printf ("Malformed input, expected '#define MACRO'\ngot '%s'\n",
|
||||||
|
line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line[8] == '_')
|
||||||
|
/* It's a safe identifier. */
|
||||||
|
continue;
|
||||||
|
if (result_len == result_max)
|
||||||
|
{
|
||||||
|
result_max += 10;
|
||||||
|
result = realloc (result, result_max * sizeof (char **));
|
||||||
|
if (result == NULL)
|
||||||
|
{
|
||||||
|
puts ("No more memory.");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
start = &line[8];
|
||||||
|
for (end = start + 1; !isspace (*end) && *end != '\0'; ++end)
|
||||||
|
;
|
||||||
|
result[result_len] = xstrndup (start, end - start);
|
||||||
|
|
||||||
|
if (strcmp (result[result_len], "NOT_IN_libc") != 0)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
fputs ("The following identifiers will be ignored since the compiler defines them\nby default:\n", stdout);
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
puts (result[result_len]);
|
||||||
|
}
|
||||||
|
++result_len;
|
||||||
|
}
|
||||||
|
if (result_len == result_max)
|
||||||
|
{
|
||||||
|
result_max += 1;
|
||||||
|
result = realloc (result, result_max * sizeof (char **));
|
||||||
|
if (result == NULL)
|
||||||
|
{
|
||||||
|
puts ("No more memory.");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result[result_len] = NULL;
|
||||||
|
fclose (input);
|
||||||
|
remove (macrofile);
|
||||||
|
|
||||||
|
return (const char **) result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
check_header (const char *file_name, const char **except)
|
||||||
|
{
|
||||||
|
char line[BUFSIZ], *command;
|
||||||
|
FILE *input;
|
||||||
|
int result = 0;
|
||||||
|
|
||||||
|
command = malloc (sizeof fmt + strlen (file_name) + 2 * strlen (CC)
|
||||||
|
+ strlen (INC) + strlen (macrofile));
|
||||||
|
|
||||||
|
if (command == NULL)
|
||||||
|
{
|
||||||
|
puts ("No more memory.");
|
||||||
|
exit (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
puts (file_name);
|
||||||
|
sprintf (command, fmt, file_name, CC, INC, CC, macrofile);
|
||||||
|
|
||||||
|
if (system (command))
|
||||||
|
{
|
||||||
|
puts ("system() returned nonzero");
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
|
free (command);
|
||||||
|
input = fopen (macrofile, "r");
|
||||||
|
|
||||||
|
if (input == NULL)
|
||||||
|
{
|
||||||
|
printf ("Could not read %s: ", macrofile);
|
||||||
|
perror (NULL);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (fgets (line, sizeof line, input) != NULL)
|
||||||
|
{
|
||||||
|
int i, okay = 0;
|
||||||
|
size_t endmac;
|
||||||
|
const char **cpp;
|
||||||
|
if (strlen (line) < 9 || line[7] != ' ')
|
||||||
|
{ /* "#define A" */
|
||||||
|
printf ("Malformed input, expected '#define MACRO'\ngot '%s'\n",
|
||||||
|
line);
|
||||||
|
result = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (i = 0; i < NUMBER_OF_PREFIXES; ++i)
|
||||||
|
{
|
||||||
|
if (!strncmp (line+8, prefix[i], strlen (prefix[i]))) {
|
||||||
|
++okay;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (okay)
|
||||||
|
continue;
|
||||||
|
for (i = 0; i < NUMBER_OF_MACROS; ++i)
|
||||||
|
{
|
||||||
|
if (!strncmp (line + 8, macros[i], strlen (macros[i])))
|
||||||
|
{
|
||||||
|
++okay;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (okay)
|
||||||
|
continue;
|
||||||
|
/* Find next char after the macro identifier; this can be either
|
||||||
|
a space or an open parenthesis. */
|
||||||
|
endmac = strcspn (line + 8, " (");
|
||||||
|
if (line[8+endmac] == '\0')
|
||||||
|
{
|
||||||
|
printf ("malformed input, expected '#define MACRO VALUE'\n"
|
||||||
|
"got '%s'\n", line);
|
||||||
|
result = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for (i = 0; i < NUMBER_OF_SUFFIXES; ++i)
|
||||||
|
{
|
||||||
|
size_t len = strlen (suffix[i]);
|
||||||
|
if (!strncmp (line + 8 + endmac - len, suffix[i], len))
|
||||||
|
{
|
||||||
|
++okay;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (okay)
|
||||||
|
continue;
|
||||||
|
if (except != NULL)
|
||||||
|
for (cpp = except; *cpp != NULL; ++cpp)
|
||||||
|
{
|
||||||
|
size_t len = strlen (*cpp);
|
||||||
|
if (!strncmp (line + 8, *cpp, len) && isspace (line[8 + len]))
|
||||||
|
{
|
||||||
|
++okay;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!okay)
|
||||||
|
{
|
||||||
|
fputs (line, stdout);
|
||||||
|
result = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose (input);
|
||||||
|
remove (macrofile);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* EOF */
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
long int
|
||||||
|
jrand48 (xsubi)
|
||||||
|
unsigned short int xsubi[3];
|
||||||
|
{
|
||||||
|
long int result;
|
||||||
|
|
||||||
|
(void) __jrand48_r (xsubi, &__libc_drand48_data, &result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
__jrand48_r (xsubi, buffer, result)
|
||||||
|
unsigned short int xsubi[3];
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
long int *result;
|
||||||
|
{
|
||||||
|
/* Compute next state. */
|
||||||
|
if (__drand48_iterate (xsubi, buffer) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Store the result. */
|
||||||
|
*result = ((xsubi[2] << 16) | xsubi[1]) & 0xffffffffl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
weak_alias (__jrand48_r, jrand48_r)
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 2000 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/* Conversion table. */
|
||||||
|
static const char conv_table[64] =
|
||||||
|
{
|
||||||
|
'.', '/', '0', '1', '2', '3', '4', '5',
|
||||||
|
'6', '7', '8', '9', 'A', 'B', 'C', 'D',
|
||||||
|
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
|
||||||
|
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||||
|
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
|
||||||
|
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
||||||
|
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
|
||||||
|
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
|
||||||
|
};
|
||||||
|
|
||||||
|
char *
|
||||||
|
l64a (n)
|
||||||
|
long int n;
|
||||||
|
{
|
||||||
|
unsigned long int m = (unsigned long int) n;
|
||||||
|
static char result[7];
|
||||||
|
int cnt;
|
||||||
|
|
||||||
|
/* The standard says that only 32 bits are used. */
|
||||||
|
m &= 0xffffffff;
|
||||||
|
|
||||||
|
if (m == 0ul)
|
||||||
|
/* The value for N == 0 is defined to be the empty string. */
|
||||||
|
return (char *) "";
|
||||||
|
|
||||||
|
for (cnt = 0; m > 0ul; ++cnt)
|
||||||
|
{
|
||||||
|
result[cnt] = conv_table[m & 0x3f];
|
||||||
|
m >>= 6;
|
||||||
|
}
|
||||||
|
result[cnt] = '\0';
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
lcong48 (param)
|
||||||
|
unsigned short int param[7];
|
||||||
|
{
|
||||||
|
(void) __lcong48_r (param, &__libc_drand48_data);
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
__lcong48_r (param, buffer)
|
||||||
|
unsigned short int param[7];
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
{
|
||||||
|
/* Store the given values. */
|
||||||
|
memcpy (buffer->__x, ¶m[0], sizeof (buffer->__x));
|
||||||
|
buffer->__a = ((uint64_t) param[5] << 32 | (uint32_t) param[4] << 16
|
||||||
|
| param[3]);
|
||||||
|
buffer->__c = param[6];
|
||||||
|
buffer->__init = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
weak_alias (__lcong48_r, lcong48_r)
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
long int
|
||||||
|
lrand48 ()
|
||||||
|
{
|
||||||
|
long int result;
|
||||||
|
|
||||||
|
(void) __nrand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/* Copyright (C) 1995,97,98,2001,02 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.org>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
lrand48_r (buffer, result)
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
long int *result;
|
||||||
|
{
|
||||||
|
/* Be generous for the arguments, detect some errors. */
|
||||||
|
if (buffer == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return __nrand48_r (buffer->__x, buffer, result);
|
||||||
|
}
|
||||||
|
libc_hidden_def (lrand48_r)
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/* Copyright (C) 1991,1997,1998,1999,2000,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <gconv.h>
|
||||||
|
#include <wcsmbs/wcsmbsload.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Internal state. */
|
||||||
|
static mbstate_t state;
|
||||||
|
|
||||||
|
/* Return the length of the multibyte character (if there is one)
|
||||||
|
at S which is no longer than N characters.
|
||||||
|
The ISO C standard says that the `mblen' function must not change
|
||||||
|
the state of the `mbtowc' function. */
|
||||||
|
int
|
||||||
|
mblen (const char *s, size_t n)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
/* If S is NULL the function has to return null or not null
|
||||||
|
depending on the encoding having a state depending encoding or
|
||||||
|
not. */
|
||||||
|
if (s == NULL)
|
||||||
|
{
|
||||||
|
const struct gconv_fcts *fcts;
|
||||||
|
|
||||||
|
/* Get the conversion functions. */
|
||||||
|
fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
|
||||||
|
|
||||||
|
/* Reset the state. */
|
||||||
|
memset (&state, '\0', sizeof state);
|
||||||
|
|
||||||
|
result = fcts->towc->__stateful;
|
||||||
|
}
|
||||||
|
else if (*s == '\0')
|
||||||
|
/* According to the ISO C 89 standard this is the expected behaviour. */
|
||||||
|
result = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset (&state, '\0', sizeof state);
|
||||||
|
|
||||||
|
result = __mbrtowc (NULL, s, n, &state);
|
||||||
|
|
||||||
|
/* The `mbrtowc' functions tell us more than we need. Fold the -1
|
||||||
|
and -2 result into -1. */
|
||||||
|
if (result < 0)
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright (C) 1991, 1992, 1996, 1997, 1999 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Convert the string of multibyte characters in S to `wchar_t's in
|
||||||
|
PWCS, writing no more than N. Return the number written,
|
||||||
|
or (size_t) -1 if an invalid multibyte character is encountered.
|
||||||
|
|
||||||
|
Attention: this function should NEVER be intentionally used.
|
||||||
|
The interface is completely stupid. The state is shared between
|
||||||
|
all conversion functions. You should use instead the restartable
|
||||||
|
version `mbsrtowcs'. */
|
||||||
|
size_t
|
||||||
|
mbstowcs (wchar_t *pwcs, const char *s, size_t n)
|
||||||
|
{
|
||||||
|
mbstate_t state;
|
||||||
|
|
||||||
|
memset (&state, '\0', sizeof state);
|
||||||
|
/* Return how many we wrote (or maybe an error). */
|
||||||
|
return __mbsrtowcs (pwcs, &s, n, &state);
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
/* Copyright (C) 1991, 1992, 1995-1999, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <gconv.h>
|
||||||
|
#include <wcsmbs/wcsmbsload.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Common state for all non-restartable conversion functions. */
|
||||||
|
mbstate_t __no_r_state attribute_hidden;
|
||||||
|
|
||||||
|
/* Convert the multibyte character at S, which is no longer
|
||||||
|
than N characters, to its `wchar_t' representation, placing
|
||||||
|
this n *PWC and returning its length.
|
||||||
|
|
||||||
|
Attention: this function should NEVER be intentionally used.
|
||||||
|
The interface is completely stupid. The state is shared between
|
||||||
|
all conversion functions. You should use instead the restartable
|
||||||
|
version `mbrtowc'. */
|
||||||
|
int
|
||||||
|
mbtowc (wchar_t *pwc, const char *s, size_t n)
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
|
||||||
|
/* If S is NULL the function has to return null or not null
|
||||||
|
depending on the encoding having a state depending encoding or
|
||||||
|
not. */
|
||||||
|
if (s == NULL)
|
||||||
|
{
|
||||||
|
const struct gconv_fcts *fcts;
|
||||||
|
|
||||||
|
/* Get the conversion functions. */
|
||||||
|
fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE));
|
||||||
|
|
||||||
|
/* This is an extension in the Unix standard which does not directly
|
||||||
|
violate ISO C. */
|
||||||
|
memset (&__no_r_state, '\0', sizeof __no_r_state);
|
||||||
|
|
||||||
|
result = fcts->towc->__stateful;
|
||||||
|
}
|
||||||
|
else if (*s == '\0')
|
||||||
|
{
|
||||||
|
if (pwc != NULL)
|
||||||
|
*pwc = L'\0';
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result = __mbrtowc (pwc, s, n, &__no_r_state);
|
||||||
|
|
||||||
|
/* The `mbrtowc' functions tell us more than we need. Fold the -1
|
||||||
|
and -2 result into -1. */
|
||||||
|
if (result < 0)
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
/* Header file for monetary value formatting functions.
|
||||||
|
Copyright (C) 1996,97,98,99,2000,02 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#ifndef _MONETARY_H
|
||||||
|
#define _MONETARY_H 1
|
||||||
|
|
||||||
|
#include <features.h>
|
||||||
|
|
||||||
|
/* Get needed types. */
|
||||||
|
#define __need_size_t
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <bits/types.h>
|
||||||
|
|
||||||
|
#ifndef __ssize_t_defined
|
||||||
|
typedef __ssize_t ssize_t;
|
||||||
|
# define __ssize_t_defined
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
/* Formatting a monetary value according to the current locale. */
|
||||||
|
extern ssize_t strfmon (char *__restrict __s, size_t __maxsize,
|
||||||
|
__const char *__restrict __format, ...)
|
||||||
|
__THROW __attribute_format_strfmon__ (3, 4);
|
||||||
|
|
||||||
|
#ifdef __USE_GNU
|
||||||
|
# include <xlocale.h>
|
||||||
|
|
||||||
|
/* Formatting a monetary value according to the current locale. */
|
||||||
|
extern ssize_t strfmon_l (char *__restrict __s, size_t __maxsize,
|
||||||
|
__locale_t loc,
|
||||||
|
__const char *__restrict __format, ...)
|
||||||
|
__THROW __attribute_format_strfmon__ (4, 5);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* monetary.h */
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
long int
|
||||||
|
mrand48 ()
|
||||||
|
{
|
||||||
|
long int result;
|
||||||
|
|
||||||
|
(void) __jrand48_r (__libc_drand48_data.__x, &__libc_drand48_data, &result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
mrand48_r (buffer, result)
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
long int *result;
|
||||||
|
{
|
||||||
|
/* Be generous for the arguments, detect some errors. */
|
||||||
|
if (buffer == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return __jrand48_r (buffer->__x, buffer, result);
|
||||||
|
}
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
/* An alternative to qsort, with an identical interface.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Copyright (C) 1992,95-97,99,2000,01,02 Free Software Foundation, Inc.
|
||||||
|
Written by Mike Haertel, September 1988.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <alloca.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <memcopy.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
static void msort_with_tmp (void *b, size_t n, size_t s,
|
||||||
|
__compar_fn_t cmp, char *t);
|
||||||
|
|
||||||
|
static void
|
||||||
|
msort_with_tmp (void *b, size_t n, size_t s, __compar_fn_t cmp,
|
||||||
|
char *t)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
char *b1, *b2;
|
||||||
|
size_t n1, n2;
|
||||||
|
|
||||||
|
if (n <= 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
n1 = n / 2;
|
||||||
|
n2 = n - n1;
|
||||||
|
b1 = b;
|
||||||
|
b2 = (char *) b + (n1 * s);
|
||||||
|
|
||||||
|
msort_with_tmp (b1, n1, s, cmp, t);
|
||||||
|
msort_with_tmp (b2, n2, s, cmp, t);
|
||||||
|
|
||||||
|
tmp = t;
|
||||||
|
|
||||||
|
if (s == OPSIZ && (b1 - (char *) 0) % OPSIZ == 0)
|
||||||
|
/* We are operating on aligned words. Use direct word stores. */
|
||||||
|
while (n1 > 0 && n2 > 0)
|
||||||
|
{
|
||||||
|
if ((*cmp) (b1, b2) <= 0)
|
||||||
|
{
|
||||||
|
--n1;
|
||||||
|
*((op_t *) tmp)++ = *((op_t *) b1)++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
--n2;
|
||||||
|
*((op_t *) tmp)++ = *((op_t *) b2)++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (n1 > 0 && n2 > 0)
|
||||||
|
{
|
||||||
|
if ((*cmp) (b1, b2) <= 0)
|
||||||
|
{
|
||||||
|
tmp = (char *) __mempcpy (tmp, b1, s);
|
||||||
|
b1 += s;
|
||||||
|
--n1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tmp = (char *) __mempcpy (tmp, b2, s);
|
||||||
|
b2 += s;
|
||||||
|
--n2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (n1 > 0)
|
||||||
|
memcpy (tmp, b1, n1 * s);
|
||||||
|
memcpy (b, t, (n - n2) * s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
qsort (void *b, size_t n, size_t s, __compar_fn_t cmp)
|
||||||
|
{
|
||||||
|
const size_t size = n * s;
|
||||||
|
|
||||||
|
if (size < 1024)
|
||||||
|
{
|
||||||
|
void *buf = __alloca (size);
|
||||||
|
|
||||||
|
/* The temporary array is small, so put it on the stack. */
|
||||||
|
msort_with_tmp (b, n, s, cmp, buf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* We should avoid allocating too much memory since this might
|
||||||
|
have to be backed up by swap space. */
|
||||||
|
static long int phys_pages;
|
||||||
|
static int pagesize;
|
||||||
|
|
||||||
|
if (phys_pages == 0)
|
||||||
|
{
|
||||||
|
phys_pages = __sysconf (_SC_PHYS_PAGES);
|
||||||
|
|
||||||
|
if (phys_pages == -1)
|
||||||
|
/* Error while determining the memory size. So let's
|
||||||
|
assume there is enough memory. Otherwise the
|
||||||
|
implementer should provide a complete implementation of
|
||||||
|
the `sysconf' function. */
|
||||||
|
phys_pages = (long int) (~0ul >> 1);
|
||||||
|
|
||||||
|
/* The following determines that we will never use more than
|
||||||
|
a quarter of the physical memory. */
|
||||||
|
phys_pages /= 4;
|
||||||
|
|
||||||
|
pagesize = __sysconf (_SC_PAGESIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Just a comment here. We cannot compute
|
||||||
|
phys_pages * pagesize
|
||||||
|
and compare the needed amount of memory against this value.
|
||||||
|
The problem is that some systems might have more physical
|
||||||
|
memory then can be represented with a `size_t' value (when
|
||||||
|
measured in bytes. */
|
||||||
|
|
||||||
|
/* If the memory requirements are too high don't allocate memory. */
|
||||||
|
if (size / pagesize > (size_t) phys_pages)
|
||||||
|
_quicksort (b, n, s, cmp);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* It's somewhat large, so malloc it. */
|
||||||
|
int save = errno;
|
||||||
|
char *tmp = malloc (size);
|
||||||
|
if (tmp == NULL)
|
||||||
|
{
|
||||||
|
/* Couldn't get space, so use the slower algorithm
|
||||||
|
that doesn't need a temporary array. */
|
||||||
|
__set_errno (save);
|
||||||
|
_quicksort (b, n, s, cmp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
__set_errno (save);
|
||||||
|
msort_with_tmp (b, n, s, cmp, tmp);
|
||||||
|
free (tmp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
libc_hidden_def (qsort)
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
long int
|
||||||
|
nrand48 (xsubi)
|
||||||
|
unsigned short int xsubi[3];
|
||||||
|
{
|
||||||
|
long int result;
|
||||||
|
|
||||||
|
(void) __nrand48_r (xsubi, &__libc_drand48_data, &result);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/* Copyright (C) 1995, 1997 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
__nrand48_r (xsubi, buffer, result)
|
||||||
|
unsigned short int xsubi[3];
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
long int *result;
|
||||||
|
{
|
||||||
|
/* Compute next state. */
|
||||||
|
if (__drand48_iterate (xsubi, buffer) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* Store the result. */
|
||||||
|
if (sizeof (unsigned short int) == 2)
|
||||||
|
*result = xsubi[2] << 15 | xsubi[1] >> 1;
|
||||||
|
else
|
||||||
|
*result = xsubi[2] >> 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
weak_alias (__nrand48_r, nrand48_r)
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include <shlib-compat.h>
|
||||||
|
|
||||||
|
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_2_2)
|
||||||
|
# define atexit __dyn_atexit
|
||||||
|
# include "atexit.c"
|
||||||
|
# undef atexit
|
||||||
|
compat_symbol (libc, __dyn_atexit, atexit, GLIBC_2_0);
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/* Copyright (C) 1991, 1996 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "exit.h"
|
||||||
|
|
||||||
|
/* Register a function to be called by exit. */
|
||||||
|
int
|
||||||
|
__on_exit (void (*func) (int status, void *arg), void *arg)
|
||||||
|
{
|
||||||
|
struct exit_function *new = __new_exitfn ();
|
||||||
|
|
||||||
|
if (new == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
new->flavor = ef_on;
|
||||||
|
new->func.on.fn = func;
|
||||||
|
new->func.on.arg = arg;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
weak_alias (__on_exit, on_exit)
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
/* Copyright (C) 1991, 1992, 1996, 1997, 1999 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Written by Douglas C. Schmidt (schmidt@ics.uci.edu).
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/* If you consider tuning this algorithm, you should consult first:
|
||||||
|
Engineering a sort function; Jon Bentley and M. Douglas McIlroy;
|
||||||
|
Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */
|
||||||
|
|
||||||
|
#include <alloca.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Byte-wise swap two items of size SIZE. */
|
||||||
|
#define SWAP(a, b, size) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
register size_t __size = (size); \
|
||||||
|
register char *__a = (a), *__b = (b); \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
char __tmp = *__a; \
|
||||||
|
*__a++ = *__b; \
|
||||||
|
*__b++ = __tmp; \
|
||||||
|
} while (--__size > 0); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Discontinue quicksort algorithm when partition gets below this size.
|
||||||
|
This particular magic number was chosen to work best on a Sun 4/260. */
|
||||||
|
#define MAX_THRESH 4
|
||||||
|
|
||||||
|
/* Stack node declarations used to store unfulfilled partition obligations. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char *lo;
|
||||||
|
char *hi;
|
||||||
|
} stack_node;
|
||||||
|
|
||||||
|
/* The next 4 #defines implement a very fast in-line stack abstraction. */
|
||||||
|
/* The stack needs log (total_elements) entries (we could even subtract
|
||||||
|
log(MAX_THRESH)). Since total_elements has type size_t, we get as
|
||||||
|
upper bound for log (total_elements):
|
||||||
|
bits per byte (CHAR_BIT) * sizeof(size_t). */
|
||||||
|
#define STACK_SIZE (CHAR_BIT * sizeof(size_t))
|
||||||
|
#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top))
|
||||||
|
#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi)))
|
||||||
|
#define STACK_NOT_EMPTY (stack < top)
|
||||||
|
|
||||||
|
|
||||||
|
/* Order size using quicksort. This implementation incorporates
|
||||||
|
four optimizations discussed in Sedgewick:
|
||||||
|
|
||||||
|
1. Non-recursive, using an explicit stack of pointer that store the
|
||||||
|
next array partition to sort. To save time, this maximum amount
|
||||||
|
of space required to store an array of SIZE_MAX is allocated on the
|
||||||
|
stack. Assuming a 32-bit (64 bit) integer for size_t, this needs
|
||||||
|
only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes).
|
||||||
|
Pretty cheap, actually.
|
||||||
|
|
||||||
|
2. Chose the pivot element using a median-of-three decision tree.
|
||||||
|
This reduces the probability of selecting a bad pivot value and
|
||||||
|
eliminates certain extraneous comparisons.
|
||||||
|
|
||||||
|
3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving
|
||||||
|
insertion sort to order the MAX_THRESH items within each partition.
|
||||||
|
This is a big win, since insertion sort is faster for small, mostly
|
||||||
|
sorted array segments.
|
||||||
|
|
||||||
|
4. The larger of the two sub-partitions is always pushed onto the
|
||||||
|
stack first, with the algorithm then concentrating on the
|
||||||
|
smaller partition. This *guarantees* no more than log (total_elems)
|
||||||
|
stack size is needed (actually O(1) in this case)! */
|
||||||
|
|
||||||
|
void
|
||||||
|
_quicksort (void *const pbase, size_t total_elems, size_t size,
|
||||||
|
__compar_fn_t cmp)
|
||||||
|
{
|
||||||
|
register char *base_ptr = (char *) pbase;
|
||||||
|
|
||||||
|
const size_t max_thresh = MAX_THRESH * size;
|
||||||
|
|
||||||
|
if (total_elems == 0)
|
||||||
|
/* Avoid lossage with unsigned arithmetic below. */
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (total_elems > MAX_THRESH)
|
||||||
|
{
|
||||||
|
char *lo = base_ptr;
|
||||||
|
char *hi = &lo[size * (total_elems - 1)];
|
||||||
|
stack_node stack[STACK_SIZE];
|
||||||
|
stack_node *top = stack + 1;
|
||||||
|
|
||||||
|
while (STACK_NOT_EMPTY)
|
||||||
|
{
|
||||||
|
char *left_ptr;
|
||||||
|
char *right_ptr;
|
||||||
|
|
||||||
|
/* Select median value from among LO, MID, and HI. Rearrange
|
||||||
|
LO and HI so the three values are sorted. This lowers the
|
||||||
|
probability of picking a pathological pivot value and
|
||||||
|
skips a comparison for both the LEFT_PTR and RIGHT_PTR in
|
||||||
|
the while loops. */
|
||||||
|
|
||||||
|
char *mid = lo + size * ((hi - lo) / size >> 1);
|
||||||
|
|
||||||
|
if ((*cmp) ((void *) mid, (void *) lo) < 0)
|
||||||
|
SWAP (mid, lo, size);
|
||||||
|
if ((*cmp) ((void *) hi, (void *) mid) < 0)
|
||||||
|
SWAP (mid, hi, size);
|
||||||
|
else
|
||||||
|
goto jump_over;
|
||||||
|
if ((*cmp) ((void *) mid, (void *) lo) < 0)
|
||||||
|
SWAP (mid, lo, size);
|
||||||
|
jump_over:;
|
||||||
|
|
||||||
|
left_ptr = lo + size;
|
||||||
|
right_ptr = hi - size;
|
||||||
|
|
||||||
|
/* Here's the famous ``collapse the walls'' section of quicksort.
|
||||||
|
Gotta like those tight inner loops! They are the main reason
|
||||||
|
that this algorithm runs much faster than others. */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
while ((*cmp) ((void *) left_ptr, (void *) mid) < 0)
|
||||||
|
left_ptr += size;
|
||||||
|
|
||||||
|
while ((*cmp) ((void *) mid, (void *) right_ptr) < 0)
|
||||||
|
right_ptr -= size;
|
||||||
|
|
||||||
|
if (left_ptr < right_ptr)
|
||||||
|
{
|
||||||
|
SWAP (left_ptr, right_ptr, size);
|
||||||
|
if (mid == left_ptr)
|
||||||
|
mid = right_ptr;
|
||||||
|
else if (mid == right_ptr)
|
||||||
|
mid = left_ptr;
|
||||||
|
left_ptr += size;
|
||||||
|
right_ptr -= size;
|
||||||
|
}
|
||||||
|
else if (left_ptr == right_ptr)
|
||||||
|
{
|
||||||
|
left_ptr += size;
|
||||||
|
right_ptr -= size;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (left_ptr <= right_ptr);
|
||||||
|
|
||||||
|
/* Set up pointers for next iteration. First determine whether
|
||||||
|
left and right partitions are below the threshold size. If so,
|
||||||
|
ignore one or both. Otherwise, push the larger partition's
|
||||||
|
bounds on the stack and continue sorting the smaller one. */
|
||||||
|
|
||||||
|
if ((size_t) (right_ptr - lo) <= max_thresh)
|
||||||
|
{
|
||||||
|
if ((size_t) (hi - left_ptr) <= max_thresh)
|
||||||
|
/* Ignore both small partitions. */
|
||||||
|
POP (lo, hi);
|
||||||
|
else
|
||||||
|
/* Ignore small left partition. */
|
||||||
|
lo = left_ptr;
|
||||||
|
}
|
||||||
|
else if ((size_t) (hi - left_ptr) <= max_thresh)
|
||||||
|
/* Ignore small right partition. */
|
||||||
|
hi = right_ptr;
|
||||||
|
else if ((right_ptr - lo) > (hi - left_ptr))
|
||||||
|
{
|
||||||
|
/* Push larger left partition indices. */
|
||||||
|
PUSH (lo, right_ptr);
|
||||||
|
lo = left_ptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Push larger right partition indices. */
|
||||||
|
PUSH (left_ptr, hi);
|
||||||
|
hi = right_ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Once the BASE_PTR array is partially sorted by quicksort the rest
|
||||||
|
is completely sorted using insertion sort, since this is efficient
|
||||||
|
for partitions below MAX_THRESH size. BASE_PTR points to the beginning
|
||||||
|
of the array to sort, and END_PTR points at the very last element in
|
||||||
|
the array (*not* one beyond it!). */
|
||||||
|
|
||||||
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||||
|
|
||||||
|
{
|
||||||
|
char *const end_ptr = &base_ptr[size * (total_elems - 1)];
|
||||||
|
char *tmp_ptr = base_ptr;
|
||||||
|
char *thresh = min(end_ptr, base_ptr + max_thresh);
|
||||||
|
register char *run_ptr;
|
||||||
|
|
||||||
|
/* Find smallest element in first threshold and place it at the
|
||||||
|
array's beginning. This is the smallest array element,
|
||||||
|
and the operation speeds up insertion sort's inner loop. */
|
||||||
|
|
||||||
|
for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size)
|
||||||
|
if ((*cmp) ((void *) run_ptr, (void *) tmp_ptr) < 0)
|
||||||
|
tmp_ptr = run_ptr;
|
||||||
|
|
||||||
|
if (tmp_ptr != base_ptr)
|
||||||
|
SWAP (tmp_ptr, base_ptr, size);
|
||||||
|
|
||||||
|
/* Insertion sort, running from left-hand-side up to right-hand-side. */
|
||||||
|
|
||||||
|
run_ptr = base_ptr + size;
|
||||||
|
while ((run_ptr += size) <= end_ptr)
|
||||||
|
{
|
||||||
|
tmp_ptr = run_ptr - size;
|
||||||
|
while ((*cmp) ((void *) run_ptr, (void *) tmp_ptr) < 0)
|
||||||
|
tmp_ptr -= size;
|
||||||
|
|
||||||
|
tmp_ptr += size;
|
||||||
|
if (tmp_ptr != run_ptr)
|
||||||
|
{
|
||||||
|
char *trav;
|
||||||
|
|
||||||
|
trav = run_ptr + size;
|
||||||
|
while (--trav >= run_ptr)
|
||||||
|
{
|
||||||
|
char c = *trav;
|
||||||
|
char *hi, *lo;
|
||||||
|
|
||||||
|
for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo)
|
||||||
|
*hi = *lo;
|
||||||
|
*hi = c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/* Copyright (C) 1991, 1996 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#undef rand
|
||||||
|
|
||||||
|
|
||||||
|
/* Return a random integer between 0 and RAND_MAX. */
|
||||||
|
int
|
||||||
|
rand ()
|
||||||
|
{
|
||||||
|
return (int) __random ();
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/* Reentrant random function frm POSIX.1c.
|
||||||
|
Copyright (C) 1996, 1999 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* This algorithm is mentioned in the ISO C standard, here extended
|
||||||
|
for 32 bits. */
|
||||||
|
int
|
||||||
|
rand_r (unsigned int *seed)
|
||||||
|
{
|
||||||
|
unsigned int next = *seed;
|
||||||
|
int result;
|
||||||
|
|
||||||
|
next *= 1103515245;
|
||||||
|
next += 12345;
|
||||||
|
result = (unsigned int) (next / 65536) % 2048;
|
||||||
|
|
||||||
|
next *= 1103515245;
|
||||||
|
next += 12345;
|
||||||
|
result <<= 10;
|
||||||
|
result ^= (unsigned int) (next / 65536) % 1024;
|
||||||
|
|
||||||
|
next *= 1103515245;
|
||||||
|
next += 12345;
|
||||||
|
result <<= 10;
|
||||||
|
result ^= (unsigned int) (next / 65536) % 1024;
|
||||||
|
|
||||||
|
*seed = next;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -0,0 +1,305 @@
|
|||||||
|
/* Copyright (C) 1995 Free Software Foundation
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is derived from the Berkeley source:
|
||||||
|
* @(#)random.c 5.5 (Berkeley) 7/6/88
|
||||||
|
* It was reworked for the GNU C Library by Roland McGrath.
|
||||||
|
* Rewritten to use reentrant functions by Ulrich Drepper, 1995.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 1983 Regents of the University of California.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
4. Neither the name of the University nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.*/
|
||||||
|
|
||||||
|
#include <bits/libc-lock.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* An improved random number generation package. In addition to the standard
|
||||||
|
rand()/srand() like interface, this package also has a special state info
|
||||||
|
interface. The initstate() routine is called with a seed, an array of
|
||||||
|
bytes, and a count of how many bytes are being passed in; this array is
|
||||||
|
then initialized to contain information for random number generation with
|
||||||
|
that much state information. Good sizes for the amount of state
|
||||||
|
information are 32, 64, 128, and 256 bytes. The state can be switched by
|
||||||
|
calling the setstate() function with the same array as was initialized
|
||||||
|
with initstate(). By default, the package runs with 128 bytes of state
|
||||||
|
information and generates far better random numbers than a linear
|
||||||
|
congruential generator. If the amount of state information is less than
|
||||||
|
32 bytes, a simple linear congruential R.N.G. is used. Internally, the
|
||||||
|
state information is treated as an array of longs; the zeroth element of
|
||||||
|
the array is the type of R.N.G. being used (small integer); the remainder
|
||||||
|
of the array is the state information for the R.N.G. Thus, 32 bytes of
|
||||||
|
state information will give 7 longs worth of state information, which will
|
||||||
|
allow a degree seven polynomial. (Note: The zeroth word of state
|
||||||
|
information also has some other information stored in it; see setstate
|
||||||
|
for details). The random number generation technique is a linear feedback
|
||||||
|
shift register approach, employing trinomials (since there are fewer terms
|
||||||
|
to sum up that way). In this approach, the least significant bit of all
|
||||||
|
the numbers in the state table will act as a linear feedback shift register,
|
||||||
|
and will have period 2^deg - 1 (where deg is the degree of the polynomial
|
||||||
|
being used, assuming that the polynomial is irreducible and primitive).
|
||||||
|
The higher order bits will have longer periods, since their values are
|
||||||
|
also influenced by pseudo-random carries out of the lower bits. The
|
||||||
|
total period of the generator is approximately deg*(2**deg - 1); thus
|
||||||
|
doubling the amount of state information has a vast influence on the
|
||||||
|
period of the generator. Note: The deg*(2**deg - 1) is an approximation
|
||||||
|
only good for large deg, when the period of the shift register is the
|
||||||
|
dominant factor. With deg equal to seven, the period is actually much
|
||||||
|
longer than the 7*(2**7 - 1) predicted by this formula. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* For each of the currently supported random number generators, we have a
|
||||||
|
break value on the amount of state information (you need at least this many
|
||||||
|
bytes of state info to support this random number generator), a degree for
|
||||||
|
the polynomial (actually a trinomial) that the R.N.G. is based on, and
|
||||||
|
separation between the two lower order coefficients of the trinomial. */
|
||||||
|
|
||||||
|
/* Linear congruential. */
|
||||||
|
#define TYPE_0 0
|
||||||
|
#define BREAK_0 8
|
||||||
|
#define DEG_0 0
|
||||||
|
#define SEP_0 0
|
||||||
|
|
||||||
|
/* x**7 + x**3 + 1. */
|
||||||
|
#define TYPE_1 1
|
||||||
|
#define BREAK_1 32
|
||||||
|
#define DEG_1 7
|
||||||
|
#define SEP_1 3
|
||||||
|
|
||||||
|
/* x**15 + x + 1. */
|
||||||
|
#define TYPE_2 2
|
||||||
|
#define BREAK_2 64
|
||||||
|
#define DEG_2 15
|
||||||
|
#define SEP_2 1
|
||||||
|
|
||||||
|
/* x**31 + x**3 + 1. */
|
||||||
|
#define TYPE_3 3
|
||||||
|
#define BREAK_3 128
|
||||||
|
#define DEG_3 31
|
||||||
|
#define SEP_3 3
|
||||||
|
|
||||||
|
/* x**63 + x + 1. */
|
||||||
|
#define TYPE_4 4
|
||||||
|
#define BREAK_4 256
|
||||||
|
#define DEG_4 63
|
||||||
|
#define SEP_4 1
|
||||||
|
|
||||||
|
|
||||||
|
/* Array versions of the above information to make code run faster.
|
||||||
|
Relies on fact that TYPE_i == i. */
|
||||||
|
|
||||||
|
#define MAX_TYPES 5 /* Max number of types above. */
|
||||||
|
|
||||||
|
|
||||||
|
/* Initially, everything is set up as if from:
|
||||||
|
initstate(1, randtbl, 128);
|
||||||
|
Note that this initialization takes advantage of the fact that srandom
|
||||||
|
advances the front and rear pointers 10*rand_deg times, and hence the
|
||||||
|
rear pointer which starts at 0 will also end up at zero; thus the zeroth
|
||||||
|
element of the state information, which contains info about the current
|
||||||
|
position of the rear pointer is just
|
||||||
|
(MAX_TYPES * (rptr - state)) + TYPE_3 == TYPE_3. */
|
||||||
|
|
||||||
|
static int32_t randtbl[DEG_3 + 1] =
|
||||||
|
{
|
||||||
|
TYPE_3,
|
||||||
|
|
||||||
|
-1726662223, 379960547, 1735697613, 1040273694, 1313901226,
|
||||||
|
1627687941, -179304937, -2073333483, 1780058412, -1989503057,
|
||||||
|
-615974602, 344556628, 939512070, -1249116260, 1507946756,
|
||||||
|
-812545463, 154635395, 1388815473, -1926676823, 525320961,
|
||||||
|
-1009028674, 968117788, -123449607, 1284210865, 435012392,
|
||||||
|
-2017506339, -911064859, -370259173, 1132637927, 1398500161,
|
||||||
|
-205601318,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static struct random_data unsafe_state =
|
||||||
|
{
|
||||||
|
/* FPTR and RPTR are two pointers into the state info, a front and a rear
|
||||||
|
pointer. These two pointers are always rand_sep places aparts, as they
|
||||||
|
cycle through the state information. (Yes, this does mean we could get
|
||||||
|
away with just one pointer, but the code for random is more efficient
|
||||||
|
this way). The pointers are left positioned as they would be from the call:
|
||||||
|
initstate(1, randtbl, 128);
|
||||||
|
(The position of the rear pointer, rptr, is really 0 (as explained above
|
||||||
|
in the initialization of randtbl) because the state table pointer is set
|
||||||
|
to point to randtbl[1] (as explained below).) */
|
||||||
|
|
||||||
|
.fptr = &randtbl[SEP_3 + 1],
|
||||||
|
.rptr = &randtbl[1],
|
||||||
|
|
||||||
|
/* The following things are the pointer to the state information table,
|
||||||
|
the type of the current generator, the degree of the current polynomial
|
||||||
|
being used, and the separation between the two pointers.
|
||||||
|
Note that for efficiency of random, we remember the first location of
|
||||||
|
the state information, not the zeroth. Hence it is valid to access
|
||||||
|
state[-1], which is used to store the type of the R.N.G.
|
||||||
|
Also, we remember the last location, since this is more efficient than
|
||||||
|
indexing every time to find the address of the last element to see if
|
||||||
|
the front and rear pointers have wrapped. */
|
||||||
|
|
||||||
|
.state = &randtbl[1],
|
||||||
|
|
||||||
|
.rand_type = TYPE_3,
|
||||||
|
.rand_deg = DEG_3,
|
||||||
|
.rand_sep = SEP_3,
|
||||||
|
|
||||||
|
.end_ptr = &randtbl[sizeof (randtbl) / sizeof (randtbl[0])]
|
||||||
|
};
|
||||||
|
|
||||||
|
/* POSIX.1c requires that there is mutual exclusion for the `rand' and
|
||||||
|
`srand' functions to prevent concurrent calls from modifying common
|
||||||
|
data. */
|
||||||
|
__libc_lock_define_initialized (static, lock)
|
||||||
|
|
||||||
|
/* Initialize the random number generator based on the given seed. If the
|
||||||
|
type is the trivial no-state-information type, just remember the seed.
|
||||||
|
Otherwise, initializes state[] based on the given "seed" via a linear
|
||||||
|
congruential generator. Then, the pointers are set to known locations
|
||||||
|
that are exactly rand_sep places apart. Lastly, it cycles the state
|
||||||
|
information a given number of times to get rid of any initial dependencies
|
||||||
|
introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
|
||||||
|
for default usage relies on values produced by this routine. */
|
||||||
|
void
|
||||||
|
__srandom (x)
|
||||||
|
unsigned int x;
|
||||||
|
{
|
||||||
|
__libc_lock_lock (lock);
|
||||||
|
(void) __srandom_r (x, &unsafe_state);
|
||||||
|
__libc_lock_unlock (lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__srandom, srandom)
|
||||||
|
weak_alias (__srandom, srand)
|
||||||
|
|
||||||
|
/* Initialize the state information in the given array of N bytes for
|
||||||
|
future random number generation. Based on the number of bytes we
|
||||||
|
are given, and the break values for the different R.N.G.'s, we choose
|
||||||
|
the best (largest) one we can and set things up for it. srandom is
|
||||||
|
then called to initialize the state information. Note that on return
|
||||||
|
from srandom, we set state[-1] to be the type multiplexed with the current
|
||||||
|
value of the rear pointer; this is so successive calls to initstate won't
|
||||||
|
lose this information and will be able to restart with setstate.
|
||||||
|
Note: The first thing we do is save the current state, if any, just like
|
||||||
|
setstate so that it doesn't matter when initstate is called.
|
||||||
|
Returns a pointer to the old state. */
|
||||||
|
char *
|
||||||
|
__initstate (seed, arg_state, n)
|
||||||
|
unsigned int seed;
|
||||||
|
char *arg_state;
|
||||||
|
size_t n;
|
||||||
|
{
|
||||||
|
int32_t *ostate;
|
||||||
|
|
||||||
|
__libc_lock_lock (lock);
|
||||||
|
|
||||||
|
ostate = &unsafe_state.state[-1];
|
||||||
|
|
||||||
|
__initstate_r (seed, arg_state, n, &unsafe_state);
|
||||||
|
|
||||||
|
__libc_lock_unlock (lock);
|
||||||
|
|
||||||
|
return (char *) ostate;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__initstate, initstate)
|
||||||
|
|
||||||
|
/* Restore the state from the given state array.
|
||||||
|
Note: It is important that we also remember the locations of the pointers
|
||||||
|
in the current state information, and restore the locations of the pointers
|
||||||
|
from the old state information. This is done by multiplexing the pointer
|
||||||
|
location into the zeroth word of the state information. Note that due
|
||||||
|
to the order in which things are done, it is OK to call setstate with the
|
||||||
|
same state as the current state
|
||||||
|
Returns a pointer to the old state information. */
|
||||||
|
char *
|
||||||
|
__setstate (arg_state)
|
||||||
|
char *arg_state;
|
||||||
|
{
|
||||||
|
int32_t *ostate;
|
||||||
|
|
||||||
|
__libc_lock_lock (lock);
|
||||||
|
|
||||||
|
ostate = &unsafe_state.state[-1];
|
||||||
|
|
||||||
|
if (__setstate_r (arg_state, &unsafe_state) < 0)
|
||||||
|
ostate = NULL;
|
||||||
|
|
||||||
|
__libc_lock_unlock (lock);
|
||||||
|
|
||||||
|
return (char *) ostate;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__setstate, setstate)
|
||||||
|
|
||||||
|
/* If we are using the trivial TYPE_0 R.N.G., just do the old linear
|
||||||
|
congruential bit. Otherwise, we do our fancy trinomial stuff, which is the
|
||||||
|
same in all the other cases due to all the global variables that have been
|
||||||
|
set up. The basic operation is to add the number at the rear pointer into
|
||||||
|
the one at the front pointer. Then both pointers are advanced to the next
|
||||||
|
location cyclically in the table. The value returned is the sum generated,
|
||||||
|
reduced to 31 bits by throwing away the "least random" low bit.
|
||||||
|
Note: The code takes advantage of the fact that both the front and
|
||||||
|
rear pointers can't wrap on the same call by not testing the rear
|
||||||
|
pointer if the front one has wrapped. Returns a 31-bit random number. */
|
||||||
|
|
||||||
|
long int
|
||||||
|
__random ()
|
||||||
|
{
|
||||||
|
int32_t retval;
|
||||||
|
|
||||||
|
__libc_lock_lock (lock);
|
||||||
|
|
||||||
|
(void) __random_r (&unsafe_state, &retval);
|
||||||
|
|
||||||
|
__libc_lock_unlock (lock);
|
||||||
|
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__random, random)
|
||||||
@@ -0,0 +1,407 @@
|
|||||||
|
/*
|
||||||
|
Copyright (C) 1995 Free Software Foundation
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
Copyright (C) 1983 Regents of the University of California.
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
4. Neither the name of the University nor the names of its contributors
|
||||||
|
may be used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGE.*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This is derived from the Berkeley source:
|
||||||
|
* @(#)random.c 5.5 (Berkeley) 7/6/88
|
||||||
|
* It was reworked for the GNU C Library by Roland McGrath.
|
||||||
|
* Rewritten to be reentrant by Ulrich Drepper, 1995
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* An improved random number generation package. In addition to the standard
|
||||||
|
rand()/srand() like interface, this package also has a special state info
|
||||||
|
interface. The initstate() routine is called with a seed, an array of
|
||||||
|
bytes, and a count of how many bytes are being passed in; this array is
|
||||||
|
then initialized to contain information for random number generation with
|
||||||
|
that much state information. Good sizes for the amount of state
|
||||||
|
information are 32, 64, 128, and 256 bytes. The state can be switched by
|
||||||
|
calling the setstate() function with the same array as was initialized
|
||||||
|
with initstate(). By default, the package runs with 128 bytes of state
|
||||||
|
information and generates far better random numbers than a linear
|
||||||
|
congruential generator. If the amount of state information is less than
|
||||||
|
32 bytes, a simple linear congruential R.N.G. is used. Internally, the
|
||||||
|
state information is treated as an array of longs; the zeroth element of
|
||||||
|
the array is the type of R.N.G. being used (small integer); the remainder
|
||||||
|
of the array is the state information for the R.N.G. Thus, 32 bytes of
|
||||||
|
state information will give 7 longs worth of state information, which will
|
||||||
|
allow a degree seven polynomial. (Note: The zeroth word of state
|
||||||
|
information also has some other information stored in it; see setstate
|
||||||
|
for details). The random number generation technique is a linear feedback
|
||||||
|
shift register approach, employing trinomials (since there are fewer terms
|
||||||
|
to sum up that way). In this approach, the least significant bit of all
|
||||||
|
the numbers in the state table will act as a linear feedback shift register,
|
||||||
|
and will have period 2^deg - 1 (where deg is the degree of the polynomial
|
||||||
|
being used, assuming that the polynomial is irreducible and primitive).
|
||||||
|
The higher order bits will have longer periods, since their values are
|
||||||
|
also influenced by pseudo-random carries out of the lower bits. The
|
||||||
|
total period of the generator is approximately deg*(2**deg - 1); thus
|
||||||
|
doubling the amount of state information has a vast influence on the
|
||||||
|
period of the generator. Note: The deg*(2**deg - 1) is an approximation
|
||||||
|
only good for large deg, when the period of the shift register is the
|
||||||
|
dominant factor. With deg equal to seven, the period is actually much
|
||||||
|
longer than the 7*(2**7 - 1) predicted by this formula. */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* For each of the currently supported random number generators, we have a
|
||||||
|
break value on the amount of state information (you need at least this many
|
||||||
|
bytes of state info to support this random number generator), a degree for
|
||||||
|
the polynomial (actually a trinomial) that the R.N.G. is based on, and
|
||||||
|
separation between the two lower order coefficients of the trinomial. */
|
||||||
|
|
||||||
|
/* Linear congruential. */
|
||||||
|
#define TYPE_0 0
|
||||||
|
#define BREAK_0 8
|
||||||
|
#define DEG_0 0
|
||||||
|
#define SEP_0 0
|
||||||
|
|
||||||
|
/* x**7 + x**3 + 1. */
|
||||||
|
#define TYPE_1 1
|
||||||
|
#define BREAK_1 32
|
||||||
|
#define DEG_1 7
|
||||||
|
#define SEP_1 3
|
||||||
|
|
||||||
|
/* x**15 + x + 1. */
|
||||||
|
#define TYPE_2 2
|
||||||
|
#define BREAK_2 64
|
||||||
|
#define DEG_2 15
|
||||||
|
#define SEP_2 1
|
||||||
|
|
||||||
|
/* x**31 + x**3 + 1. */
|
||||||
|
#define TYPE_3 3
|
||||||
|
#define BREAK_3 128
|
||||||
|
#define DEG_3 31
|
||||||
|
#define SEP_3 3
|
||||||
|
|
||||||
|
/* x**63 + x + 1. */
|
||||||
|
#define TYPE_4 4
|
||||||
|
#define BREAK_4 256
|
||||||
|
#define DEG_4 63
|
||||||
|
#define SEP_4 1
|
||||||
|
|
||||||
|
|
||||||
|
/* Array versions of the above information to make code run faster.
|
||||||
|
Relies on fact that TYPE_i == i. */
|
||||||
|
|
||||||
|
#define MAX_TYPES 5 /* Max number of types above. */
|
||||||
|
|
||||||
|
struct random_poly_info
|
||||||
|
{
|
||||||
|
int seps[MAX_TYPES];
|
||||||
|
int degrees[MAX_TYPES];
|
||||||
|
};
|
||||||
|
|
||||||
|
static const struct random_poly_info random_poly_info =
|
||||||
|
{
|
||||||
|
{ SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 },
|
||||||
|
{ DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize the random number generator based on the given seed. If the
|
||||||
|
type is the trivial no-state-information type, just remember the seed.
|
||||||
|
Otherwise, initializes state[] based on the given "seed" via a linear
|
||||||
|
congruential generator. Then, the pointers are set to known locations
|
||||||
|
that are exactly rand_sep places apart. Lastly, it cycles the state
|
||||||
|
information a given number of times to get rid of any initial dependencies
|
||||||
|
introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
|
||||||
|
for default usage relies on values produced by this routine. */
|
||||||
|
int
|
||||||
|
__srandom_r (seed, buf)
|
||||||
|
unsigned int seed;
|
||||||
|
struct random_data *buf;
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int32_t *state;
|
||||||
|
long int i;
|
||||||
|
long int word;
|
||||||
|
int32_t *dst;
|
||||||
|
int kc;
|
||||||
|
|
||||||
|
if (buf == NULL)
|
||||||
|
goto fail;
|
||||||
|
type = buf->rand_type;
|
||||||
|
if ((unsigned int) type >= MAX_TYPES)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
state = buf->state;
|
||||||
|
/* We must make sure the seed is not 0. Take arbitrarily 1 in this case. */
|
||||||
|
if (seed == 0)
|
||||||
|
seed = 1;
|
||||||
|
state[0] = seed;
|
||||||
|
if (type == TYPE_0)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
dst = state;
|
||||||
|
word = seed;
|
||||||
|
kc = buf->rand_deg;
|
||||||
|
for (i = 1; i < kc; ++i)
|
||||||
|
{
|
||||||
|
/* This does:
|
||||||
|
state[i] = (16807 * state[i - 1]) % 2147483647;
|
||||||
|
but avoids overflowing 31 bits. */
|
||||||
|
long int hi = word / 127773;
|
||||||
|
long int lo = word % 127773;
|
||||||
|
word = 16807 * lo - 2836 * hi;
|
||||||
|
if (word < 0)
|
||||||
|
word += 2147483647;
|
||||||
|
*++dst = word;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf->fptr = &state[buf->rand_sep];
|
||||||
|
buf->rptr = &state[0];
|
||||||
|
kc *= 10;
|
||||||
|
while (--kc >= 0)
|
||||||
|
{
|
||||||
|
int32_t discard;
|
||||||
|
(void) __random_r (buf, &discard);
|
||||||
|
}
|
||||||
|
|
||||||
|
done:
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__srandom_r, srandom_r)
|
||||||
|
|
||||||
|
/* Initialize the state information in the given array of N bytes for
|
||||||
|
future random number generation. Based on the number of bytes we
|
||||||
|
are given, and the break values for the different R.N.G.'s, we choose
|
||||||
|
the best (largest) one we can and set things up for it. srandom is
|
||||||
|
then called to initialize the state information. Note that on return
|
||||||
|
from srandom, we set state[-1] to be the type multiplexed with the current
|
||||||
|
value of the rear pointer; this is so successive calls to initstate won't
|
||||||
|
lose this information and will be able to restart with setstate.
|
||||||
|
Note: The first thing we do is save the current state, if any, just like
|
||||||
|
setstate so that it doesn't matter when initstate is called.
|
||||||
|
Returns a pointer to the old state. */
|
||||||
|
int
|
||||||
|
__initstate_r (seed, arg_state, n, buf)
|
||||||
|
unsigned int seed;
|
||||||
|
char *arg_state;
|
||||||
|
size_t n;
|
||||||
|
struct random_data *buf;
|
||||||
|
{
|
||||||
|
int type;
|
||||||
|
int degree;
|
||||||
|
int separation;
|
||||||
|
int32_t *state;
|
||||||
|
|
||||||
|
if (buf == NULL)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (n >= BREAK_3)
|
||||||
|
type = n < BREAK_4 ? TYPE_3 : TYPE_4;
|
||||||
|
else if (n < BREAK_1)
|
||||||
|
{
|
||||||
|
if (n < BREAK_0)
|
||||||
|
{
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
type = TYPE_0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
type = n < BREAK_2 ? TYPE_1 : TYPE_2;
|
||||||
|
|
||||||
|
degree = random_poly_info.degrees[type];
|
||||||
|
separation = random_poly_info.seps[type];
|
||||||
|
|
||||||
|
buf->rand_type = type;
|
||||||
|
buf->rand_sep = separation;
|
||||||
|
buf->rand_deg = degree;
|
||||||
|
state = &((int32_t *) arg_state)[1]; /* First location. */
|
||||||
|
/* Must set END_PTR before srandom. */
|
||||||
|
buf->end_ptr = &state[degree];
|
||||||
|
|
||||||
|
buf->state = state;
|
||||||
|
|
||||||
|
__srandom_r (seed, buf);
|
||||||
|
|
||||||
|
state[-1] = TYPE_0;
|
||||||
|
if (type != TYPE_0)
|
||||||
|
state[-1] = (buf->rptr - state) * MAX_TYPES + type;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__initstate_r, initstate_r)
|
||||||
|
|
||||||
|
/* Restore the state from the given state array.
|
||||||
|
Note: It is important that we also remember the locations of the pointers
|
||||||
|
in the current state information, and restore the locations of the pointers
|
||||||
|
from the old state information. This is done by multiplexing the pointer
|
||||||
|
location into the zeroth word of the state information. Note that due
|
||||||
|
to the order in which things are done, it is OK to call setstate with the
|
||||||
|
same state as the current state
|
||||||
|
Returns a pointer to the old state information. */
|
||||||
|
int
|
||||||
|
__setstate_r (arg_state, buf)
|
||||||
|
char *arg_state;
|
||||||
|
struct random_data *buf;
|
||||||
|
{
|
||||||
|
int32_t *new_state = 1 + (int32_t *) arg_state;
|
||||||
|
int type;
|
||||||
|
int old_type;
|
||||||
|
int32_t *old_state;
|
||||||
|
int degree;
|
||||||
|
int separation;
|
||||||
|
|
||||||
|
if (arg_state == NULL || buf == NULL)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
old_type = buf->rand_type;
|
||||||
|
old_state = buf->state;
|
||||||
|
if (old_type == TYPE_0)
|
||||||
|
old_state[-1] = TYPE_0;
|
||||||
|
else
|
||||||
|
old_state[-1] = (MAX_TYPES * (buf->rptr - old_state)) + old_type;
|
||||||
|
|
||||||
|
type = new_state[-1] % MAX_TYPES;
|
||||||
|
if (type < TYPE_0 || type > TYPE_4)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
buf->rand_deg = degree = random_poly_info.degrees[type];
|
||||||
|
buf->rand_sep = separation = random_poly_info.seps[type];
|
||||||
|
buf->rand_type = type;
|
||||||
|
|
||||||
|
if (type != TYPE_0)
|
||||||
|
{
|
||||||
|
int rear = new_state[-1] / MAX_TYPES;
|
||||||
|
buf->rptr = &new_state[rear];
|
||||||
|
buf->fptr = &new_state[(rear + separation) % degree];
|
||||||
|
}
|
||||||
|
buf->state = new_state;
|
||||||
|
/* Set end_ptr too. */
|
||||||
|
buf->end_ptr = &new_state[degree];
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__setstate_r, setstate_r)
|
||||||
|
|
||||||
|
/* If we are using the trivial TYPE_0 R.N.G., just do the old linear
|
||||||
|
congruential bit. Otherwise, we do our fancy trinomial stuff, which is the
|
||||||
|
same in all the other cases due to all the global variables that have been
|
||||||
|
set up. The basic operation is to add the number at the rear pointer into
|
||||||
|
the one at the front pointer. Then both pointers are advanced to the next
|
||||||
|
location cyclically in the table. The value returned is the sum generated,
|
||||||
|
reduced to 31 bits by throwing away the "least random" low bit.
|
||||||
|
Note: The code takes advantage of the fact that both the front and
|
||||||
|
rear pointers can't wrap on the same call by not testing the rear
|
||||||
|
pointer if the front one has wrapped. Returns a 31-bit random number. */
|
||||||
|
|
||||||
|
int
|
||||||
|
__random_r (buf, result)
|
||||||
|
struct random_data *buf;
|
||||||
|
int32_t *result;
|
||||||
|
{
|
||||||
|
int32_t *state;
|
||||||
|
|
||||||
|
if (buf == NULL || result == NULL)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
state = buf->state;
|
||||||
|
|
||||||
|
if (buf->rand_type == TYPE_0)
|
||||||
|
{
|
||||||
|
int32_t val = state[0];
|
||||||
|
val = ((state[0] * 1103515245) + 12345) & 0x7fffffff;
|
||||||
|
state[0] = val;
|
||||||
|
*result = val;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int32_t *fptr = buf->fptr;
|
||||||
|
int32_t *rptr = buf->rptr;
|
||||||
|
int32_t *end_ptr = buf->end_ptr;
|
||||||
|
int32_t val;
|
||||||
|
|
||||||
|
val = *fptr += *rptr;
|
||||||
|
/* Chucking least random bit. */
|
||||||
|
*result = (val >> 1) & 0x7fffffff;
|
||||||
|
++fptr;
|
||||||
|
if (fptr >= end_ptr)
|
||||||
|
{
|
||||||
|
fptr = state;
|
||||||
|
++rptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++rptr;
|
||||||
|
if (rptr >= end_ptr)
|
||||||
|
rptr = state;
|
||||||
|
}
|
||||||
|
buf->fptr = fptr;
|
||||||
|
buf->rptr = rptr;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
__set_errno (EINVAL);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
weak_alias (__random_r, random_r)
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/* Determine whether string value is affirmation or negative response
|
||||||
|
according to current locale's data.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Copyright (C) 1996, 1997, 2000 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <langinfo.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <regex.h>
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
rpmatch (response)
|
||||||
|
const char *response;
|
||||||
|
{
|
||||||
|
/* Match against one of the response patterns, compiling the pattern
|
||||||
|
first if necessary. */
|
||||||
|
auto inline int try (const int tag, const int match, const int nomatch,
|
||||||
|
const char **lastp, regex_t *re);
|
||||||
|
|
||||||
|
inline int try (const int tag, const int match, const int nomatch,
|
||||||
|
const char **lastp, regex_t *re)
|
||||||
|
{
|
||||||
|
const char *pattern = nl_langinfo (tag);
|
||||||
|
if (pattern != *lastp)
|
||||||
|
{
|
||||||
|
/* The pattern has changed. */
|
||||||
|
if (*lastp)
|
||||||
|
{
|
||||||
|
/* Free the old compiled pattern. */
|
||||||
|
__regfree (re);
|
||||||
|
*lastp = NULL;
|
||||||
|
}
|
||||||
|
/* Compile the pattern and cache it for future runs. */
|
||||||
|
if (__regcomp (re, pattern, REG_EXTENDED) != 0)
|
||||||
|
return -1;
|
||||||
|
*lastp = pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Try the pattern. */
|
||||||
|
return __regexec (re, response, 0, NULL, 0) == 0 ? match : nomatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We cache the response patterns and compiled regexps here. */
|
||||||
|
static const char *yesexpr, *noexpr;
|
||||||
|
static regex_t yesre, nore;
|
||||||
|
|
||||||
|
return (try (YESEXPR, 1, 0, &yesexpr, &yesre) ?:
|
||||||
|
try (NOEXPR, 0, -1, &noexpr, &nore));
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/* Copyright (C) 1991, 1992, 1994, 1996, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/* Some programs and especially the libc itself have to be careful
|
||||||
|
what values to accept from the environment. This special version
|
||||||
|
checks for SUID or SGID first before doing any work. */
|
||||||
|
char *
|
||||||
|
__secure_getenv (name)
|
||||||
|
const char *name;
|
||||||
|
{
|
||||||
|
return __libc_enable_secure ? NULL : getenv (name);
|
||||||
|
}
|
||||||
|
libc_hidden_def (__secure_getenv)
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/* Copyright (C) 1995,1996,1997,1998,2001,2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
unsigned short int *
|
||||||
|
seed48 (seed16v)
|
||||||
|
unsigned short int seed16v[3];
|
||||||
|
{
|
||||||
|
(void) __seed48_r (seed16v, &__libc_drand48_data);
|
||||||
|
|
||||||
|
return __libc_drand48_data.__old_x;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/* Copyright (C) 1995, 1997, 1998, 2001 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
__seed48_r (seed16v, buffer)
|
||||||
|
unsigned short int seed16v[3];
|
||||||
|
struct drand48_data *buffer;
|
||||||
|
{
|
||||||
|
/* Save old value at a private place to be used as return value. */
|
||||||
|
memcpy (buffer->__old_x, buffer->__x, sizeof (buffer->__x));
|
||||||
|
|
||||||
|
/* Install new state. */
|
||||||
|
buffer->__x[2] = seed16v[2];
|
||||||
|
buffer->__x[1] = seed16v[1];
|
||||||
|
buffer->__x[0] = seed16v[0];
|
||||||
|
buffer->__a = 0x5deece66dull;
|
||||||
|
buffer->__c = 0xb;
|
||||||
|
buffer->__init = 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
weak_alias (__seed48_r, seed48_r)
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/* Copyright (C) 1995, 1996, 1997, 2002 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, write to the Free
|
||||||
|
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
02111-1307 USA. */
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
srand48 (seedval)
|
||||||
|
long seedval;
|
||||||
|
{
|
||||||
|
(void) __srand48_r (seedval, &__libc_drand48_data);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user