forked from KolibriOS/kolibrios
newlib: update
git-svn-id: svn://kolibrios.org@1906 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
99
programs/develop/libraries/newlib/stdlib/__atexit.c
Normal file
99
programs/develop/libraries/newlib/stdlib/__atexit.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Common routine to implement atexit-like functionality.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
#include <sys/lock.h>
|
||||
#include "atexit.h"
|
||||
|
||||
/* Make this a weak reference to avoid pulling in malloc. */
|
||||
void * malloc(size_t) _ATTRIBUTE((__weak__));
|
||||
__LOCK_INIT_RECURSIVE(, __atexit_lock);
|
||||
|
||||
/*
|
||||
* Register a function to be performed at exit or on shared library unload.
|
||||
*/
|
||||
|
||||
int
|
||||
_DEFUN (__register_exitproc,
|
||||
(type, fn, arg, d),
|
||||
int type _AND
|
||||
void (*fn) (void) _AND
|
||||
void *arg _AND
|
||||
void *d)
|
||||
{
|
||||
struct _on_exit_args * args;
|
||||
register struct _atexit *p;
|
||||
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_acquire_recursive(__atexit_lock);
|
||||
#endif
|
||||
|
||||
p = _GLOBAL_REENT->_atexit;
|
||||
if (p == NULL)
|
||||
_GLOBAL_REENT->_atexit = p = &_GLOBAL_REENT->_atexit0;
|
||||
if (p->_ind >= _ATEXIT_SIZE)
|
||||
{
|
||||
#ifndef _ATEXIT_DYNAMIC_ALLOC
|
||||
return -1;
|
||||
#else
|
||||
/* Don't dynamically allocate the atexit array if malloc is not
|
||||
available. */
|
||||
if (!malloc)
|
||||
return -1;
|
||||
|
||||
p = (struct _atexit *) malloc (sizeof *p);
|
||||
if (p == NULL)
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release_recursive(__atexit_lock);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
p->_ind = 0;
|
||||
p->_next = _GLOBAL_REENT->_atexit;
|
||||
_GLOBAL_REENT->_atexit = p;
|
||||
#ifndef _REENT_SMALL
|
||||
p->_on_exit_args._fntypes = 0;
|
||||
p->_on_exit_args._is_cxa = 0;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
if (type != __et_atexit)
|
||||
{
|
||||
#ifdef _REENT_SMALL
|
||||
args = p->_on_exit_args_ptr;
|
||||
if (args == NULL)
|
||||
{
|
||||
if (malloc)
|
||||
args = malloc (sizeof * p->_on_exit_args_ptr);
|
||||
|
||||
if (args == NULL)
|
||||
{
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release(lock);
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
args->_fntypes = 0;
|
||||
args->_is_cxa = 0;
|
||||
p->_on_exit_args_ptr = args;
|
||||
}
|
||||
#else
|
||||
args = &p->_on_exit_args;
|
||||
#endif
|
||||
args->_fnargs[p->_ind] = arg;
|
||||
args->_fntypes |= (1 << p->_ind);
|
||||
args->_dso_handle[p->_ind] = d;
|
||||
if (type == __et_cxa)
|
||||
args->_is_cxa |= (1 << p->_ind);
|
||||
}
|
||||
p->_fns[p->_ind++] = fn;
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release_recursive(__atexit_lock);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
161
programs/develop/libraries/newlib/stdlib/__call_atexit.c
Normal file
161
programs/develop/libraries/newlib/stdlib/__call_atexit.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* COmmon routine to call call registered atexit-like routines.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
#include <sys/lock.h>
|
||||
#include "atexit.h"
|
||||
|
||||
/* Make this a weak reference to avoid pulling in free. */
|
||||
void free(void *) _ATTRIBUTE((__weak__));
|
||||
|
||||
#ifndef __SINGLE_THREAD__
|
||||
extern _LOCK_RECURSIVE_T __atexit_lock;
|
||||
#endif
|
||||
|
||||
#ifdef _WANT_REGISTER_FINI
|
||||
|
||||
/* If "__libc_fini" is defined, finalizers (either
|
||||
"__libc_fini_array", or "_fini", as appropriate) will be run after
|
||||
all user-specified atexit handlers. For example, you can define
|
||||
"__libc_fini" to "_fini" in your linker script if you want the C
|
||||
library, rather than startup code, to register finalizers. If you
|
||||
do that, then your startup code need not contain references to
|
||||
"atexit" or "exit". As a result, only applications that reference
|
||||
"exit" explicitly will pull in finalization code.
|
||||
|
||||
The choice of whether to register finalizers from libc or from
|
||||
startup code is deferred to link-time, rather than being a
|
||||
configure-time option, so that the same C library binary can be
|
||||
used with multiple BSPs, some of which register finalizers from
|
||||
startup code, while others defer to the C library. */
|
||||
extern char __libc_fini __attribute__((weak));
|
||||
|
||||
/* Register the application finalization function with atexit. These
|
||||
finalizers should run last. Therefore, we want to call atexit as
|
||||
soon as possible. */
|
||||
static void
|
||||
register_fini(void) __attribute__((constructor (0)));
|
||||
|
||||
static void
|
||||
register_fini(void)
|
||||
{
|
||||
if (&__libc_fini) {
|
||||
#ifdef HAVE_INITFINI_ARRAY
|
||||
extern void __libc_fini_array (void);
|
||||
atexit (__libc_fini_array);
|
||||
#else
|
||||
extern void _fini (void);
|
||||
atexit (_fini);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* _WANT_REGISTER_FINI */
|
||||
|
||||
/*
|
||||
* Call registered exit handlers. If D is null then all handlers are called,
|
||||
* otherwise only the handlers from that DSO are called.
|
||||
*/
|
||||
|
||||
void
|
||||
_DEFUN (__call_exitprocs, (code, d),
|
||||
int code _AND _PTR d)
|
||||
{
|
||||
register struct _atexit *p;
|
||||
struct _atexit **lastp;
|
||||
register struct _on_exit_args * args;
|
||||
register int n;
|
||||
int i;
|
||||
void (*fn) (void);
|
||||
|
||||
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_acquire_recursive(__atexit_lock);
|
||||
#endif
|
||||
|
||||
restart:
|
||||
|
||||
p = _GLOBAL_REENT->_atexit;
|
||||
lastp = &_GLOBAL_REENT->_atexit;
|
||||
while (p)
|
||||
{
|
||||
#ifdef _REENT_SMALL
|
||||
args = p->_on_exit_args_ptr;
|
||||
#else
|
||||
args = &p->_on_exit_args;
|
||||
#endif
|
||||
for (n = p->_ind - 1; n >= 0; n--)
|
||||
{
|
||||
int ind;
|
||||
|
||||
i = 1 << n;
|
||||
|
||||
/* Skip functions not from this dso. */
|
||||
if (d && (!args || args->_dso_handle[n] != d))
|
||||
continue;
|
||||
|
||||
/* Remove the function now to protect against the
|
||||
function calling exit recursively. */
|
||||
fn = p->_fns[n];
|
||||
if (n == p->_ind - 1)
|
||||
p->_ind--;
|
||||
else
|
||||
p->_fns[n] = NULL;
|
||||
|
||||
/* Skip functions that have already been called. */
|
||||
if (!fn)
|
||||
continue;
|
||||
|
||||
ind = p->_ind;
|
||||
|
||||
/* Call the function. */
|
||||
if (!args || (args->_fntypes & i) == 0)
|
||||
fn ();
|
||||
else if ((args->_is_cxa & i) == 0)
|
||||
(*((void (*)(int, _PTR)) fn))(code, args->_fnargs[n]);
|
||||
else
|
||||
(*((void (*)(_PTR)) fn))(args->_fnargs[n]);
|
||||
|
||||
/* The function we called call atexit and registered another
|
||||
function (or functions). Call these new functions before
|
||||
continuing with the already registered functions. */
|
||||
if (ind != p->_ind || *lastp != p)
|
||||
goto restart;
|
||||
}
|
||||
|
||||
#ifndef _ATEXIT_DYNAMIC_ALLOC
|
||||
break;
|
||||
#else
|
||||
/* Don't dynamically free the atexit array if free is not
|
||||
available. */
|
||||
if (!free)
|
||||
break;
|
||||
|
||||
/* Move to the next block. Free empty blocks except the last one,
|
||||
which is part of _GLOBAL_REENT. */
|
||||
if (p->_ind == 0 && p->_next)
|
||||
{
|
||||
/* Remove empty block from the list. */
|
||||
*lastp = p->_next;
|
||||
#ifdef _REENT_SMALL
|
||||
if (args)
|
||||
free (args);
|
||||
#endif
|
||||
free (p);
|
||||
p = *lastp;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastp = &p->_next;
|
||||
p = p->_next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifndef __SINGLE_THREAD__
|
||||
__lock_release_recursive(__atexit_lock);
|
||||
#endif
|
||||
|
||||
}
|
||||
72
programs/develop/libraries/newlib/stdlib/atof.c
Normal file
72
programs/develop/libraries/newlib/stdlib/atof.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<atof>>, <<atoff>>---string to double or float
|
||||
|
||||
INDEX
|
||||
atof
|
||||
INDEX
|
||||
atoff
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double atof(const char *<[s]>);
|
||||
float atoff(const char *<[s]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double atof(<[s]>)
|
||||
char *<[s]>;
|
||||
|
||||
float atoff(<[s]>)
|
||||
char *<[s]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<atof>> converts the initial portion of a string to a <<double>>.
|
||||
<<atoff>> converts the initial portion of a string to a <<float>>.
|
||||
|
||||
The functions parse the character string <[s]>,
|
||||
locating a substring which can be converted to a floating-point
|
||||
value. The substring must match the format:
|
||||
. [+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>]
|
||||
The substring converted is the longest initial
|
||||
fragment of <[s]> that has the expected format, beginning with
|
||||
the first non-whitespace character. The substring
|
||||
is empty if <<str>> is empty, consists entirely
|
||||
of whitespace, or if the first non-whitespace character is
|
||||
something other than <<+>>, <<->>, <<.>>, or a digit.
|
||||
|
||||
<<atof(<[s]>)>> is implemented as <<strtod(<[s]>, NULL)>>.
|
||||
<<atoff(<[s]>)>> is implemented as <<strtof(<[s]>, NULL)>>.
|
||||
|
||||
RETURNS
|
||||
<<atof>> returns the converted substring value, if any, as a
|
||||
<<double>>; or <<0.0>>, if no conversion could be performed.
|
||||
If the correct value is out of the range of representable values, plus
|
||||
or minus <<HUGE_VAL>> is returned, and <<ERANGE>> is stored in
|
||||
<<errno>>.
|
||||
If the correct value would cause underflow, <<0.0>> is returned
|
||||
and <<ERANGE>> is stored in <<errno>>.
|
||||
|
||||
<<atoff>> obeys the same rules as <<atof>>, except that it
|
||||
returns a <<float>>.
|
||||
|
||||
PORTABILITY
|
||||
<<atof>> is ANSI C. <<atof>>, <<atoi>>, and <<atol>> are subsumed by <<strod>>
|
||||
and <<strol>>, but are used extensively in existing code. These functions are
|
||||
less reliable, but may be faster if the argument is verified to be in a valid
|
||||
range.
|
||||
|
||||
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
|
||||
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <_ansi.h>
|
||||
|
||||
double
|
||||
_DEFUN (atof, (s),
|
||||
_CONST char *s)
|
||||
{
|
||||
return strtod (s, NULL);
|
||||
}
|
||||
132
programs/develop/libraries/newlib/stdlib/div.c
Normal file
132
programs/develop/libraries/newlib/stdlib/div.c
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<div>>---divide two integers
|
||||
|
||||
INDEX
|
||||
div
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
div_t div(int <[n]>, int <[d]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
div_t div(<[n]>, <[d]>)
|
||||
int <[n]>, <[d]>;
|
||||
|
||||
DESCRIPTION
|
||||
Divide
|
||||
@tex
|
||||
$n/d$,
|
||||
@end tex
|
||||
@ifnottex
|
||||
<[n]>/<[d]>,
|
||||
@end ifnottex
|
||||
returning quotient and remainder as two integers in a structure <<div_t>>.
|
||||
|
||||
RETURNS
|
||||
The result is represented with the structure
|
||||
|
||||
. typedef struct
|
||||
. {
|
||||
. int quot;
|
||||
. int rem;
|
||||
. } div_t;
|
||||
|
||||
where the <<quot>> field represents the quotient, and <<rem>> the
|
||||
remainder. For nonzero <[d]>, if `<<<[r]> = div(<[n]>,<[d]>);>>' then
|
||||
<[n]> equals `<<<[r]>.rem + <[d]>*<[r]>.quot>>'.
|
||||
|
||||
To divide <<long>> rather than <<int>> values, use the similar
|
||||
function <<ldiv>>.
|
||||
|
||||
PORTABILITY
|
||||
<<div>> 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> /* div_t */
|
||||
|
||||
div_t
|
||||
_DEFUN (div, (num, denom),
|
||||
int num _AND
|
||||
int denom)
|
||||
{
|
||||
div_t r;
|
||||
|
||||
r.quot = num / denom;
|
||||
r.rem = num % denom;
|
||||
/*
|
||||
* The ANSI standard says that |r.quot| <= |n/d|, where
|
||||
* n/d is to be computed in infinite precision. In other
|
||||
* words, we should always truncate the quotient towards
|
||||
* 0, never -infinity or +infinity.
|
||||
*
|
||||
* Machine division and remainer may work either way when
|
||||
* one or both of n or d is negative. If only one is
|
||||
* negative and r.quot has been truncated towards -inf,
|
||||
* r.rem will have the same sign as denom and the opposite
|
||||
* sign of num; if both are negative and r.quot has been
|
||||
* truncated towards -inf, r.rem will be positive (will
|
||||
* have the opposite sign of num). These are considered
|
||||
* `wrong'.
|
||||
*
|
||||
* If both are num and denom are positive, r will always
|
||||
* be positive.
|
||||
*
|
||||
* This all boils down to:
|
||||
* if num >= 0, but r.rem < 0, we got the wrong answer.
|
||||
* In that case, to get the right answer, add 1 to r.quot and
|
||||
* subtract denom from r.rem.
|
||||
* if num < 0, but r.rem > 0, we also have the wrong answer.
|
||||
* In this case, to get the right answer, subtract 1 from r.quot and
|
||||
* add denom to r.rem.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
66
programs/develop/libraries/newlib/stdlib/exit.c
Normal file
66
programs/develop/libraries/newlib/stdlib/exit.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1990 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* %sccs.include.redist.c%
|
||||
*/
|
||||
|
||||
/*
|
||||
FUNCTION
|
||||
<<exit>>---end program execution
|
||||
|
||||
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>> does two kinds of cleanup before ending execution of your
|
||||
program. First, it calls all application-defined cleanup functions
|
||||
you have enrolled with <<atexit>>. Second, files and streams are
|
||||
cleaned up: any pending output is delivered to the host system, each
|
||||
open file or stream is closed, and files created by <<tmpfile>> are
|
||||
deleted.
|
||||
|
||||
RETURNS
|
||||
<<exit>> does not return to its caller.
|
||||
|
||||
PORTABILITY
|
||||
ANSI C requires <<exit>>, and specifies that <<EXIT_SUCCESS>> and
|
||||
<<EXIT_FAILURE>> must be defined.
|
||||
|
||||
Supporting OS subroutines required: <<_exit>>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> /* for _exit() declaration */
|
||||
#include <reent.h>
|
||||
#include "atexit.h"
|
||||
|
||||
/*
|
||||
* Exit, flushing stdio buffers if necessary.
|
||||
*/
|
||||
|
||||
void
|
||||
_DEFUN (exit, (code),
|
||||
int code)
|
||||
{
|
||||
__call_exitprocs (code, NULL);
|
||||
|
||||
if (_GLOBAL_REENT->__cleanup)
|
||||
(*_GLOBAL_REENT->__cleanup) (_GLOBAL_REENT);
|
||||
_exit (code);
|
||||
}
|
||||
93
programs/develop/libraries/newlib/stdlib/getenv.c
Normal file
93
programs/develop/libraries/newlib/stdlib/getenv.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<getenv>>---look up environment variable
|
||||
|
||||
INDEX
|
||||
getenv
|
||||
INDEX
|
||||
environ
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
char *getenv(const char *<[name]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
char *getenv(<[name]>)
|
||||
char *<[name]>;
|
||||
|
||||
DESCRIPTION
|
||||
<<getenv>> searches the list of environment variable names and values
|
||||
(using the global pointer ``<<char **environ>>'') for a variable whose
|
||||
name matches the string at <[name]>. If a variable name matches,
|
||||
<<getenv>> returns a pointer to the associated value.
|
||||
|
||||
RETURNS
|
||||
A pointer to the (string) value of the environment variable, or
|
||||
<<NULL>> if there is no such environment variable.
|
||||
|
||||
PORTABILITY
|
||||
<<getenv>> is ANSI, but the rules for properly forming names of environment
|
||||
variables vary from one system to another.
|
||||
|
||||
<<getenv>> requires a global pointer <<environ>>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 2000 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms are permitted
|
||||
* provided that: (1) source distributions retain this entire copyright
|
||||
* notice and comment, and (2) distributions including binaries display
|
||||
* the following acknowledgement: ``This product includes software
|
||||
* developed by the University of California, Berkeley and its contributors''
|
||||
* in the documentation or other materials provided with the distribution
|
||||
* and in all advertising materials mentioning features or use of this
|
||||
* software. 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* _findenv --
|
||||
* Returns pointer to value associated with name, if any, else NULL.
|
||||
* Sets offset to be the offset of the name/value combination in the
|
||||
* environmental array, for use by setenv(3) and unsetenv(3).
|
||||
* Explicitly removes '=' in argument name.
|
||||
*
|
||||
* This routine *should* be a static; don't use it.
|
||||
*/
|
||||
|
||||
char *
|
||||
_DEFUN (_findenv, (name, offset),
|
||||
register _CONST char *name _AND
|
||||
int *offset)
|
||||
{
|
||||
return NULL; //_findenv_r (_REENT, name, offset);
|
||||
}
|
||||
|
||||
/*
|
||||
* getenv --
|
||||
* Returns ptr to value associated with name, if any, else NULL.
|
||||
*/
|
||||
|
||||
char *
|
||||
_DEFUN (getenv, (name),
|
||||
_CONST char *name)
|
||||
{
|
||||
int offset;
|
||||
|
||||
return NULL; //_findenv_r (_REENT, name, &offset);
|
||||
}
|
||||
|
||||
#endif /* !_REENT_ONLY */
|
||||
File diff suppressed because it is too large
Load Diff
91
programs/develop/libraries/newlib/stdlib/rand.c
Normal file
91
programs/develop/libraries/newlib/stdlib/rand.c
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<rand>>, <<srand>>---pseudo-random numbers
|
||||
|
||||
INDEX
|
||||
rand
|
||||
INDEX
|
||||
srand
|
||||
INDEX
|
||||
rand_r
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int rand(void);
|
||||
void srand(unsigned int <[seed]>);
|
||||
int rand_r(unsigned int *<[seed]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int rand();
|
||||
|
||||
void srand(<[seed]>)
|
||||
unsigned int <[seed]>;
|
||||
|
||||
void rand_r(<[seed]>)
|
||||
unsigned int *<[seed]>;
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
<<rand>> returns a different integer each time it is called; each
|
||||
integer is chosen by an algorithm designed to be unpredictable, so
|
||||
that you can use <<rand>> when you require a random number.
|
||||
The algorithm depends on a static variable called the ``random seed'';
|
||||
starting with a given value of the random seed always produces the
|
||||
same sequence of numbers in successive calls to <<rand>>.
|
||||
|
||||
You can set the random seed using <<srand>>; it does nothing beyond
|
||||
storing its argument in the static variable used by <<rand>>. You can
|
||||
exploit this to make the pseudo-random sequence less predictable, if
|
||||
you wish, by using some other unpredictable value (often the least
|
||||
significant parts of a time-varying value) as the random seed before
|
||||
beginning a sequence of calls to <<rand>>; or, if you wish to ensure
|
||||
(for example, while debugging) that successive runs of your program
|
||||
use the same ``random'' numbers, you can use <<srand>> to set the same
|
||||
random seed at the outset.
|
||||
|
||||
RETURNS
|
||||
<<rand>> returns the next pseudo-random integer in sequence; it is a
|
||||
number between <<0>> and <<RAND_MAX>> (inclusive).
|
||||
|
||||
<<srand>> does not return a result.
|
||||
|
||||
NOTES
|
||||
<<rand>> and <<srand>> are unsafe for multi-threaded applications.
|
||||
<<rand_r>> is thread-safe and should be used instead.
|
||||
|
||||
|
||||
PORTABILITY
|
||||
<<rand>> is required by ANSI, but the algorithm for pseudo-random
|
||||
number generation is not specified; therefore, even if you use
|
||||
the same random seed, you cannot expect the same sequence of results
|
||||
on two different systems.
|
||||
|
||||
<<rand>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
|
||||
void
|
||||
_DEFUN (srand, (seed), unsigned int seed)
|
||||
{
|
||||
_REENT_CHECK_RAND48(_REENT);
|
||||
_REENT_RAND_NEXT(_REENT) = seed;
|
||||
}
|
||||
|
||||
int
|
||||
_DEFUN_VOID (rand)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
|
||||
#endif /* _REENT_ONLY */
|
||||
179
programs/develop/libraries/newlib/stdlib/rand48.c
Normal file
179
programs/develop/libraries/newlib/stdlib/rand48.c
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
FUNCTION
|
||||
<<rand48>>, <<drand48>>, <<erand48>>, <<lrand48>>, <<nrand48>>, <<mrand48>>, <<jrand48>>, <<srand48>>, <<seed48>>, <<lcong48>>---pseudo-random number generators and initialization routines
|
||||
|
||||
INDEX
|
||||
rand48
|
||||
INDEX
|
||||
drand48
|
||||
INDEX
|
||||
erand48
|
||||
INDEX
|
||||
lrand48
|
||||
INDEX
|
||||
nrand48
|
||||
INDEX
|
||||
mrand48
|
||||
INDEX
|
||||
jrand48
|
||||
INDEX
|
||||
srand48
|
||||
INDEX
|
||||
seed48
|
||||
INDEX
|
||||
lcong48
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double drand48(void);
|
||||
double erand48(unsigned short <[xseed]>[3]);
|
||||
long lrand48(void);
|
||||
long nrand48(unsigned short <[xseed]>[3]);
|
||||
long mrand48(void);
|
||||
long jrand48(unsigned short <[xseed]>[3]);
|
||||
void srand48(long <[seed]>);
|
||||
unsigned short *seed48(unsigned short <[xseed]>[3]);
|
||||
void lcong48(unsigned short <[p]>[7]);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
double drand48();
|
||||
|
||||
double erand48(<[xseed]>)
|
||||
unsigned short <[xseed]>[3];
|
||||
|
||||
long lrand48();
|
||||
|
||||
long nrand48(<[xseed]>)
|
||||
unsigned short <[xseed]>[3];
|
||||
|
||||
long mrand48();
|
||||
|
||||
long jrand48(<[xseed]>)
|
||||
unsigned short <[xseed]>[3];
|
||||
|
||||
void srand48(<[seed]>)
|
||||
long <[seed]>;
|
||||
|
||||
unsigned short *seed48(<[xseed]>)
|
||||
unsigned short <[xseed]>[3];
|
||||
|
||||
void lcong48(<[p]>)
|
||||
unsigned short <[p]>[7];
|
||||
|
||||
DESCRIPTION
|
||||
The <<rand48>> family of functions generates pseudo-random numbers
|
||||
using a linear congruential algorithm working on integers 48 bits in size.
|
||||
The particular formula employed is
|
||||
r(n+1) = (a * r(n) + c) mod m
|
||||
where the default values are
|
||||
for the multiplicand a = 0xfdeece66d = 25214903917 and
|
||||
the addend c = 0xb = 11. The modulo is always fixed at m = 2 ** 48.
|
||||
r(n) is called the seed of the random number generator.
|
||||
|
||||
For all the six generator routines described next, the first
|
||||
computational step is to perform a single iteration of the algorithm.
|
||||
|
||||
<<drand48>> and <<erand48>>
|
||||
return values of type double. The full 48 bits of r(n+1) are
|
||||
loaded into the mantissa of the returned value, with the exponent set
|
||||
such that the values produced lie in the interval [0.0, 1.0].
|
||||
|
||||
<<lrand48>> and <<nrand48>>
|
||||
return values of type long in the range
|
||||
[0, 2**31-1]. The high-order (31) bits of
|
||||
r(n+1) are loaded into the lower bits of the returned value, with
|
||||
the topmost (sign) bit set to zero.
|
||||
|
||||
<<mrand48>> and <<jrand48>>
|
||||
return values of type long in the range
|
||||
[-2**31, 2**31-1]. The high-order (32) bits of
|
||||
r(n+1) are loaded into the returned value.
|
||||
|
||||
<<drand48>>, <<lrand48>>, and <<mrand48>>
|
||||
use an internal buffer to store r(n). For these functions
|
||||
the initial value of r(0) = 0x1234abcd330e = 20017429951246.
|
||||
|
||||
On the other hand, <<erand48>>, <<nrand48>>, and <<jrand48>>
|
||||
use a user-supplied buffer to store the seed r(n),
|
||||
which consists of an array of 3 shorts, where the zeroth member
|
||||
holds the least significant bits.
|
||||
|
||||
All functions share the same multiplicand and addend.
|
||||
|
||||
<<srand48>> is used to initialize the internal buffer r(n) of
|
||||
<<drand48>>, <<lrand48>>, and <<mrand48>>
|
||||
such that the 32 bits of the seed value are copied into the upper 32 bits
|
||||
of r(n), with the lower 16 bits of r(n) arbitrarily being set to 0x330e.
|
||||
Additionally, the constant multiplicand and addend of the algorithm are
|
||||
reset to the default values given above.
|
||||
|
||||
<<seed48>> also initializes the internal buffer r(n) of
|
||||
<<drand48>>, <<lrand48>>, and <<mrand48>>,
|
||||
but here all 48 bits of the seed can be specified in an array of 3 shorts,
|
||||
where the zeroth member specifies the lowest bits. Again,
|
||||
the constant multiplicand and addend of the algorithm are
|
||||
reset to the default values given above.
|
||||
<<seed48>> returns a pointer to an array of 3 shorts which contains
|
||||
the old seed.
|
||||
This array is statically allocated, thus its contents are lost after
|
||||
each new call to <<seed48>>.
|
||||
|
||||
Finally, <<lcong48>> allows full control over the multiplicand and
|
||||
addend used in <<drand48>>, <<erand48>>, <<lrand48>>, <<nrand48>>,
|
||||
<<mrand48>>, and <<jrand48>>,
|
||||
and the seed used in <<drand48>>, <<lrand48>>, and <<mrand48>>.
|
||||
An array of 7 shorts is passed as parameter; the first three shorts are
|
||||
used to initialize the seed; the second three are used to initialize the
|
||||
multiplicand; and the last short is used to initialize the addend.
|
||||
It is thus not possible to use values greater than 0xffff as the addend.
|
||||
|
||||
Note that all three methods of seeding the random number generator
|
||||
always also set the multiplicand and addend for any of the six
|
||||
generator calls.
|
||||
|
||||
For a more powerful random number generator, see <<random>>.
|
||||
|
||||
PORTABILITY
|
||||
SUS requires these functions.
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
#include "rand48.h"
|
||||
|
||||
void
|
||||
_DEFUN (__dorand48, (r, xseed),
|
||||
struct _reent *r _AND
|
||||
unsigned short xseed[3])
|
||||
{
|
||||
unsigned long accu;
|
||||
unsigned short temp[2];
|
||||
|
||||
_REENT_CHECK_RAND48(r);
|
||||
accu = (unsigned long) __rand48_mult[0] * (unsigned long) xseed[0] +
|
||||
(unsigned long) __rand48_add;
|
||||
temp[0] = (unsigned short) accu; /* lower 16 bits */
|
||||
accu >>= sizeof(unsigned short) * 8;
|
||||
accu += (unsigned long) __rand48_mult[0] * (unsigned long) xseed[1] +
|
||||
(unsigned long) __rand48_mult[1] * (unsigned long) xseed[0];
|
||||
temp[1] = (unsigned short) accu; /* middle 16 bits */
|
||||
accu >>= sizeof(unsigned short) * 8;
|
||||
accu += __rand48_mult[0] * xseed[2] + __rand48_mult[1] * xseed[1] + __rand48_mult[2] * xseed[0];
|
||||
xseed[0] = temp[0];
|
||||
xseed[1] = temp[1];
|
||||
xseed[2] = (unsigned short) accu;
|
||||
}
|
||||
37
programs/develop/libraries/newlib/stdlib/rand_r.c
Normal file
37
programs/develop/libraries/newlib/stdlib/rand_r.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Pseudo-random generator based on Minimal Standard by
|
||||
Lewis, Goodman, and Miller in 1969.
|
||||
|
||||
I[j+1] = a*I[j] (mod m)
|
||||
|
||||
where a = 16807
|
||||
m = 2147483647
|
||||
|
||||
Using Schrage's algorithm, a*I[j] (mod m) can be rewritten as:
|
||||
|
||||
a*(I[j] mod q) - r*{I[j]/q} if >= 0
|
||||
a*(I[j] mod q) - r*{I[j]/q} + m otherwise
|
||||
|
||||
where: {} denotes integer division
|
||||
q = {m/a} = 127773
|
||||
r = m (mod a) = 2836
|
||||
|
||||
note that the seed value of 0 cannot be used in the calculation as
|
||||
it results in 0 itself
|
||||
*/
|
||||
|
||||
int
|
||||
_DEFUN (rand_r, (seed), unsigned int *seed)
|
||||
{
|
||||
long k;
|
||||
long s = (long)(*seed);
|
||||
if (s == 0)
|
||||
s = 0x12345987;
|
||||
k = s / 127773;
|
||||
s = 16807 * (s - k * 127773) - 2836 * k;
|
||||
if (s < 0)
|
||||
s += 2147483647;
|
||||
(*seed) = (unsigned int)s;
|
||||
return (int)(s & RAND_MAX);
|
||||
}
|
||||
44
programs/develop/libraries/newlib/stdlib/seed48.c
Normal file
44
programs/develop/libraries/newlib/stdlib/seed48.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
unsigned short *
|
||||
_DEFUN (_seed48_r, (r, xseed),
|
||||
struct _reent *r _AND
|
||||
unsigned short xseed[3])
|
||||
{
|
||||
static unsigned short sseed[3];
|
||||
|
||||
_REENT_CHECK_RAND48(r);
|
||||
sseed[0] = __rand48_seed[0];
|
||||
sseed[1] = __rand48_seed[1];
|
||||
sseed[2] = __rand48_seed[2];
|
||||
__rand48_seed[0] = xseed[0];
|
||||
__rand48_seed[1] = xseed[1];
|
||||
__rand48_seed[2] = xseed[2];
|
||||
__rand48_mult[0] = _RAND48_MULT_0;
|
||||
__rand48_mult[1] = _RAND48_MULT_1;
|
||||
__rand48_mult[2] = _RAND48_MULT_2;
|
||||
__rand48_add = _RAND48_ADD;
|
||||
return sseed;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
unsigned short *
|
||||
_DEFUN (seed48, (xseed),
|
||||
unsigned short xseed[3])
|
||||
{
|
||||
return _seed48_r (_REENT, xseed);
|
||||
}
|
||||
#endif /* !_REENT_ONLY */
|
||||
38
programs/develop/libraries/newlib/stdlib/srand48.c
Normal file
38
programs/develop/libraries/newlib/stdlib/srand48.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
_VOID
|
||||
_DEFUN (_srand48_r, (r, seed),
|
||||
struct _reent *r _AND
|
||||
long seed)
|
||||
{
|
||||
_REENT_CHECK_RAND48(r);
|
||||
__rand48_seed[0] = _RAND48_SEED_0;
|
||||
__rand48_seed[1] = (unsigned short) seed;
|
||||
__rand48_seed[2] = (unsigned short) ((unsigned long)seed >> 16);
|
||||
__rand48_mult[0] = _RAND48_MULT_0;
|
||||
__rand48_mult[1] = _RAND48_MULT_1;
|
||||
__rand48_mult[2] = _RAND48_MULT_2;
|
||||
__rand48_add = _RAND48_ADD;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
_VOID
|
||||
_DEFUN (srand48, (seed),
|
||||
long seed)
|
||||
{
|
||||
_srand48_r (_REENT, seed);
|
||||
}
|
||||
#endif /* !_REENT_ONLY */
|
||||
@@ -300,10 +300,10 @@ _DEFUN (_strtod_r, (ptr, s00, se),
|
||||
s0 = s;
|
||||
y = z = 0;
|
||||
for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
|
||||
if (nd < 9)
|
||||
y = 10*y + c - '0';
|
||||
if (nd < 9)
|
||||
y = 10*y + c - '0';
|
||||
else if (nd < 16)
|
||||
z = 10*z + c - '0';
|
||||
z = 10*z + c - '0';
|
||||
nd0 = nd;
|
||||
if (strncmp (s, _localeconv_r (ptr)->decimal_point,
|
||||
strlen (_localeconv_r (ptr)->decimal_point)) == 0)
|
||||
@@ -328,13 +328,13 @@ _DEFUN (_strtod_r, (ptr, s00, se),
|
||||
nf += nz;
|
||||
for(i = 1; i < nz; i++)
|
||||
if (nd++ < 9)
|
||||
y *= 10;
|
||||
y *= 10;
|
||||
else if (nd <= DBL_DIG + 1)
|
||||
z *= 10;
|
||||
z *= 10;
|
||||
if (nd++ < 9)
|
||||
y = 10*y + c;
|
||||
y = 10*y + c;
|
||||
else if (nd <= DBL_DIG + 1)
|
||||
z = 10*z + c;
|
||||
z = 10*z + c;
|
||||
nz = 0;
|
||||
}
|
||||
}
|
||||
|
||||
42
programs/develop/libraries/newlib/stdlib/strtold.c
Normal file
42
programs/develop/libraries/newlib/stdlib/strtold.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
(C) Copyright IBM Corp. 2009
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* 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.
|
||||
* Neither the name of IBM 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 COPYRIGHT HOLDERS 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 COPYRIGHT OWNER 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 "local.h"
|
||||
|
||||
/* On platforms where long double is as wide as double. */
|
||||
#ifdef _LDBL_EQ_DBL
|
||||
long double
|
||||
strtold (const char *s00, char **se)
|
||||
{
|
||||
return strtod(s00, se);
|
||||
}
|
||||
#endif /* _LDBL_EQ_DBL */
|
||||
|
||||
138
programs/develop/libraries/newlib/stdlib/strtoll.c
Normal file
138
programs/develop/libraries/newlib/stdlib/strtoll.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strtoll>>---string to long long
|
||||
|
||||
INDEX
|
||||
strtoll
|
||||
INDEX
|
||||
_strtoll_r
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
long long strtoll(const char *<[s]>, char **<[ptr]>,int <[base]>);
|
||||
|
||||
long long _strtoll_r(void *<[reent]>,
|
||||
const char *<[s]>, char **<[ptr]>,int <[base]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
long long strtoll (<[s]>, <[ptr]>, <[base]>)
|
||||
const char *<[s]>;
|
||||
char **<[ptr]>;
|
||||
int <[base]>;
|
||||
|
||||
long long _strtoll_r (<[reent]>, <[s]>, <[ptr]>, <[base]>)
|
||||
char *<[reent]>;
|
||||
const char *<[s]>;
|
||||
char **<[ptr]>;
|
||||
int <[base]>;
|
||||
|
||||
DESCRIPTION
|
||||
The function <<strtoll>> converts the string <<*<[s]>>> to
|
||||
a <<long long>>. First, it breaks down the string into three parts:
|
||||
leading whitespace, which is ignored; a subject string consisting
|
||||
of characters resembling an integer in the radix specified by <[base]>;
|
||||
and a trailing portion consisting of zero or more unparseable characters,
|
||||
and always including the terminating null character. Then, it attempts
|
||||
to convert the subject string into a <<long long>> and returns the
|
||||
result.
|
||||
|
||||
If the value of <[base]> is 0, the subject string is expected to look
|
||||
like a normal C integer constant: an optional sign, a possible `<<0x>>'
|
||||
indicating a hexadecimal base, and a number. If <[base]> is between
|
||||
2 and 36, the expected form of the subject is a sequence of letters
|
||||
and digits representing an integer in the radix specified by <[base]>,
|
||||
with an optional plus or minus sign. The letters <<a>>--<<z>> (or,
|
||||
equivalently, <<A>>--<<Z>>) are used to signify values from 10 to 35;
|
||||
only letters whose ascribed values are less than <[base]> are
|
||||
permitted. If <[base]> is 16, a leading <<0x>> is permitted.
|
||||
|
||||
The subject sequence is the longest initial sequence of the input
|
||||
string that has the expected form, starting with the first
|
||||
non-whitespace character. If the string is empty or consists entirely
|
||||
of whitespace, or if the first non-whitespace character is not a
|
||||
permissible letter or digit, the subject string is empty.
|
||||
|
||||
If the subject string is acceptable, and the value of <[base]> is zero,
|
||||
<<strtoll>> attempts to determine the radix from the input string. A
|
||||
string with a leading <<0x>> is treated as a hexadecimal value; a string with
|
||||
a leading 0 and no <<x>> is treated as octal; all other strings are
|
||||
treated as decimal. If <[base]> is between 2 and 36, it is used as the
|
||||
conversion radix, as described above. If the subject string begins with
|
||||
a minus sign, the value is negated. Finally, a pointer to the first
|
||||
character past the converted subject string is stored in <[ptr]>, if
|
||||
<[ptr]> is not <<NULL>>.
|
||||
|
||||
If the subject string is empty (or not in acceptable form), no conversion
|
||||
is performed and the value of <[s]> is stored in <[ptr]> (if <[ptr]> is
|
||||
not <<NULL>>).
|
||||
|
||||
The alternate function <<_strtoll_r>> is a reentrant version. The
|
||||
extra argument <[reent]> is a pointer to a reentrancy structure.
|
||||
|
||||
RETURNS
|
||||
<<strtoll>> returns the converted value, if any. If no conversion was
|
||||
made, 0 is returned.
|
||||
|
||||
<<strtoll>> returns <<LONG_LONG_MAX>> or <<LONG_LONG_MIN>> if the magnitude of
|
||||
the converted value is too large, and sets <<errno>> to <<ERANGE>>.
|
||||
|
||||
PORTABILITY
|
||||
<<strtoll>> is ANSI.
|
||||
|
||||
No supporting OS subroutines are required.
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 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 <_ansi.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
long long
|
||||
_DEFUN (strtoll, (s, ptr, base),
|
||||
_CONST char *s _AND
|
||||
char **ptr _AND
|
||||
int base)
|
||||
{
|
||||
return _strtoll_r (_REENT, s, ptr, base);
|
||||
}
|
||||
|
||||
#endif
|
||||
140
programs/develop/libraries/newlib/stdlib/strtoll_r.c
Normal file
140
programs/develop/libraries/newlib/stdlib/strtoll_r.c
Normal file
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
This code is based on strtoul.c which has the following copyright.
|
||||
It is used to convert a string into a signed long long.
|
||||
|
||||
long long _strtoll_r (struct _reent *rptr, const char *s,
|
||||
char **ptr, int base);
|
||||
*/
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990 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.
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <_ansi.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
|
||||
/*
|
||||
* Convert a string to a long long integer.
|
||||
*
|
||||
* Ignores `locale' stuff. Assumes that the upper and lower case
|
||||
* alphabets and digits are each contiguous.
|
||||
*/
|
||||
long long
|
||||
_DEFUN (_strtoll_r, (rptr, nptr, endptr, base),
|
||||
struct _reent *rptr _AND
|
||||
_CONST char *nptr _AND
|
||||
char **endptr _AND
|
||||
int base)
|
||||
{
|
||||
register const unsigned char *s = (const unsigned char *)nptr;
|
||||
register unsigned long long acc;
|
||||
register int c;
|
||||
register unsigned long long cutoff;
|
||||
register int neg = 0, any, cutlim;
|
||||
|
||||
/*
|
||||
* Skip white space and pick up leading +/- sign if any.
|
||||
* If base is 0, allow 0x for hex and 0 for octal, else
|
||||
* assume decimal; if base is already 16, allow 0x.
|
||||
*/
|
||||
do {
|
||||
c = *s++;
|
||||
} while (isspace(c));
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
} else if (c == '+')
|
||||
c = *s++;
|
||||
if ((base == 0 || base == 16) &&
|
||||
c == '0' && (*s == 'x' || *s == 'X')) {
|
||||
c = s[1];
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
if (base == 0)
|
||||
base = c == '0' ? 8 : 10;
|
||||
|
||||
/*
|
||||
* Compute the cutoff value between legal numbers and illegal
|
||||
* numbers. That is the largest legal value, divided by the
|
||||
* base. An input number that is greater than this value, if
|
||||
* followed by a legal input character, is too big. One that
|
||||
* is equal to this value may be valid or not; the limit
|
||||
* between valid and invalid numbers is then based on the last
|
||||
* digit. For instance, if the range for longs is
|
||||
* [-2147483648..2147483647] and the input base is 10,
|
||||
* cutoff will be set to 214748364 and cutlim to either
|
||||
* 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
|
||||
* a value > 214748364, or equal but the next digit is > 7 (or 8),
|
||||
* the number is too big, and we will return a range error.
|
||||
*
|
||||
* Set any if any `digits' consumed; make it negative to indicate
|
||||
* overflow.
|
||||
*/
|
||||
cutoff = neg ? -(unsigned long long)LONG_LONG_MIN : LONG_LONG_MAX;
|
||||
cutlim = cutoff % (unsigned long long)base;
|
||||
cutoff /= (unsigned long long)base;
|
||||
for (acc = 0, any = 0;; c = *s++) {
|
||||
if (isdigit(c))
|
||||
c -= '0';
|
||||
else if (isalpha(c))
|
||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||
else
|
||||
break;
|
||||
if (c >= base)
|
||||
break;
|
||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
||||
any = -1;
|
||||
else {
|
||||
any = 1;
|
||||
acc *= base;
|
||||
acc += c;
|
||||
}
|
||||
}
|
||||
if (any < 0) {
|
||||
acc = neg ? LONG_LONG_MIN : LONG_LONG_MAX;
|
||||
rptr->_errno = ERANGE;
|
||||
} else if (neg)
|
||||
acc = -acc;
|
||||
if (endptr != 0)
|
||||
*endptr = (char *) (any ? (char *)s - 1 : nptr);
|
||||
return (acc);
|
||||
}
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
139
programs/develop/libraries/newlib/stdlib/strtoull.c
Normal file
139
programs/develop/libraries/newlib/stdlib/strtoull.c
Normal file
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<strtoull>>---string to unsigned long long
|
||||
|
||||
INDEX
|
||||
strtoull
|
||||
INDEX
|
||||
_strtoull_r
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
unsigned long long strtoull(const char *<[s]>, char **<[ptr]>,
|
||||
int <[base]>);
|
||||
|
||||
unsigned long long _strtoull_r(void *<[reent]>, const char *<[s]>,
|
||||
char **<[ptr]>, int <[base]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
unsigned long long strtoull(<[s]>, <[ptr]>, <[base]>)
|
||||
char *<[s]>;
|
||||
char **<[ptr]>;
|
||||
int <[base]>;
|
||||
|
||||
unsigned long long _strtoull_r(<[reent]>, <[s]>, <[ptr]>, <[base]>)
|
||||
char *<[reent]>;
|
||||
char *<[s]>;
|
||||
char **<[ptr]>;
|
||||
int <[base]>;
|
||||
|
||||
DESCRIPTION
|
||||
The function <<strtoull>> converts the string <<*<[s]>>> to
|
||||
an <<unsigned long long>>. First, it breaks down the string into three parts:
|
||||
leading whitespace, which is ignored; a subject string consisting
|
||||
of the digits meaningful in the radix specified by <[base]>
|
||||
(for example, <<0>> through <<7>> if the value of <[base]> is 8);
|
||||
and a trailing portion consisting of one or more unparseable characters,
|
||||
which always includes the terminating null character. Then, it attempts
|
||||
to convert the subject string into an unsigned long long integer, and returns the
|
||||
result.
|
||||
|
||||
If the value of <[base]> is zero, the subject string is expected to look
|
||||
like a normal C integer constant (save that no optional sign is permitted):
|
||||
a possible <<0x>> indicating hexadecimal radix, and a number.
|
||||
If <[base]> is between 2 and 36, the expected form of the subject is a
|
||||
sequence of digits (which may include letters, depending on the
|
||||
base) representing an integer in the radix specified by <[base]>.
|
||||
The letters <<a>>--<<z>> (or <<A>>--<<Z>>) are used as digits valued from
|
||||
10 to 35. If <[base]> is 16, a leading <<0x>> is permitted.
|
||||
|
||||
The subject sequence is the longest initial sequence of the input
|
||||
string that has the expected form, starting with the first
|
||||
non-whitespace character. If the string is empty or consists entirely
|
||||
of whitespace, or if the first non-whitespace character is not a
|
||||
permissible digit, the subject string is empty.
|
||||
|
||||
If the subject string is acceptable, and the value of <[base]> is zero,
|
||||
<<strtoull>> attempts to determine the radix from the input string. A
|
||||
string with a leading <<0x>> is treated as a hexadecimal value; a string with
|
||||
a leading <<0>> and no <<x>> is treated as octal; all other strings are
|
||||
treated as decimal. If <[base]> is between 2 and 36, it is used as the
|
||||
conversion radix, as described above. Finally, a pointer to the first
|
||||
character past the converted subject string is stored in <[ptr]>, if
|
||||
<[ptr]> is not <<NULL>>.
|
||||
|
||||
If the subject string is empty (that is, if <<*>><[s]> does not start
|
||||
with a substring in acceptable form), no conversion
|
||||
is performed and the value of <[s]> is stored in <[ptr]> (if <[ptr]> is
|
||||
not <<NULL>>).
|
||||
|
||||
The alternate function <<_strtoull_r>> is a reentrant version. The
|
||||
extra argument <[reent]> is a pointer to a reentrancy structure.
|
||||
|
||||
|
||||
RETURNS
|
||||
<<strtoull>> returns the converted value, if any. If no conversion was
|
||||
made, <<0>> is returned.
|
||||
|
||||
<<strtoull>> returns <<ULONG_LONG_MAX>> if the magnitude of the converted
|
||||
value is too large, and sets <<errno>> to <<ERANGE>>.
|
||||
|
||||
PORTABILITY
|
||||
<<strtoull>> is ANSI.
|
||||
|
||||
<<strtoull>> requires no supporting OS subroutines.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990 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 <_ansi.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
unsigned long long
|
||||
_DEFUN (strtoull, (s, ptr, base),
|
||||
_CONST char *s _AND
|
||||
char **ptr _AND
|
||||
int base)
|
||||
{
|
||||
return _strtoull_r (_REENT, s, ptr, base);
|
||||
}
|
||||
|
||||
#endif
|
||||
120
programs/develop/libraries/newlib/stdlib/strtoull_r.c
Normal file
120
programs/develop/libraries/newlib/stdlib/strtoull_r.c
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
This code is based on strtoul.c which has the following copyright.
|
||||
It is used to convert a string into an unsigned long long.
|
||||
|
||||
long long _strtoull_r (struct _reent *rptr, const char *s,
|
||||
char **ptr, int base);
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1990 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.
|
||||
*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <_ansi.h>
|
||||
#include <limits.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <reent.h>
|
||||
|
||||
/*
|
||||
* Convert a string to an unsigned long long integer.
|
||||
*
|
||||
* Ignores `locale' stuff. Assumes that the upper and lower case
|
||||
* alphabets and digits are each contiguous.
|
||||
*/
|
||||
unsigned long long
|
||||
_DEFUN (_strtoull_r, (rptr, nptr, endptr, base),
|
||||
struct _reent *rptr _AND
|
||||
_CONST char *nptr _AND
|
||||
char **endptr _AND
|
||||
int base)
|
||||
{
|
||||
register const unsigned char *s = (const unsigned char *)nptr;
|
||||
register unsigned long long acc;
|
||||
register int c;
|
||||
register unsigned long long cutoff;
|
||||
register int neg = 0, any, cutlim;
|
||||
|
||||
/*
|
||||
* See strtol for comments as to the logic used.
|
||||
*/
|
||||
do {
|
||||
c = *s++;
|
||||
} while (isspace(c));
|
||||
if (c == '-') {
|
||||
neg = 1;
|
||||
c = *s++;
|
||||
} else if (c == '+')
|
||||
c = *s++;
|
||||
if ((base == 0 || base == 16) &&
|
||||
c == '0' && (*s == 'x' || *s == 'X')) {
|
||||
c = s[1];
|
||||
s += 2;
|
||||
base = 16;
|
||||
}
|
||||
if (base == 0)
|
||||
base = c == '0' ? 8 : 10;
|
||||
cutoff = (unsigned long long)ULONG_LONG_MAX / (unsigned long long)base;
|
||||
cutlim = (unsigned long long)ULONG_LONG_MAX % (unsigned long long)base;
|
||||
for (acc = 0, any = 0;; c = *s++) {
|
||||
if (isdigit(c))
|
||||
c -= '0';
|
||||
else if (isalpha(c))
|
||||
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
||||
else
|
||||
break;
|
||||
if (c >= base)
|
||||
break;
|
||||
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
||||
any = -1;
|
||||
else {
|
||||
any = 1;
|
||||
acc *= base;
|
||||
acc += c;
|
||||
}
|
||||
}
|
||||
if (any < 0) {
|
||||
acc = ULONG_LONG_MAX;
|
||||
rptr->_errno = ERANGE;
|
||||
} else if (neg)
|
||||
acc = -acc;
|
||||
if (endptr != 0)
|
||||
*endptr = (char *) (any ? (char *)s - 1 : nptr);
|
||||
return (acc);
|
||||
}
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
85
programs/develop/libraries/newlib/stdlib/system.c
Normal file
85
programs/develop/libraries/newlib/stdlib/system.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
FUNCTION
|
||||
<<system>>---execute command string
|
||||
|
||||
INDEX
|
||||
system
|
||||
INDEX
|
||||
_system_r
|
||||
|
||||
ANSI_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int system(char *<[s]>);
|
||||
|
||||
int _system_r(void *<[reent]>, char *<[s]>);
|
||||
|
||||
TRAD_SYNOPSIS
|
||||
#include <stdlib.h>
|
||||
int system(<[s]>)
|
||||
char *<[s]>;
|
||||
|
||||
int _system_r(<[reent]>, <[s]>)
|
||||
char *<[reent]>;
|
||||
char *<[s]>;
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Use <<system>> to pass a command string <<*<[s]>>> to <</bin/sh>> on
|
||||
your system, and wait for it to finish executing.
|
||||
|
||||
Use ``<<system(NULL)>>'' to test whether your system has <</bin/sh>>
|
||||
available.
|
||||
|
||||
The alternate function <<_system_r>> is a reentrant version. The
|
||||
extra argument <[reent]> is a pointer to a reentrancy structure.
|
||||
|
||||
RETURNS
|
||||
<<system(NULL)>> returns a non-zero value if <</bin/sh>> is available, and
|
||||
<<0>> if it is not.
|
||||
|
||||
With a command argument, the result of <<system>> is the exit status
|
||||
returned by <</bin/sh>>.
|
||||
|
||||
PORTABILITY
|
||||
ANSI C requires <<system>>, but leaves the nature and effects of a
|
||||
command processor undefined. ANSI C does, however, specify that
|
||||
<<system(NULL)>> return zero or nonzero to report on the existence of
|
||||
a command processor.
|
||||
|
||||
POSIX.2 requires <<system>>, and requires that it invoke a <<sh>>.
|
||||
Where <<sh>> is found is left unspecified.
|
||||
|
||||
Supporting OS subroutines required: <<_exit>>, <<_execve>>, <<_fork_r>>,
|
||||
<<_wait_r>>.
|
||||
*/
|
||||
|
||||
#include <_ansi.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <_syslist.h>
|
||||
#include <reent.h>
|
||||
|
||||
|
||||
int
|
||||
_DEFUN(_system_r, (ptr, s),
|
||||
struct _reent *ptr _AND
|
||||
_CONST char *s)
|
||||
{
|
||||
if (s == NULL)
|
||||
return 0;
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef _REENT_ONLY
|
||||
|
||||
int
|
||||
_DEFUN(system, (s),
|
||||
_CONST char *s)
|
||||
{
|
||||
return _system_r (_REENT, s);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user