Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4874 → Rev 4921

/contrib/sdk/sources/newlib/libc/stdlib/_Exit.c
0,0 → 1,46
/*
FUNCTION
<<_Exit>>---end program execution with no cleanup processing
 
INDEX
_Exit
 
ANSI_SYNOPSIS
#include <stdlib.h>
void _Exit(int <[code]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
void _Exit(<[code]>)
int <[code]>;
 
DESCRIPTION
Use <<_Exit>> to return control from a program to the host operating
environment. Use the argument <[code]> to pass an exit status to the
operating environment: two particular values, <<EXIT_SUCCESS>> and
<<EXIT_FAILURE>>, are defined in `<<stdlib.h>>' to indicate success or
failure in a portable fashion.
 
<<_Exit>> differs from <<exit>> in that it does not run any
application-defined cleanup functions registered with <<atexit>> and
it does not clean up files and streams. It is identical to <<_exit>>.
 
RETURNS
<<_Exit>> does not return to its caller.
 
PORTABILITY
<<_Exit>> is defined by the C99 standard.
 
Supporting OS subroutines required: <<_exit>>.
*/
 
#include <stdlib.h>
#include <unistd.h> /* for _exit() declaration */
#include <reent.h>
 
void
_DEFUN (_Exit, (code),
int code)
{
_exit (code);
}
/contrib/sdk/sources/newlib/libc/stdlib/__adjust.c
0,0 → 1,44
/*
* return (*acc) scaled by 10**dexp.
*/
 
#include <_ansi.h>
#include <reent.h>
#include "std.h"
 
#define abs(x) (((x) < 0) ? -(x) : (x))
 
double
_DEFUN (__adjust, (ptr, acc, dexp, sign),
struct _reent *ptr _AND
double *acc _AND
int dexp _AND
int sign)
/* *acc the 64 bit accumulator */
/* dexp decimal exponent */
/* sign sign flag */
{
double r;
 
if (dexp > MAXE)
{
ptr->_errno = ERANGE;
return (sign) ? -HUGE_VAL : HUGE_VAL;
}
else if (dexp < MINE)
{
ptr->_errno = ERANGE;
return 0.0;
}
 
r = *acc;
if (sign)
r = -r;
if (dexp == 0)
return r;
 
if (dexp < 0)
return r / __exp10 (abs (dexp));
else
return r * __exp10 (dexp);
}
/contrib/sdk/sources/newlib/libc/stdlib/__atexit.c
1,5 → 1,35
/*
* Common routine to implement atexit-like functionality.
*
* This is also the key function to be configured as lite exit, a size-reduced
* implementation of exit that doesn't invoke clean-up functions such as _fini
* or global destructors.
*
* Default (without lite exit) call graph is like:
* _start -> atexit -> __register_exitproc
* _start -> __libc_init_array -> __cxa_atexit -> __register_exitproc
* on_exit -> __register_exitproc
* _start -> exit -> __call_exitprocs
*
* Here an -> means arrow tail invokes arrow head. All invocations here
* are non-weak reference in current newlib/libgloss.
*
* Lite exit makes some of above calls as weak reference, so that size expansive
* functions __register_exitproc and __call_exitprocs may not be linked. These
* calls are:
* _start w-> atexit
* __cxa_atexit w-> __register_exitproc
* exit w-> __call_exitprocs
*
* Lite exit also makes sure that __call_exitprocs will be referenced as non-weak
* whenever __register_exitproc is referenced as non-weak.
*
* Thus with lite exit libs, a program not explicitly calling atexit or on_exit
* will escape from the burden of cleaning up code. A program with atexit or on_exit
* will work consistently to normal libs.
*
* Lite exit is enabled with --enable-lite-exit, and is controlled with macro
* _LITE_EXIT.
*/
 
#include <stddef.h>
10,8 → 40,24
 
/* Make this a weak reference to avoid pulling in malloc. */
void * malloc(size_t) _ATTRIBUTE((__weak__));
__LOCK_INIT_RECURSIVE(, __atexit_lock);
 
#ifdef _LITE_EXIT
/* As __call_exitprocs is weak reference in lite exit, make a
non-weak reference to it here. */
const void * __atexit_dummy = &__call_exitprocs;
#endif
 
#ifndef __SINGLE_THREAD__
extern _LOCK_RECURSIVE_T __atexit_lock;
#endif
 
#ifdef _REENT_GLOBAL_ATEXIT
static struct _atexit _global_atexit0 = _ATEXIT_INIT;
# define _GLOBAL_ATEXIT0 (&_global_atexit0)
#else
# define _GLOBAL_ATEXIT0 (&_GLOBAL_REENT->_atexit0)
#endif
 
/*
* Register a function to be performed at exit or on shared library unload.
*/
31,9 → 77,9
__lock_acquire_recursive(__atexit_lock);
#endif
 
p = _GLOBAL_REENT->_atexit;
p = _GLOBAL_ATEXIT;
if (p == NULL)
_GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
_GLOBAL_ATEXIT = p = _GLOBAL_ATEXIT0;
if (p->_ind >= _ATEXIT_SIZE)
{
#ifndef _ATEXIT_DYNAMIC_ALLOC
53,11 → 99,13
return -1;
}
p->_ind = 0;
p->_next = _GLOBAL_REENT->_atexit;
_GLOBAL_REENT->_atexit = p;
p->_next = _GLOBAL_ATEXIT;
_GLOBAL_ATEXIT = p;
#ifndef _REENT_SMALL
p->_on_exit_args._fntypes = 0;
p->_on_exit_args._is_cxa = 0;
#else
p->_on_exit_args_ptr = NULL;
#endif
#endif
}
74,7 → 122,7
if (args == NULL)
{
#ifndef __SINGLE_THREAD__
__lock_release(lock);
__lock_release(__atexit_lock);
#endif
return -1;
}
/contrib/sdk/sources/newlib/libc/stdlib/__call_atexit.c
11,8 → 11,10
/* Make this a weak reference to avoid pulling in free. */
void free(void *) _ATTRIBUTE((__weak__));
 
#ifndef __SINGLE_THREAD__
extern _LOCK_RECURSIVE_T __atexit_lock;
__LOCK_INIT_RECURSIVE(, __atexit_lock);
 
#ifdef _REENT_GLOBAL_ATEXIT
struct _atexit *_global_atexit = _NULL;
#endif
 
#ifdef _WANT_REGISTER_FINI
78,8 → 80,8
 
restart:
 
p = _GLOBAL_REENT->_atexit;
lastp = &_GLOBAL_REENT->_atexit;
p = _GLOBAL_ATEXIT;
lastp = &_GLOBAL_ATEXIT;
while (p)
{
#ifdef _REENT_SMALL
/contrib/sdk/sources/newlib/libc/stdlib/__exp10.c
0,0 → 1,30
/*
* compute 10**x by successive squaring.
*/
 
#include <_ansi.h>
#include "std.h"
 
double
_DEFUN (__exp10, (x),
unsigned x)
{
static _CONST double powtab[] =
{1.0,
10.0,
100.0,
1000.0,
10000.0};
 
if (x < (sizeof (powtab) / sizeof (double)))
return powtab[x];
else if (x & 1)
{
return 10.0 * __exp10 (x - 1);
}
else
{
double n = __exp10 (x / 2);
return n * n;
}
}
/contrib/sdk/sources/newlib/libc/stdlib/__ten_mu.c
0,0 → 1,24
/*
* [atw] multiply 64 bit accumulator by 10 and add digit.
* The KA/CA way to do this should be to use
* a 64-bit integer internally and use "adjust" to
* convert it to float at the end of processing.
*/
 
#include <_ansi.h>
#include "std.h"
 
int
_DEFUN (__ten_mul, (acc, digit),
double *acc _AND
int digit)
{
/*
* [atw] Crude, but effective (at least on a KB)...
*/
 
*acc *= 10;
*acc += digit;
 
return 0; /* no overflow */
}
/contrib/sdk/sources/newlib/libc/stdlib/a64l.c
0,0 → 1,197
/*
FUNCTION
<<a64l>>, <<l64a>>---convert between radix-64 ASCII string and long
 
INDEX
a64l
INDEX
l64a
 
ANSI_SYNOPSIS
#include <stdlib.h>
long a64l(const char *<[input]>);
char *l64a(long <[input]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
long a64l(<[input]>)
const char *<[input]>;
 
char *l64a(<[input]>)
long <[input]>;
 
DESCRIPTION
Conversion is performed between long and radix-64 characters. The
<<l64a>> routine transforms up to 32 bits of input value starting from
least significant bits to the most significant bits. The input value
is split up into a maximum of 5 groups of 6 bits and possibly one
group of 2 bits (bits 31 and 30).
 
Each group of 6 bits forms a value from 0--63 which is translated into
a character as follows:
 
O+
o 0 = '.'
o 1 = '/'
o 2--11 = '0' to '9'
o 12--37 = 'A' to 'Z'
o 38--63 = 'a' to 'z'
O-
 
When the remaining bits are zero or all bits have been translated, a
null terminator is appended to the string. An input value of 0
results in the empty string.
 
The <<a64l>> function performs the reverse translation. Each
character is used to generate a 6-bit value for up to 30 bits and then
a 2-bit value to complete a 32-bit result. The null terminator means
that the remaining digits are 0. An empty input string or NULL string
results in 0L. An invalid string results in undefined behavior. If
the size of a long is greater than 32 bits, the result is sign-extended.
 
RETURNS
<<l64a>> returns a null-terminated string of 0 to 6 characters.
<<a64l>> returns the 32-bit translated value from the input character string.
 
PORTABILITY
<<l64a>> and <<a64l>> are non-ANSI and are defined by the Single Unix Specification.
 
Supporting OS subroutines required: None.
*/
 
#include <_ansi.h>
#include <stdlib.h>
#include <limits.h>
 
long
_DEFUN (a64l, (input),
const char *input)
{
const char *ptr;
char ch;
int i, digit;
unsigned long result = 0;
 
if (input == NULL)
return 0;
 
ptr = input;
 
/* it easiest to go from most significant digit to least so find end of input or up
to 6 characters worth */
for (i = 0; i < 6; ++i)
{
if (*ptr)
++ptr;
}
 
while (ptr > input)
{
ch = *(--ptr);
 
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
if (ch >= 'a')
digit = (ch - 'a') + 38;
else if (ch >= 'A')
digit = (ch - 'A') + 12;
else if (ch >= '0')
digit = (ch - '0') + 2;
else if (ch == '/')
digit = 1;
else
digit = 0;
#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */
switch (ch)
{
case '/':
digit = 1;
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
digit = (ch - '0') + 2;
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'T':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
digit = (ch - 'A') + 12;
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
digit = (ch - 'a') + 38;
break;
default:
digit = 0;
break;
}
#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) */
result = (result << 6) + digit;
}
 
#if LONG_MAX > 2147483647
/* for implementations where long is > 32 bits, the result must be sign-extended */
if (result & 0x80000000)
return (((long)-1 >> 32) << 32) + result;
#endif
 
return result;
}
 
 
 
 
/contrib/sdk/sources/newlib/libc/stdlib/abort.c
59,7 → 59,7
 
while (1)
{
// raise (SIGABRT);
raise (SIGABRT);
_exit (1);
}
}
/contrib/sdk/sources/newlib/libc/stdlib/atoff.c
0,0 → 1,9
#include <stdlib.h>
#include <_ansi.h>
 
float
_DEFUN (atoff, (s),
_CONST char *s)
{
return strtof (s, NULL);
}
/contrib/sdk/sources/newlib/libc/stdlib/atoll.c
0,0 → 1,94
/*
FUNCTION
<<atoll>>---convert a string to a long long integer
 
INDEX
atoll
INDEX
_atoll_r
 
ANSI_SYNOPSIS
#include <stdlib.h>
long long atoll(const char *<[str]>);
long long _atoll_r(struct _reent *<[ptr]>, const char *<[str]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
long long atoll(<[str]>)
const char *<[str]>;
 
long long _atoll_r(<[ptr]>, <[str]>)
struct _reent *<[ptr]>;
const char *<[str]>;
 
DESCRIPTION
The function <<atoll>> converts the initial portion of the string
pointed to by <<*<[str]>>> to a type <<long long>>. A call to
atoll(str) in this implementation is equivalent to
strtoll(str, (char **)NULL, 10) including behavior on error.
 
The alternate function <<_atoll_r>> is a reentrant version. The
extra argument <[reent]> is a pointer to a reentrancy structure.
 
 
RETURNS
The converted value.
 
PORTABILITY
<<atoll>> is ISO 9899 (C99) and POSIX 1003.1-2001 compatable.
 
No supporting OS subroutines are required.
*/
 
/*
* Copyright (c) 1988, 1993
* The 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 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 <stdlib.h>
#include <stddef.h>
 
#ifndef _REENT_ONLY
long long
_DEFUN(atoll, (str),
_CONST char *str)
{
return strtoll(str, (char **)NULL, 10);
}
#endif /* !_REENT_ONLY */
 
long long
_DEFUN(_atoll_r, (ptr, str),
struct _reent *ptr _AND
_CONST char *str)
{
return _strtoll_r(ptr, str, (char **)NULL, 10);
}
/contrib/sdk/sources/newlib/libc/stdlib/exit.c
58,6 → 58,11
_DEFUN (exit, (code),
int code)
{
#ifdef _LITE_EXIT
/* Refer to comments in __atexit.c for more details of lite exit. */
void __call_exitprocs _PARAMS ((int, _PTR)) __attribute__((weak));
if (__call_exitprocs)
#endif
__call_exitprocs (code, NULL);
 
if (_GLOBAL_REENT->__cleanup)
/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-gethex.c
37,27 → 37,37
#include "gd_qnan.h"
#include "locale.h"
 
unsigned char hexdig[256];
 
static void
_DEFUN (htinit, (h, s, inc),
unsigned char *h _AND
unsigned char *s _AND
int inc)
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG)
_CONST unsigned char __hexdig[256]=
{
int i, j;
for(i = 0; (j = s[i]) !=0; i++)
h[j] = i + inc;
}
 
void
_DEFUN_VOID (hexdig_init)
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0,
0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */
unsigned char
_DEFUN (__hexdig_fun, (c),
unsigned char c)
{
#define USC (unsigned char *)
htinit(hexdig, USC "0123456789", 0x10);
htinit(hexdig, USC "abcdef", 0x10 + 10);
htinit(hexdig, USC "ABCDEF", 0x10 + 10);
if(c>='0' && c<='9') return c-'0'+0x10;
else if(c>='a' && c<='f') return c-'a'+0x10+10;
else if(c>='A' && c<='F') return c-'A'+0x10+10;
else return 0;
}
#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */
 
static void
_DEFUN(rshift, (b, k),
138,7 → 148,7
_DEFUN(gethex, (ptr, sp, fpi, exp, bp, sign),
struct _reent *ptr _AND
_CONST char **sp _AND
FPI *fpi _AND
_CONST FPI *fpi _AND
Long *exp _AND
_Bigint **bp _AND
int sign)
153,8 → 163,6
size_t decp_len = strlen ((const char *) decimalpoint);
unsigned char decp_end = decimalpoint[decp_len - 1];
 
if (!hexdig['0'])
hexdig_init();
havedig = 0;
s0 = *(_CONST unsigned char **)sp + 2;
while(s0[havedig] == '0')
164,28 → 172,28
decpt = 0;
zret = 0;
e = 0;
if (!hexdig[*s]) {
if (!__get_hexdig(*s)) {
zret = 1;
if (strncmp ((const char *) s, (const char *) decimalpoint,
decp_len) != 0)
goto pcheck;
decpt = (s += decp_len);
if (!hexdig[*s])
if (!__get_hexdig(*s))
goto pcheck;
while(*s == '0')
s++;
if (hexdig[*s])
if (__get_hexdig(*s))
zret = 0;
havedig = 1;
s0 = s;
}
while(hexdig[*s])
while(__get_hexdig(*s))
s++;
if (strncmp ((const char *) s, (const char *) decimalpoint,
decp_len) == 0
&& !decpt) {
decpt = (s += decp_len);
while(hexdig[*s])
while(__get_hexdig(*s))
s++;
}
if (decpt)
203,12 → 211,12
case '+':
s++;
}
if ((n = hexdig[*s]) == 0 || n > 0x19) {
if ((n = __get_hexdig(*s)) == 0 || n > 0x19) {
s = s1;
break;
}
e1 = n - 0x10;
while((n = hexdig[*++s]) !=0 && n <= 0x19)
while((n = __get_hexdig(*++s)) !=0 && n <= 0x19)
e1 = 10*e1 + n - 0x10;
if (esign)
e1 = -e1;
236,7 → 244,7
L = 0;
n = 0;
}
L |= (hexdig[*s1] & 0x0f) << n;
L |= (__get_hexdig(*s1) & 0x0f) << n;
n += 4;
}
*x++ = L;
/contrib/sdk/sources/newlib/libc/stdlib/gdtoa-hexnan.c
64,7 → 64,7
int
_DEFUN (hexnan, (sp, fpi, x0),
_CONST char **sp _AND
FPI *fpi _AND
_CONST FPI *fpi _AND
__ULong *x0)
{
__ULong c, h, *x, *x1, *xe;
71,8 → 71,6
_CONST char *s;
int havedig, hd0, i, nbits;
 
if (!hexdig['0'])
hexdig_init();
nbits = fpi->nbits;
x = x0 + (nbits >> kshift);
if (nbits & kmask)
82,7 → 80,7
havedig = hd0 = i = 0;
s = *sp;
while((c = *(_CONST unsigned char*)++s)) {
if (!(h = hexdig[c])) {
if (!(h = __get_hexdig(c))) {
if (c <= ' ') {
if (hd0 < havedig) {
if (x < x1 && i < 8)
/contrib/sdk/sources/newlib/libc/stdlib/ldiv.c
0,0 → 1,109
/*
FUNCTION
<<ldiv>>---divide two long integers
 
INDEX
ldiv
 
ANSI_SYNOPSIS
#include <stdlib.h>
ldiv_t ldiv(long <[n]>, long <[d]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
ldiv_t ldiv(<[n]>, <[d]>)
long <[n]>, <[d]>;
 
DESCRIPTION
Divide
@tex
$n/d$,
@end tex
@ifnottex
<[n]>/<[d]>,
@end ifnottex
returning quotient and remainder as two long integers in a structure <<ldiv_t>>.
 
RETURNS
The result is represented with the structure
 
. typedef struct
. {
. long quot;
. long rem;
. } ldiv_t;
 
where the <<quot>> field represents the quotient, and <<rem>> the
remainder. For nonzero <[d]>, if `<<<[r]> = ldiv(<[n]>,<[d]>);>>' then
<[n]> equals `<<<[r]>.rem + <[d]>*<[r]>.quot>>'.
 
To divide <<int>> rather than <<long>> values, use the similar
function <<div>>.
 
PORTABILITY
<<ldiv>> is ANSI.
 
No supporting OS subroutines are required.
*/
 
 
/*
* Copyright (c) 1990 Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 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 <_ansi.h>
#include <stdlib.h> /* ldiv_t */
 
ldiv_t
_DEFUN (ldiv, (num, denom),
long num _AND
long denom)
{
ldiv_t r;
 
/* see div.c for comments */
 
r.quot = num / denom;
r.rem = num % denom;
if (num >= 0 && r.rem < 0) {
++r.quot;
r.rem -= denom;
}
else if (num < 0 && r.rem > 0) {
--r.quot;
r.rem += denom;
}
return (r);
}
/contrib/sdk/sources/newlib/libc/stdlib/lrand48.c
0,0 → 1,32
/*
* Copyright (c) 1993 Martin Birgmeier
* All rights reserved.
*
* You may redistribute unmodified or modified versions of this source
* code provided that the above copyright notice and this and the
* following conditions are retained.
*
* This software is provided ``as is'', and comes with no warranties
* of any kind. I shall in no event be liable for anything that happens
* to anyone/anything when using this software.
*/
 
#include "rand48.h"
 
long
_DEFUN (_lrand48_r, (r),
struct _reent *r)
{
_REENT_CHECK_RAND48(r);
__dorand48(r, __rand48_seed);
return (long)((unsigned long) __rand48_seed[2] << 15) +
((unsigned long) __rand48_seed[1] >> 1);
}
 
#ifndef _REENT_ONLY
long
_DEFUN_VOID (lrand48)
{
return _lrand48_r (_REENT);
}
#endif /* !_REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdlib/mbrtowc.c
43,33 → 43,34
#ifndef _REENT_ONLY
size_t
_DEFUN (mbrtowc, (pwc, s, n, ps),
wchar_t *pwc _AND
const char *s _AND
wchar_t *__restrict pwc _AND
const char *__restrict s _AND
size_t n _AND
mbstate_t *ps)
mbstate_t *__restrict ps)
{
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
return _mbrtowc_r (_REENT, pwc, s, n, ps);
#else
int retval = 0;
struct _reent *reent = _REENT;
 
#ifdef _MB_CAPABLE
if (ps == NULL)
{
_REENT_CHECK_MISC(_REENT);
ps = &(_REENT_MBRTOWC_STATE(_REENT));
_REENT_CHECK_MISC(reent);
ps = &(_REENT_MBRTOWC_STATE(reent));
}
#endif
 
if (s == NULL)
retval = __mbtowc (_REENT, NULL, "", 1, __locale_charset (), ps);
retval = __mbtowc (reent, NULL, "", 1, __locale_charset (), ps);
else
retval = __mbtowc (_REENT, pwc, s, n, __locale_charset (), ps);
retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);
 
if (retval == -1)
{
ps->__count = 0;
_REENT->_errno = EILSEQ;
reent->_errno = EILSEQ;
return (size_t)(-1);
}
else
/contrib/sdk/sources/newlib/libc/stdlib/mbtowc.c
7,7 → 7,7
 
ANSI_SYNOPSIS
#include <stdlib.h>
int mbtowc(wchar_t *<[pwc]>, const char *<[s]>, size_t <[n]>);
int mbtowc(wchar_t *restrict <[pwc]>, const char *restrict <[s]>, size_t <[n]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
58,18 → 58,19
 
int
_DEFUN (mbtowc, (pwc, s, n),
wchar_t *pwc _AND
const char *s _AND
wchar_t *__restrict pwc _AND
const char *__restrict s _AND
size_t n)
{
#ifdef _MB_CAPABLE
int retval = 0;
struct _reent *reent = _REENT;
mbstate_t *ps;
 
_REENT_CHECK_MISC(_REENT);
ps = &(_REENT_MBTOWC_STATE(_REENT));
_REENT_CHECK_MISC(reent);
ps = &(_REENT_MBTOWC_STATE(reent));
retval = __mbtowc (_REENT, pwc, s, n, __locale_charset (), ps);
retval = __mbtowc (reent, pwc, s, n, __locale_charset (), ps);
if (retval < 0)
{
/contrib/sdk/sources/newlib/libc/stdlib/mbtowc_r.c
19,8 → 19,8
int
_DEFUN (_mbtowc_r, (r, pwc, s, n, state),
struct _reent *r _AND
wchar_t *pwc _AND
const char *s _AND
wchar_t *__restrict pwc _AND
const char *__restrict s _AND
size_t n _AND
mbstate_t *state)
{
78,6 → 78,7
* is 2 (switch to JIS) + 2 (JIS characters) + 2 (switch back to ASCII) = 6.
*************************************************************************************/
 
#ifndef __CYGWIN__
static JIS_STATE JIS_state_table[JIS_S_NUM][JIS_C_NUM] = {
/* ESCAPE DOLLAR BRACKET AT B J NUL JIS_CHAR OTHER */
/* ASCII */ { A_ESC, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII, ASCII },
99,6 → 100,7
/* J_ESC */ { ERROR, ERROR, NOOP, ERROR, ERROR, ERROR, ERROR, ERROR, ERROR },
/* J_ESC_BR */{ ERROR, ERROR, ERROR, ERROR, MAKE_A, MAKE_A, ERROR, ERROR, ERROR },
};
#endif /* !__CYGWIN__ */
 
/* we override the mbstate_t __count field for more complex encodings and use it store a state value */
#define __state __count
/contrib/sdk/sources/newlib/libc/stdlib/mlock.c
1,3 → 1,4
#ifndef MALLOC_PROVIDED
/*
FUNCTION
<<__malloc_lock>>, <<__malloc_unlock>>---lock malloc pool
38,13 → 39,17
#include <malloc.h>
#include <sys/lock.h>
 
#ifndef __SINGLE_THREAD__
__LOCK_INIT_RECURSIVE(static, __malloc_lock_object);
#endif
 
void
__malloc_lock (ptr)
struct _reent *ptr;
{
#ifndef __SINGLE_THREAD__
__lock_acquire_recursive (__malloc_lock_object);
#endif
}
 
void
51,6 → 56,9
__malloc_unlock (ptr)
struct _reent *ptr;
{
#ifndef __SINGLE_THREAD__
__lock_release_recursive (__malloc_lock_object);
#endif
}
 
#endif
/contrib/sdk/sources/newlib/libc/stdlib/mprec.h
98,7 → 98,7
#define SI 0
#endif
 
#define Storeinc(a,b,c) (*(a)++ = (b) << 16 | (c) & 0xffff)
#define Storeinc(a,b,c) (*(a)++ = ((b) << 16) | ((c) & 0xffff))
 
/* #define P DBL_MANT_DIG */
/* Ten_pmax = floor(P*log(2)/log(5)) */
370,9 → 370,12
#define gethex __gethex
#define copybits __copybits
#define hexnan __hexnan
#define hexdig_init __hexdig_init
 
#define hexdig __hexdig
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG)
#define __get_hexdig(x) __hexdig[x] /* NOTE: must evaluate arg only once */
#else /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */
#define __get_hexdig(x) __hexdig_fun(x)
#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */
 
#define tens __mprec_tens
#define bigtens __mprec_bigtens
395,13 → 398,15
_Bigint * _EXFUN(lshift,(struct _reent *p, _Bigint *b, int k));
_Bigint * _EXFUN(diff,(struct _reent *p, _Bigint *a, _Bigint *b));
int _EXFUN(cmp,(_Bigint *a, _Bigint *b));
int _EXFUN(gethex,(struct _reent *p, _CONST char **sp, struct FPI *fpi, Long *exp, _Bigint **bp, int sign));
int _EXFUN(gethex,(struct _reent *p, _CONST char **sp, _CONST struct FPI *fpi, Long *exp, _Bigint **bp, int sign));
double _EXFUN(ratio,(_Bigint *a, _Bigint *b));
__ULong _EXFUN(any_on,(_Bigint *b, int k));
void _EXFUN(copybits,(__ULong *c, int n, _Bigint *b));
void _EXFUN(hexdig_init,(void));
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) || defined(_SMALL_HEXDIG)
unsigned char _EXFUN(__hexdig_fun,(unsigned char));
#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */
#ifdef INFNAN_CHECK
int _EXFUN(hexnan,(_CONST char **sp, struct FPI *fpi, __ULong *x0));
int _EXFUN(hexnan,(_CONST char **sp, _CONST struct FPI *fpi, __ULong *x0));
#endif
 
#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(__Long) + 2*sizeof(int))
409,7 → 414,9
extern _CONST double tinytens[];
extern _CONST double bigtens[];
extern _CONST double tens[];
extern unsigned char hexdig[];
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG)
extern _CONST unsigned char __hexdig[];
#endif /* !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) && !defined(_SMALL_HEXDIG) */
 
 
double _EXFUN(_mprec_log10,(int));
/contrib/sdk/sources/newlib/libc/stdlib/rand.c
72,20 → 72,24
void
_DEFUN (srand, (seed), unsigned int seed)
{
_REENT_CHECK_RAND48(_REENT);
_REENT_RAND_NEXT(_REENT) = seed;
struct _reent *reent = _REENT;
 
_REENT_CHECK_RAND48(reent);
_REENT_RAND_NEXT(reent) = seed;
}
 
int
_DEFUN_VOID (rand)
{
struct _reent *reent = _REENT;
 
/* This multiplier was obtained from Knuth, D.E., "The Art of
Computer Programming," Vol 2, Seminumerical Algorithms, Third
Edition, Addison-Wesley, 1998, p. 106 (line 26) & p. 108 */
_REENT_CHECK_RAND48(_REENT);
_REENT_RAND_NEXT(_REENT) =
_REENT_RAND_NEXT(_REENT) * __extension__ 6364136223846793005LL + 1;
return (int)((_REENT_RAND_NEXT(_REENT) >> 32) & RAND_MAX);
_REENT_CHECK_RAND48(reent);
_REENT_RAND_NEXT(reent) =
_REENT_RAND_NEXT(reent) * __extension__ 6364136223846793005LL + 1;
return (int)((_REENT_RAND_NEXT(reent) >> 32) & RAND_MAX);
}
 
#endif /* _REENT_ONLY */
/contrib/sdk/sources/newlib/libc/stdlib/strtod.c
11,11 → 11,11
 
ANSI_SYNOPSIS
#include <stdlib.h>
double strtod(const char *<[str]>, char **<[tail]>);
float strtof(const char *<[str]>, char **<[tail]>);
double strtod(const char *restrict <[str]>, char **restrict <[tail]>);
float strtof(const char *restrict <[str]>, char **restrict <[tail]>);
 
double _strtod_r(void *<[reent]>,
const char *<[str]>, char **<[tail]>);
const char *restrict <[str]>, char **restrict <[tail]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
128,11 → 128,17
#ifndef NO_IEEE_Scale
#define Avoid_Underflow
#undef tinytens
/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */
/* The factor of 2^106 in tinytens[4] helps us avoid setting the underflow */
/* flag unnecessarily. It leads to a song and dance at the end of strtod. */
static _CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
9007199254740992.e-256
static _CONST double tinytens[] = { 1e-16, 1e-32,
#ifdef _DOUBLE_IS_32BITS
0.0, 0.0, 0.0
#else
1e-64, 1e-128,
9007199254740992. * 9007199254740992.e-256
#endif
};
 
#endif
#endif
 
144,6 → 150,28
#define Rounding Flt_Rounds
#endif
 
#ifdef Avoid_Underflow /*{*/
static double
_DEFUN (sulp, (x, scale),
U x _AND
int scale)
{
U u;
double rv;
int i;
 
rv = ulp(dval(x));
if (!scale || (i = 2*P + 1 - ((dword0(x) & Exp_mask) >> Exp_shift)) <= 0)
return rv; /* Is there an example where i <= 0 ? */
dword0(u) = Exp_1 + (i << Exp_shift);
#ifndef _DOUBLE_IS_32BITS
dword1(u) = 0;
#endif
return rv * u.d;
}
#endif /*}*/
 
 
#ifndef NO_HEX_FP
 
static void
208,8 → 236,8
double
_DEFUN (_strtod_r, (ptr, s00, se),
struct _reent *ptr _AND
_CONST char *s00 _AND
char **se)
_CONST char *__restrict s00 _AND
char **__restrict se)
{
#ifdef Avoid_Underflow
int scale;
221,7 → 249,10
U aadj1, rv, rv0;
Long L;
__ULong y, z;
_Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
_Bigint *bb = NULL, *bb1, *bd = NULL, *bd0, *bs = NULL, *delta = NULL;
#ifdef Avoid_Underflow
__ULong Lsb, Lsb1;
#endif
#ifdef SET_INEXACT
int inexact, oldinexact;
#endif
256,7 → 287,7
if (*s == '0') {
#ifndef NO_HEX_FP
{
static FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
static _CONST FPI fpi = { 53, 1-1023-53+1, 2046-1023-53+1, 1, SI };
Long exp;
__ULong bits[2];
switch(s[1]) {
279,6 → 310,8
switch((i = gethex(ptr, &s, &fpi1, &exp, &bb, sign)) & STRTOG_Retmask) {
case STRTOG_NoNumber:
s = s00;
sign = 0;
/* FALLTHROUGH */
case STRTOG_Zero:
break;
default:
299,17 → 332,15
}
s0 = s;
y = z = 0;
for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++) {
if (nd < DBL_DIG + 1) {
for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
if (nd < 9)
y = 10*y + c - '0';
else
z = 10*z + c - '0';
}
}
nd0 = nd;
if (strncmp (s, _localeconv_r (ptr)->decimal_point,
strlen (_localeconv_r (ptr)->decimal_point)) == 0) {
strlen (_localeconv_r (ptr)->decimal_point)) == 0)
{
decpt = 1;
c = *(s += strlen (_localeconv_r (ptr)->decimal_point));
if (!nd) {
327,24 → 358,16
have_dig:
nz++;
if (c -= '0') {
for(i = 1; i < nz; i++) {
if (nd <= DBL_DIG + 1) {
if (nd + i < 10)
nf += nz;
for(i = 1; i < nz; i++)
if (nd++ < 9)
y *= 10;
else
else if (nd <= DBL_DIG + 1)
z *= 10;
}
}
if (nd <= DBL_DIG + 1) {
if (nd + i < 10)
if (nd++ < 9)
y = 10*y + c;
else
else if (nd <= DBL_DIG + 1)
z = 10*z + c;
}
if (nd <= DBL_DIG + 1) {
nf += nz;
nd += nz;
}
nz = 0;
}
}
392,7 → 415,7
#ifdef INFNAN_CHECK
/* Check for Nan and Infinity */
__ULong bits[2];
static FPI fpinan = /* only 52 explicit bits */
static _CONST FPI fpinan = /* only 52 explicit bits */
{ 52, 1-1023-53+1, 2046-1023-53+1, 1, SI };
if (!decpt)
switch(c) {
693,12 → 716,20
/* Put digits into bd: true value = bd * 10^e */
 
bd0 = s2b(ptr, s0, nd0, nd, y);
if (bd0 == NULL)
goto ovfl;
 
for(;;) {
bd = Balloc(ptr,bd0->_k);
if (bd == NULL)
goto ovfl;
Bcopy(bd, bd0);
bb = d2b(ptr,dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
if (bb == NULL)
goto ovfl;
bs = i2b(ptr,1);
if (bs == NULL)
goto ovfl;
 
if (e >= 0) {
bb2 = bb5 = 0;
718,12 → 749,19
bs2++;
#endif
#ifdef Avoid_Underflow
Lsb = LSB;
Lsb1 = 0;
j = bbe - scale;
i = j + bbbits - 1; /* logb(rv) */
if (i < Emin) /* denormal */
j += P - Emin;
j = P + 1 - bbbits;
if (i < Emin) { /* denormal */
i = Emin - i;
j -= i;
if (i < 32)
Lsb <<= i;
else
j = P + 1 - bbbits;
Lsb1 = Lsb << (i-32);
}
#else /*Avoid_Underflow*/
#ifdef Sudden_Underflow
#ifdef IBM
755,19 → 793,37
}
if (bb5 > 0) {
bs = pow5mult(ptr, bs, bb5);
if (bs == NULL)
goto ovfl;
bb1 = mult(ptr, bs, bb);
if (bb1 == NULL)
goto ovfl;
Bfree(ptr, bb);
bb = bb1;
}
if (bb2 > 0)
if (bb2 > 0) {
bb = lshift(ptr, bb, bb2);
if (bd5 > 0)
if (bb == NULL)
goto ovfl;
}
if (bd5 > 0) {
bd = pow5mult(ptr, bd, bd5);
if (bd2 > 0)
if (bd == NULL)
goto ovfl;
}
if (bd2 > 0) {
bd = lshift(ptr, bd, bd2);
if (bs2 > 0)
if (bd == NULL)
goto ovfl;
}
if (bs2 > 0) {
bs = lshift(ptr, bs, bs2);
if (bs == NULL)
goto ovfl;
}
delta = diff(ptr, bb, bd);
if (delta == NULL)
goto ovfl;
dsign = delta->_sign;
delta->_sign = 0;
i = cmp(delta, bs);
854,7 → 910,9
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
adj *= ulp(dval(rv));
if (dsign)
if (dsign) {
if (dword0(rv) == Big0 && dword1(rv) == Big1)
goto ovfl;
dval(rv) += adj;
else
dval(rv) -= adj;
904,6 → 962,8
#endif
0xffffffff)) {
/*boundary case -- increment exponent*/
if (dword0(rv) == Big0 && dword1(rv) == Big1)
goto ovfl;
dword0(rv) = (dword0(rv) & Exp_mask)
+ Exp_msk1
#ifdef IBM
962,14 → 1022,31
#endif
}
#ifndef ROUND_BIASED
#ifdef Avoid_Underflow
if (Lsb1) {
if (!(dword0(rv) & Lsb1))
break;
}
else if (!(dword1(rv) & Lsb))
break;
#else
if (!(dword1(rv) & LSB))
break;
#endif
#endif
if (dsign)
#ifdef Avoid_Underflow
dval(rv) += sulp(rv, scale);
#else
dval(rv) += ulp(dval(rv));
#endif
#ifndef ROUND_BIASED
else {
#ifdef Avoid_Underflow
dval(rv) -= sulp(rv, scale);
#else
dval(rv) -= ulp(dval(rv));
#endif
#ifndef Sudden_Underflow
if (!dval(rv))
goto undfl;
1046,7 → 1123,7
#ifdef Avoid_Underflow
if (scale && y <= 2*P*Exp_msk1) {
if (aadj <= 0x7fffffff) {
if ((z = aadj) <= 0)
if ((z = aadj) == 0)
z = 1;
aadj = z;
dval(aadj1) = dsign ? aadj : -aadj;
1178,7 → 1255,7
 
double
_DEFUN (strtod, (s00, se),
_CONST char *s00 _AND char **se)
_CONST char *__restrict s00 _AND char **__restrict se)
{
return _strtod_r (_REENT, s00, se);
}
1185,8 → 1262,8
 
float
_DEFUN (strtof, (s00, se),
_CONST char *s00 _AND
char **se)
_CONST char *__restrict s00 _AND
char **__restrict se)
{
double retval = _strtod_r (_REENT, s00, se);
if (isnan (retval))
/contrib/sdk/sources/newlib/libc/stdlib/strtol.c
9,10 → 9,10
 
ANSI_SYNOPSIS
#include <stdlib.h>
long strtol(const char *<[s]>, char **<[ptr]>,int <[base]>);
long strtol(const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
long _strtol_r(void *<[reent]>,
const char *<[s]>, char **<[ptr]>,int <[base]>);
const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
133,8 → 133,8
long
_DEFUN (_strtol_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST char *nptr _AND
char **endptr _AND
_CONST char *__restrict nptr _AND
char **__restrict endptr _AND
int base)
{
register const unsigned char *s = (const unsigned char *)nptr;
216,8 → 216,8
 
long
_DEFUN (strtol, (s, ptr, base),
_CONST char *s _AND
char **ptr _AND
_CONST char *__restrict s _AND
char **__restrict ptr _AND
int base)
{
return _strtol_r (_REENT, s, ptr, base);
/contrib/sdk/sources/newlib/libc/stdlib/strtold.c
34,7 → 34,7
/* On platforms where long double is as wide as double. */
#ifdef _LDBL_EQ_DBL
long double
strtold (const char *s00, char **se)
strtold (const char *__restrict s00, char **__restrict se)
{
return strtod(s00, se);
}
/contrib/sdk/sources/newlib/libc/stdlib/strtoll.c
9,10 → 9,10
 
ANSI_SYNOPSIS
#include <stdlib.h>
long long strtoll(const char *<[s]>, char **<[ptr]>,int <[base]>);
long long strtoll(const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
long long _strtoll_r(void *<[reent]>,
const char *<[s]>, char **<[ptr]>,int <[base]>);
const char *restrict <[s]>, char **restrict <[ptr]>,int <[base]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
128,8 → 128,8
 
long long
_DEFUN (strtoll, (s, ptr, base),
_CONST char *s _AND
char **ptr _AND
_CONST char *__restrict s _AND
char **__restrict ptr _AND
int base)
{
return _strtoll_r (_REENT, s, ptr, base);
/contrib/sdk/sources/newlib/libc/stdlib/strtoll_r.c
58,8 → 58,8
long long
_DEFUN (_strtoll_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST char *nptr _AND
char **endptr _AND
_CONST char *__restrict nptr _AND
char **__restrict endptr _AND
int base)
{
register const unsigned char *s = (const unsigned char *)nptr;
/contrib/sdk/sources/newlib/libc/stdlib/strtoul.c
9,11 → 9,11
 
ANSI_SYNOPSIS
#include <stdlib.h>
unsigned long strtoul(const char *<[s]>, char **<[ptr]>,
unsigned long strtoul(const char *restrict <[s]>, char **restrict <[ptr]>,
int <[base]>);
 
unsigned long _strtoul_r(void *<[reent]>, const char *<[s]>,
char **<[ptr]>, int <[base]>);
unsigned long _strtoul_r(void *<[reent]>, const char *restrict <[s]>,
char **restrict <[ptr]>, int <[base]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
134,8 → 134,8
unsigned long
_DEFUN (_strtoul_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST char *nptr _AND
char **endptr _AND
_CONST char *__restrict nptr _AND
char **__restrict endptr _AND
int base)
{
register const unsigned char *s = (const unsigned char *)nptr;
196,8 → 196,8
 
unsigned long
_DEFUN (strtoul, (s, ptr, base),
_CONST char *s _AND
char **ptr _AND
_CONST char *__restrict s _AND
char **__restrict ptr _AND
int base)
{
return _strtoul_r (_REENT, s, ptr, base);
/contrib/sdk/sources/newlib/libc/stdlib/strtoull.c
9,11 → 9,11
 
ANSI_SYNOPSIS
#include <stdlib.h>
unsigned long long strtoull(const char *<[s]>, char **<[ptr]>,
unsigned long long strtoull(const char *restrict <[s]>, char **restrict <[ptr]>,
int <[base]>);
 
unsigned long long _strtoull_r(void *<[reent]>, const char *<[s]>,
char **<[ptr]>, int <[base]>);
unsigned long long _strtoull_r(void *<[reent]>, const char *restrict <[s]>,
char **restrict <[ptr]>, int <[base]>);
 
TRAD_SYNOPSIS
#include <stdlib.h>
129,8 → 129,8
 
unsigned long long
_DEFUN (strtoull, (s, ptr, base),
_CONST char *s _AND
char **ptr _AND
_CONST char *__restrict s _AND
char **__restrict ptr _AND
int base)
{
return _strtoull_r (_REENT, s, ptr, base);
/contrib/sdk/sources/newlib/libc/stdlib/strtoull_r.c
59,8 → 59,8
unsigned long long
_DEFUN (_strtoull_r, (rptr, nptr, endptr, base),
struct _reent *rptr _AND
_CONST char *nptr _AND
char **endptr _AND
_CONST char *__restrict nptr _AND
char **__restrict endptr _AND
int base)
{
register const unsigned char *s = (const unsigned char *)nptr;
/contrib/sdk/sources/newlib/libc/stdlib/system.c
61,6 → 61,9
#include <_syslist.h>
#include <reent.h>
 
#if defined (unix) || defined (__CYGWIN__)
static int _EXFUN(do_system, (struct _reent *ptr _AND _CONST char *s));
#endif
 
int
_DEFUN(_system_r, (ptr, s),
67,10 → 70,33
struct _reent *ptr _AND
_CONST char *s)
{
#if defined(HAVE_SYSTEM)
return _system (s);
ptr = ptr;
#elif defined(NO_EXEC)
if (s == NULL)
return 0;
errno = ENOSYS;
return -1;
#else
 
/* ??? How to handle (s == NULL) here is not exactly clear.
If _fork_r fails, that's not really a justification for returning 0.
For now we always return 0 and leave it to each target to explicitly
handle otherwise (this can always be relaxed in the future). */
 
#if defined (unix) || defined (__CYGWIN__)
if (s == NULL)
return 1;
return do_system (ptr, s);
#else
if (s == NULL)
return 0;
errno = ENOSYS;
return -1;
#endif
 
#endif
}
 
#ifndef _REENT_ONLY
83,3 → 109,83
}
 
#endif
#if defined (unix) && !defined (__CYGWIN__) && !defined(__rtems__)
extern char **environ;
 
/* Only deal with a pointer to environ, to work around subtle bugs with shared
libraries and/or small data systems where the user declares his own
'environ'. */
static char ***p_environ = &environ;
 
static int
_DEFUN(do_system, (ptr, s),
struct _reent *ptr _AND
_CONST char *s)
{
char *argv[4];
int pid, status;
 
argv[0] = "sh";
argv[1] = "-c";
argv[2] = (char *) s;
argv[3] = NULL;
 
if ((pid = _fork_r (ptr)) == 0)
{
_execve ("/bin/sh", argv, *p_environ);
exit (100);
}
else if (pid == -1)
return -1;
else
{
int rc = _wait_r (ptr, &status);
if (rc == -1)
return -1;
status = (status >> 8) & 0xff;
return status;
}
}
#endif
 
#if defined (__CYGWIN__)
static int
_DEFUN(do_system, (ptr, s),
struct _reent *ptr _AND
_CONST char *s)
{
char *argv[4];
int pid, status;
 
argv[0] = "sh";
argv[1] = "-c";
argv[2] = (char *) s;
argv[3] = NULL;
 
if ((pid = vfork ()) == 0)
{
/* ??? It's not clear what's the right path to take (pun intended :-).
There won't be an "sh" in any fixed location so we need each user
to be able to say where to find "sh". That suggests using an
environment variable, but after a few more such situations we may
have too many of them. */
char *sh = getenv ("SH_PATH");
if (sh == NULL)
sh = "/bin/sh";
_execve (sh, argv, environ);
exit (100);
}
else if (pid == -1)
return -1;
else
{
extern int _wait (int *);
int rc = _wait (&status);
if (rc == -1)
return -1;
status = (status >> 8) & 0xff;
return status;
}
}
#endif
/contrib/sdk/sources/newlib/libc/stdlib/wcrtomb.c
42,33 → 42,34
#ifndef _REENT_ONLY
size_t
_DEFUN (wcrtomb, (s, wc, ps),
char *s _AND
char *__restrict s _AND
wchar_t wc _AND
mbstate_t *ps)
mbstate_t *__restrict ps)
{
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
return _wcrtomb_r (_REENT, s, wc, ps);
#else
int retval = 0;
struct _reent *reent = _REENT;
char buf[10];
 
#ifdef _MB_CAPABLE
if (ps == NULL)
{
_REENT_CHECK_MISC(_REENT);
ps = &(_REENT_WCRTOMB_STATE(_REENT));
_REENT_CHECK_MISC(reent);
ps = &(_REENT_WCRTOMB_STATE(reent));
}
#endif
 
if (s == NULL)
retval = __wctomb (_REENT, buf, L'\0', __locale_charset (), ps);
retval = __wctomb (reent, buf, L'\0', __locale_charset (), ps);
else
retval = __wctomb (_REENT, s, wc, __locale_charset (), ps);
retval = __wctomb (reent, s, wc, __locale_charset (), ps);
 
if (retval == -1)
{
ps->__count = 0;
_REENT->_errno = EILSEQ;
reent->_errno = EILSEQ;
return (size_t)(-1);
}
else
/contrib/sdk/sources/newlib/libc/stdlib/wctomb_r.c
81,7 → 81,7
to return extra 3 bytes. */
wchar_t tmp;
tmp = (state->__value.__wchb[0] << 16 | state->__value.__wchb[1] << 8)
- 0x10000 >> 10 | 0xd80d;
- (0x10000 >> 10 | 0xd80d);
*s++ = 0xe0 | ((tmp & 0xf000) >> 12);
*s++ = 0x80 | ((tmp & 0xfc0) >> 6);
*s++ = 0x80 | (tmp & 0x3f);