This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

strtoll, strtoull


Recently, patches were accepted to implement long long and unsigned long 
long functionality for the scanf family of functions.  This was done 
using new private functions __strtoull_r and __strtoll_r.  However, this 
functionality was not exported.

So, I've renamed __strtoull_r and __strtoll_r to _strtoull_r and 
_strtoll_r (following the pattern of _strtod_r), as well as implemented 
new functions strtoull and strtoll.  This involves the attached patch as 
well as two new files: newlib/libc/stdlib/strtoull.c and 
newlib/libc/stdlib/strtoll.c.  All four functions are now declared in 
stdlib.h.

--Chuck
2001-09-24  Charles Wilson  <cwilson@ece.gatech.edu>

	* libc/include/stdlib.h: add declarations for
	_strtoull_r, _strtoll_r, strtoull, and strtoll.
	* libc/stdio/local.h: remove declarations of
	__strtoull_r and __strtoll_r.
	* libc/stdio/vfscanf.c(__svfscanf_r): call
	_strtoull_r instead of __strtoull_r. Ditto
	_strtoll_r vs. __strtoll_r.
	* libc/stdlib/Makefile.am: add new files to
	.c list and .def list
	* libc/stdlib/Makefile.in: regenerate
	* libc/stdlib/strtoll_r.c: rename __strtoll_r
	as _strtoll_r
	* libc/stdlib/strtoull_r.c: rename __strtoull_r
	as _strtoull_r
	* libc/stdlib/strtoull.c: new file
	* libc/stdlib/strtoll.c: new file
? libc/stdlib/strtoll.c
? libc/stdlib/strtoull.c
Index: libc/include/stdlib.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/stdlib.h,v
retrieving revision 1.10
diff -u -r1.10 stdlib.h
--- stdlib.h	2001/04/27 20:43:42	1.10
+++ stdlib.h	2001/09/25 00:15:05
@@ -97,6 +97,11 @@
 long	_EXFUN(_strtol_r,(struct _reent *,const char *__n, char **_end_PTR, int __base));
 unsigned long _EXFUN(strtoul,(const char *_n_PTR, char **_end_PTR, int __base));
 unsigned long _EXFUN(_strtoul_r,(struct _reent *,const char *_n_PTR, char **_end_PTR, int __base));
+long long _EXFUN(strtoll,(const char *_n_PTR, char **_end_PTR, int __base));
+long long _EXFUN(_strtoll_r,(struct _reent *, const char *_n_PTR, char **_end_PTR, int __base));
+unsigned long long _EXFUN(strtoull,(const char *_n_PTR, char **_end_PTR, int __base));
+unsigned long long _EXFUN(_strtoull_r,(struct _reent *, const char *_n_PTR, char **_end_PTR, int __base));
+
 int	_EXFUN(system,(const char *__string));
 
 #ifndef __STRICT_ANSI__
Index: libc/stdio/local.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/local.h,v
retrieving revision 1.5
diff -u -r1.5 local.h
--- local.h	2001/09/13 21:12:32	1.5
+++ local.h	2001/09/25 00:15:07
@@ -86,12 +86,6 @@
 char *_EXFUN(_llicvt,(char *, long long, char));
 #endif
 
-/* The following are found in the stdlib directory, not here */
-#ifdef __GNUC__
-long long _EXFUN(__strtoll_r,(struct _reent *, const char *, char **, int));
-unsigned long long _EXFUN(__strtoull_r,(struct _reent *, const char *, char **, int));
-#endif
-
 #define CVT_BUF_SIZE 128
 
 #define	NDYNAMIC 4	/* add four more whenever necessary */
Index: libc/stdio/vfscanf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfscanf.c,v
retrieving revision 1.9
diff -u -r1.9 vfscanf.c
--- vfscanf.c	2001/09/13 21:12:32	1.9
+++ vfscanf.c	2001/09/25 00:15:08
@@ -822,9 +822,9 @@
 		{
 		  u_long_long resll;
 		  if (ccfn == _strtoul_r)
-		    resll = __strtoull_r (rptr, buf, (char **) NULL, base);
+		    resll = _strtoull_r (rptr, buf, (char **) NULL, base);
 		  else
-		    resll = __strtoll_r (rptr, buf, (char **) NULL, base);
+		    resll = _strtoll_r (rptr, buf, (char **) NULL, base);
 		  llp = va_arg (ap, long long*);
 		  *llp = resll;
 		}
Index: libc/stdlib/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/Makefile.am,v
retrieving revision 1.4
diff -u -r1.4 Makefile.am
--- Makefile.am	2001/09/13 21:12:33	1.4
+++ Makefile.am	2001/09/25 00:15:08
@@ -70,8 +70,10 @@
 	strdup_r.c	\
 	strtod.c	\
 	strtol.c	\
+	strtoll.c	\
 	strtoll_r.c	\
 	strtoul.c	\
+	strtoull.c	\
 	strtoull_r.c	\
 	system.c	\
 	valloc.c	\
@@ -150,7 +152,9 @@
 	rand48.def	\
 	strtod.def 	\
 	strtol.def 	\
+	strtoll.def 	\
 	strtoul.def 	\
+	strtoull.def 	\
 	system.def	\
 	wcstombs.def	\
 	wctomb.def	
Index: libc/stdlib/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/Makefile.in,v
retrieving revision 1.4
diff -u -r1.4 Makefile.in
--- Makefile.in	2001/09/13 21:12:33	1.4
+++ Makefile.in	2001/09/25 00:15:08
@@ -152,8 +152,10 @@
 	strdup_r.c	\
 	strtod.c	\
 	strtol.c	\
+	strtoll.c	\
 	strtoll_r.c	\
 	strtoul.c	\
+	strtoull.c	\
 	strtoull_r.c	\
 	system.c	\
 	valloc.c	\
@@ -198,7 +200,9 @@
 	rand48.def	\
 	strtod.def 	\
 	strtol.def 	\
+	strtoll.def 	\
 	strtoul.def 	\
+	strtoull.def 	\
 	system.def	\
 	wcstombs.def	\
 	wctomb.def	
@@ -231,9 +235,9 @@
 mblen_r.o mbstowcs.o mbstowcs_r.o mbtowc.o mbtowc_r.o mlock.o mprec.o \
 mrand48.o msize.o mstats.o mtrim.o nrand48.o putenv.o putenv_r.o \
 qsort.o rand.o rand48.o rand_r.o realloc.o seed48.o setenv.o setenv_r.o \
-srand48.o strdup.o strdup_r.o strtod.o strtol.o strtoll_r.o strtoul.o \
-strtoull_r.o system.o valloc.o wcstombs.o wcstombs_r.o wctomb.o \
-wctomb_r.o
+srand48.o strdup.o strdup_r.o strtod.o strtol.o strtoll.o strtoll_r.o \
+strtoul.o strtoull.o strtoull_r.o system.o valloc.o wcstombs.o wcstombs_r.o \
+wctomb.o wctomb_r.o
 CFLAGS = @CFLAGS@
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
Index: libc/stdlib/strtoll_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtoll_r.c,v
retrieving revision 1.1
diff -u -r1.1 strtoll_r.c
--- strtoll_r.c	2001/09/13 21:12:33	1.1
+++ strtoll_r.c	2001/09/25 00:15:09
@@ -56,7 +56,7 @@
  * alphabets and digits are each contiguous.
  */
 long long
-_DEFUN (__strtoll_r, (rptr, nptr, endptr, base),
+_DEFUN (_strtoll_r, (rptr, nptr, endptr, base),
 	struct _reent *rptr _AND
 	_CONST char *nptr _AND
 	char **endptr _AND
Index: libc/stdlib/strtoull_r.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdlib/strtoull_r.c,v
retrieving revision 1.1
diff -u -r1.1 strtoull_r.c
--- strtoull_r.c	2001/09/13 21:12:33	1.1
+++ strtoull_r.c	2001/09/25 00:15:09
@@ -57,7 +57,7 @@
  * alphabets and digits are each contiguous.
  */
 unsigned long long
-_DEFUN (__strtoull_r, (rptr, nptr, endptr, base),
+_DEFUN (_strtoull_r, (rptr, nptr, endptr, base),
 	struct _reent *rptr _AND
 	_CONST char *nptr _AND
 	char **endptr _AND
/*
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 strtoll (<[s]>, <[ptr]>, <[base]>)
        char *<[s]>;
        char **<[ptr]>;
        int <[base]>;

	long _strtoll_r (<[reent]>, <[s]>, <[ptr]>, <[base]>)
	char *<[reent]>;
        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 nonstandard.

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
/*
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 nonstandard.

<<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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]