aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2003-11-27 19:47:19 +0000
committerJeff Johnston <jjohnstn@redhat.com>2003-11-27 19:47:19 +0000
commit6bbb700c348150b7f16b185ec63eb0c1fcc92584 (patch)
tree13268ce667a37322fd6e8d7aef7f713905e47209 /newlib
parent6dec26cd0ce7a817fc660ed59182032a44bbac5f (diff)
downloadnewlib-6bbb700c348150b7f16b185ec63eb0c1fcc92584.zip
newlib-6bbb700c348150b7f16b185ec63eb0c1fcc92584.tar.gz
newlib-6bbb700c348150b7f16b185ec63eb0c1fcc92584.tar.bz2
2003-11-27 Artem B. Bityuckiy <mail_lists@mail.ru>
Jeff Johnston <jjohnstn@redhat.com> * libc/include/stdlib.h (lldiv_t): New type. (atoll, llabs, lldiv): New prototypes. * libc/stdlib/Makefile.am: Add support for atoll, llabs, and lldiv. * libc/stdlib/stdlib.tex: Ditto. * libc/stdlib/Makefile.in: Regenerated. * libc/stdlib/atoll.c: New file. * libc/stdlib/llabs.c: Ditto. * libc/stdlib/lldiv.c: Ditto.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog12
-rw-r--r--newlib/libc/include/stdlib.h11
-rw-r--r--newlib/libc/stdlib/Makefile.am10
-rw-r--r--newlib/libc/stdlib/Makefile.in20
-rw-r--r--newlib/libc/stdlib/atoll.c73
-rw-r--r--newlib/libc/stdlib/llabs.c66
-rw-r--r--newlib/libc/stdlib/lldiv.c115
-rw-r--r--newlib/libc/stdlib/stdlib.tex12
8 files changed, 311 insertions, 8 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 257c1df..211c066 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,15 @@
+2003-11-27 Artem B. Bityuckiy <mail_lists@mail.ru>
+ Jeff Johnston <jjohnstn@redhat.com>
+
+ * libc/include/stdlib.h (lldiv_t): New type.
+ (atoll, llabs, lldiv): New prototypes.
+ * libc/stdlib/Makefile.am: Add support for atoll, llabs, and lldiv.
+ * libc/stdlib/stdlib.tex: Ditto.
+ * libc/stdlib/Makefile.in: Regenerated.
+ * libc/stdlib/atoll.c: New file.
+ * libc/stdlib/llabs.c: Ditto.
+ * libc/stdlib/lldiv.c: Ditto.
+
2003-11-26 Corinna Vinschen <corinna@vinschen.de>
* libc/include/fcntl.h: Declare syscalls only when building newlib.
diff --git a/newlib/libc/include/stdlib.h b/newlib/libc/include/stdlib.h
index 5bfe4f7..53dec3e 100644
--- a/newlib/libc/include/stdlib.h
+++ b/newlib/libc/include/stdlib.h
@@ -33,6 +33,14 @@ typedef struct
long rem; /* remainder */
} ldiv_t;
+#ifndef __STRICT_ANSI__
+typedef struct
+{
+ long long int quot; /* quotient */
+ long long int rem; /* remainder */
+} lldiv_t;
+#endif
+
#ifndef NULL
#define NULL 0
#endif
@@ -155,6 +163,9 @@ unsigned short *
_EXFUN(_seed48_r,(struct _reent *, unsigned short [3]));
_VOID _EXFUN(srand48,(long));
_VOID _EXFUN(_srand48_r,(struct _reent *, long));
+long long _EXFUN(atoll,(const char *__nptr));
+long long _EXFUN(llabs,(long long));
+lldiv_t _EXFUN(lldiv,(long long __numer, long long __denom));
long long _EXFUN(strtoll,(const char *__n, char **__end_PTR, int __base));
long long _EXFUN(_strtoll_r,(struct _reent *, const char *__n, char **__end_PTR, int __base));
unsigned long long _EXFUN(strtoull,(const char *__n, char **__end_PTR, int __base));
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index cdd7987..f6ac17c 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -69,7 +69,10 @@ EXTENDED_SOURCES = \
strtoll.c \
strtoll_r.c \
strtoull.c \
- strtoull_r.c
+ strtoull_r.c \
+ atoll.c \
+ llabs.c \
+ lldiv.c
ELIX_2_OBJS = \
a64l.$(oext) \
@@ -185,16 +188,19 @@ CHEWOUT_FILES= \
assert.def \
atexit.def \
atof.def \
- ecvtbuf.def \
atoi.def \
+ atoll.def \
calloc.def \
div.def \
+ ecvtbuf.def \
efgcvt.def \
envlock.def \
exit.def \
getenv.def \
labs.def \
ldiv.def \
+ llabs.def \
+ lldiv.def \
malloc.def \
mallocr.def \
mblen.def \
diff --git a/newlib/libc/stdlib/Makefile.in b/newlib/libc/stdlib/Makefile.in
index 6f72deb..4d0fdf8 100644
--- a/newlib/libc/stdlib/Makefile.in
+++ b/newlib/libc/stdlib/Makefile.in
@@ -1,6 +1,6 @@
-# Makefile.in generated automatically by automake 1.4 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am
-# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# with or without modifications, as long as this notice is preserved.
@@ -176,7 +176,10 @@ EXTENDED_SOURCES = \
strtoll.c \
strtoll_r.c \
strtoull.c \
- strtoull_r.c
+ strtoull_r.c \
+ atoll.c \
+ llabs.c \
+ lldiv.c
ELIX_2_OBJS = \
@@ -246,16 +249,19 @@ CHEWOUT_FILES = \
assert.def \
atexit.def \
atof.def \
- ecvtbuf.def \
atoi.def \
+ atoll.def \
calloc.def \
div.def \
+ ecvtbuf.def \
efgcvt.def \
envlock.def \
exit.def \
getenv.def \
labs.def \
ldiv.def \
+ llabs.def \
+ lldiv.def \
malloc.def \
mallocr.def \
mblen.def \
@@ -314,7 +320,8 @@ LIBS = @LIBS@
@USE_LIBTOOL_FALSE@mtrim.$(OBJEXT) nrand48.$(OBJEXT) rand48.$(OBJEXT) \
@USE_LIBTOOL_FALSE@seed48.$(OBJEXT) srand48.$(OBJEXT) strtoll.$(OBJEXT) \
@USE_LIBTOOL_FALSE@strtoll_r.$(OBJEXT) strtoull.$(OBJEXT) \
-@USE_LIBTOOL_FALSE@strtoull_r.$(OBJEXT)
+@USE_LIBTOOL_FALSE@strtoull_r.$(OBJEXT) atoll.$(OBJEXT) llabs.$(OBJEXT) \
+@USE_LIBTOOL_FALSE@lldiv.$(OBJEXT)
LTLIBRARIES = $(noinst_LTLIBRARIES)
@USE_LIBTOOL_TRUE@libstdlib_la_OBJECTS = __adjust.lo __exp10.lo \
@@ -330,7 +337,8 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
@USE_LIBTOOL_TRUE@ecvtbuf.lo efgcvt.lo erand48.lo jrand48.lo lcong48.lo \
@USE_LIBTOOL_TRUE@lrand48.lo mrand48.lo msize.lo mtrim.lo nrand48.lo \
@USE_LIBTOOL_TRUE@rand48.lo seed48.lo srand48.lo strtoll.lo \
-@USE_LIBTOOL_TRUE@strtoll_r.lo strtoull.lo strtoull_r.lo
+@USE_LIBTOOL_TRUE@strtoll_r.lo strtoull.lo strtoull_r.lo atoll.lo \
+@USE_LIBTOOL_TRUE@llabs.lo lldiv.lo
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
diff --git a/newlib/libc/stdlib/atoll.c b/newlib/libc/stdlib/atoll.c
new file mode 100644
index 0000000..1dd4ec3
--- /dev/null
+++ b/newlib/libc/stdlib/atoll.c
@@ -0,0 +1,73 @@
+/*
+FUNCTION
+<<atoll>>---convert a string to a long long integer
+
+INDEX
+ atoll
+
+ANSI_SYNOPSIS
+ #include <stdlib.h>
+ long long atoll(const char *<[str]>);
+
+TRAD_SYNOPSIS
+ #include <stdlib.h>
+ long long atoll(<[str]>)
+ const char *<[str]>;
+
+DESCRIPTION
+The function <<atoll>> converts the initial portion of the string
+pointed to by <<*<[str]>>> to a type <<long long>>. The call to
+atoll(str) should be equivalent to strtoll(str, (char **)NULL, 10)
+except that <<atoll>> doesn't detect errors.
+
+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>
+
+long long
+_DEFUN(atoll, (str),
+ _CONST char *str)
+{
+ return strtoll(str, (char **)NULL, 10);
+}
diff --git a/newlib/libc/stdlib/llabs.c b/newlib/libc/stdlib/llabs.c
new file mode 100644
index 0000000..11246c3
--- /dev/null
+++ b/newlib/libc/stdlib/llabs.c
@@ -0,0 +1,66 @@
+/*
+FUNCTION
+<<llabs>>---compute the absolute value of an long long integer.
+
+INDEX
+ llabs
+
+ANSI_SYNOPSIS
+ #include <stdlib.h>
+ long long llabs(long long j);
+
+TRAD_SYNOPSIS
+ #include <stdlib.h>
+ long long llabs(<[j]>)
+ long long <[j]>;
+
+DESCRIPTION
+The <<llabs>> function computes the absolute value of the long long integer
+argument <[j]> (also called the magnitude of <[j]>).
+
+The similar function <<labs>> uses and returns <<long>> rather than
+<<long long>> values.
+
+RETURNS
+A nonnegative long long integer.
+
+PORTABILITY
+<<llabs>> is ISO 9899 (C99) compatable.
+
+No supporting OS subroutines are required.
+*/
+
+/*-
+ * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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>
+
+long long
+_DEFUN(llabs, (j),
+ long long j)
+{
+ return (j < 0 ? -j : j);
+}
diff --git a/newlib/libc/stdlib/lldiv.c b/newlib/libc/stdlib/lldiv.c
new file mode 100644
index 0000000..6b853e4
--- /dev/null
+++ b/newlib/libc/stdlib/lldiv.c
@@ -0,0 +1,115 @@
+/*
+FUNCTION
+<<lldiv>>---divide two long long integers
+
+INDEX
+ lldiv
+
+ANSI_SYNOPSIS
+ #include <stdlib.h>
+ lldiv_t lldiv(long long <[n]>, long long <[d]>);
+
+TRAD_SYNOPSIS
+ #include <stdlib.h>
+ lldiv_t lldiv(<[n]>, <[d]>)
+ long long <[n]>, <[d]>;
+
+DESCRIPTION
+Divide
+@tex
+$n/d$,
+@end tex
+@ifnottex
+<[n]>/<[d]>,
+@end ifnottex
+returning quotient and remainder as two long long integers in a structure
+<<lldiv_t>>.
+
+RETURNS
+The result is represented with the structure
+
+. typedef struct
+. {
+. long long quot;
+. long long rem;
+. } lldiv_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 <<long>> rather than <<long long>> values, use the similar
+function <<ldiv>>.
+
+PORTABILITY
+<<lldiv>> is ISO 9899 (C99) compatable.
+
+No supporting OS subroutines are required.
+*/
+
+/*-
+ * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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>
+
+/*
+ * 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.
+ *
+ * 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.
+ */
+lldiv_t
+_DEFUN (lldiv, (number, denom),
+ long long numer _AND long long denom)
+{
+ lldiv_t retval;
+
+ retval.quot = numer / denom;
+ retval.rem = numer % denom;
+ if (numer >= 0 && retval.rem < 0) {
+ retval.quot++;
+ retval.rem -= denom;
+ }
+ return (retval);
+}
+
diff --git a/newlib/libc/stdlib/stdlib.tex b/newlib/libc/stdlib/stdlib.tex
index 5798caa..39fb915 100644
--- a/newlib/libc/stdlib/stdlib.tex
+++ b/newlib/libc/stdlib/stdlib.tex
@@ -11,6 +11,7 @@ The corresponding declarations are in the header file @file{stdlib.h}.
* atexit:: Request execution of functions at program exit
* atof:: String to double or float
* atoi:: String to integer
+* atoll:: String to long long
* calloc:: Allocate space for arrays
* div:: Divide two integers
* ecvtbuf:: Double or float to string of digits
@@ -21,6 +22,8 @@ The corresponding declarations are in the header file @file{stdlib.h}.
* getenv:: Look up environment variable
* labs:: Long integer absolute value (magnitude)
* ldiv:: Divide two long integers
+* llabs:: Long long integer absolute value (magnitude)
+* lldiv:: Divide two long long integers
* malloc:: Allocate and manage memory (malloc, realloc, free)
* mallinfo:: Get information about allocated memory
* __malloc_lock:: Lock memory pool for malloc and free
@@ -56,6 +59,9 @@ The corresponding declarations are in the header file @file{stdlib.h}.
@include stdlib/atoi.def
@page
+@include stdlib/atoll.def
+
+@page
@include stdlib/calloc.def
@page
@@ -83,6 +89,12 @@ The corresponding declarations are in the header file @file{stdlib.h}.
@include stdlib/ldiv.def
@page
+@include stdlib/llabs.def
+
+@page
+@include stdlib/lldiv.def
+
+@page
@include stdlib/malloc.def
@page