This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
Re: [ECOS] scanf(...) long long patch?
- From: Jonathan Larmour <jifl at eCosCentric dot com>
- To: fredrik at wespot dot com
- Cc: andrew at lunn dot ch,eCos Patches List <ecos-patches at ecos dot sourceware dot org>
- Date: Wed, 18 Aug 2004 15:11:27 +0100
- Subject: Re: [ECOS] scanf(...) long long patch?
- References: <5A8A17126B73AC4C83968F6C4505E3C5ECC0FD@JO-EX01.JENOPTIK.NET> <1371.217.215.197.44.1092043430.squirrel@support.wespot.se> <20040809092806.GF27052@lunn.ch> <1387.217.215.197.44.1092044258.squirrel@support.wespot.se> <20040809095604.GI27052@lunn.ch> <41174D70.5090109@eCosCentric.com> <32928.217.215.197.44.1092170565.squirrel@support.wespot.se>
fredrik@wespot.com wrote:
Yes, but Fredrik, it would be better if you generated the patch with
"cvs diff -u".
Ok, submitted below is the patch in -u-format.
The files 'strtoll.cxx' and 'strtoull.cxx' (added into
/ecos/.../stdlib/current/src) are new files and are attached as simple
text.
Thanks. Unfortunately your mailer wrapped the patch and it was corrupt.
Still, I was able to munge your previous patch to get it to apply (it was
less corrupt), and was able to use the diff -u one for reading for myself.
I've made a number of changes. Firstly the changes to existing files are
optional so people can choose not to have them (I should have done the same
for the vfnprintf changes way back, ho hum; I've named the option to leave
that open). This is because it increases the footprintf of *scanf quite a
bit because of the extra functions pulled in on top of the changes in
vfscanf itself.
Now even the new files are configurable, although that's partly just
because I want to earmark down the road those files that provide
non-standard (C89 anyway) functions so in due course we can do things like
provide stricter standards compliance (so people can be more sure about
portability).
I did not at all like long doubles being treated as integer types. It is
far less bad to treat them with lower precision, so that's what I've done.
Finally I added ChangeLog entries which you omitted.
I'll apply the patch I've attached. But can I ask if you could consider
extending the testsuite a little to support testing long long ints and
doubles too (configurably on the new options of course). I've timed out for
doing that myself.
Oh, I've also included a trivial Stdio CDL patch for the console device CDL
I've been sitting on.
Jifl
--
eCosCentric http://www.eCosCentric.com/ The eCos and RedBoot experts
--["No sense being pessimistic, it wouldn't work anyway"]-- Opinions==mine
Index: stdio/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/ChangeLog,v
retrieving revision 1.29
diff -u -5 -p -r1.29 ChangeLog
--- stdio/current/ChangeLog 16 Aug 2004 14:37:03 -0000 1.29
+++ stdio/current/ChangeLog 18 Aug 2004 14:05:52 -0000
@@ -1,5 +1,17 @@
+2004-08-18 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * cdl/stdio.cdl (CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE): Only use
+ CYGDAT_IO_SERIAL_TTY_CONSOLE if set.
+
+2004-08-18 Fredrik Hederstierna <fredrik@wespot.com>
+2004-08-18 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * src/input/vfscanf.cxx (vfscanf): Add long long and long double
+ support.
+ * cdl/stdio.cdl (CYGFUN_LIBC_STDIO_LONGLONG): Make it a new option.
+
2004-08-16 Oyvind Harboe <oyvind.harboe@zylin.com>
* src/common/stream.cxx (read): fixed performance problem with
unbuffered reads. Long unbuffered i/o read requests would cause
one roundtrip to the underlying file system for each byte, instead
Index: stdio/current/cdl/stdio.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/cdl/stdio.cdl,v
retrieving revision 1.12
diff -u -5 -p -r1.12 stdio.cdl
--- stdio/current/cdl/stdio.cdl 15 Mar 2004 15:21:43 -0000 1.12
+++ stdio/current/cdl/stdio.cdl 18 Aug 2004 14:05:52 -0000
@@ -291,11 +291,11 @@ cdl_package CYGPKG_LIBC_STDIO {
}
cdl_option CYGDAT_LIBC_STDIO_DEFAULT_CONSOLE {
display "Default console device"
flavor data
- default_value CYGDAT_IO_SERIAL_TTY_CONSOLE
+ default_value { CYGDAT_IO_SERIAL_TTY_CONSOLE ? CYGDAT_IO_SERIAL_TTY_CONSOLE : "\"/dev/null\"" }
description "
This option allows you to choose the
default console device. In the current
implementation, all these devices begin
with the prefix /dev/ and are followed by
@@ -346,10 +346,20 @@ cdl_package CYGPKG_LIBC_STDIO {
is disabled then floating point specifiers
(%e, %f, %g) are ignored, and nothing is
converted."
}
}
+
+ cdl_option CYGFUN_LIBC_STDIO_LONGLONG {
+ display "Long long support"
+ requires CYGFUN_LIBC_STDLIB_CONV_LONGLONG
+ default_value 1
+ description "
+ This option allows various functions in the C Standard I/O
+ library to support the 'long long' datatype. Doing so
+ will come with a noticeable code size penalty however."
+ }
cdl_option CYGSEM_LIBC_STDIO_THREAD_SAFE_STREAMS {
display "Thread safe I/O streams"
doc ref/libc-thread-safety.html
active_if CYGPKG_KERNEL
Index: stdio/current/src/input/vfscanf.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdio/current/src/input/vfscanf.cxx,v
retrieving revision 1.5
diff -u -5 -p -r1.5 vfscanf.cxx
--- stdio/current/src/input/vfscanf.cxx 15 Mar 2004 15:21:44 -0000 1.5
+++ stdio/current/src/input/vfscanf.cxx 18 Aug 2004 14:05:52 -0000
@@ -107,11 +107,11 @@
/*
* Flags used during conversion.
*/
#define LONG 0x01 /* l: long or double */
-#define LONGDBL 0x02 /* L: long double; unimplemented */
+#define LONGDBL 0x02 /* L: long double */
#define SHORT 0x04 /* h: short */
#define SUPPRESS 0x08 /* suppress assignment */
#define POINTER 0x10 /* weird %p pointer (`fake hex') */
#define NOSKIP 0x20 /* do not skip blanks */
@@ -144,12 +144,14 @@
#if 0
#define u_char unsigned char
#endif
#define u_char char
#define u_long unsigned long
+#define u_long_long unsigned long long
typedef unsigned long (*strtoul_t)(const char *, char **endptr, int base);
+typedef unsigned long long (*strtoull_t)(const char *, char **endptr, int base);
static u_char *
__sccl (char *tab, u_char *fmt);
@@ -198,10 +200,14 @@ vfscanf (FILE *fp, const char *fmt0, va_
mbtowc_fn_type mbtowc_fn;
int state = 0; /* used for mbtowc_fn */
#endif
strtoul_t ccfn = NULL; /* conversion function (strtol/strtoul) */
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ strtoull_t ccfnL = NULL; /* conversion function (strtoll/strtoull) */
+ long long *ll;
+#endif
char ccltab[256]; /* character class table for %[...] */
char buf[BUF]; /* buffer for numeric conversions */
Cyg_StdioStream *file = (Cyg_StdioStream *)fp;
char curr_byte;
@@ -278,15 +284,27 @@ literal:
case '*':
flags |= SUPPRESS;
goto again;
case 'l':
- flags |= LONG;
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ // check if we are using long long 'll'
+ if (flags & LONG) {
+ // change to long long
+ flags &= ~LONG;
+ flags |= LONGDBL;
+ }
+ else
+#endif
+ flags |= LONG;
+
goto again;
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
case 'L':
flags |= LONGDBL;
goto again;
+#endif
case 'h':
flags |= SHORT;
goto again;
case '0':
@@ -314,39 +332,59 @@ literal:
flags |= LONG;
/* FALLTHROUGH */
case 'd':
c = CT_INT;
ccfn = (strtoul_t)strtol;
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ if (flags & LONGDBL)
+ ccfnL = (strtoull_t)strtoll;
+#endif
base = 10;
break;
case 'i':
c = CT_INT;
ccfn = (strtoul_t)strtol;
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ if (flags & LONGDBL)
+ ccfnL = (strtoull_t)strtoll;
+#endif
base = 0;
break;
case 'O': /* compat */
flags |= LONG;
/* FALLTHROUGH */
case 'o':
c = CT_INT;
ccfn = strtoul;
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ if (flags & LONGDBL)
+ ccfnL = strtoull;
+#endif
base = 8;
break;
case 'u':
c = CT_INT;
ccfn = strtoul;
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ if (flags & LONGDBL)
+ ccfnL = strtoull;
+#endif
base = 10;
break;
case 'X': /* compat XXX */
case 'x':
flags |= PFXOK; /* enable 0x prefixing */
c = CT_INT;
ccfn = strtoul;
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ if (flags & LONGDBL)
+ ccfnL = strtoull;
+#endif
base = 16;
break;
case 'E': /* compat XXX */
case 'G': /* compat XXX */
@@ -731,14 +769,25 @@ literal:
--p;
/*(void)*/ ungetc (c, fp);
}
if ((flags & SUPPRESS) == 0)
{
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ u_long_long res;
+#else
u_long res;
+#endif
*p = 0;
- res = (*ccfn) (buf, (char **) NULL, base);
+
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ if (flags & LONGDBL)
+ res = (*ccfnL) (buf, (char **) NULL, base);
+ else
+#endif
+ res = (*ccfn) (buf, (char **) NULL, base);
+
if (flags & POINTER)
*(va_arg (ap, char **)) = (char *) (CYG_ADDRESS) res;
else if (flags & SHORT)
{
sp = va_arg (ap, short *);
@@ -747,10 +796,17 @@ literal:
else if (flags & LONG)
{
lp = va_arg (ap, long *);
*lp = res;
}
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
+ else if (flags & LONGDBL)
+ {
+ ll = va_arg (ap, long long *);
+ *ll = res;
+ }
+#endif
else
{
ip = va_arg (ap, int *);
*ip = res;
}
@@ -857,27 +913,28 @@ literal:
_CAST_VOID ungetc (c, fp);
}
if ((flags & SUPPRESS) == 0)
{
double res;
-
*p = 0;
#ifdef CYGSEM_LIBC_STDIO_SCANF_FLOATING_POINT
- res = atof (buf);
+ res = strtod( buf, NULL );
#else
res = 0.0;
#endif
if (flags & LONG)
{
dp = va_arg (ap, double *);
*dp = res;
}
+#ifdef CYGFUN_LIBC_STDIO_LONGLONG
else if (flags & LONGDBL)
{
ldp = va_arg (ap, long double *);
*ldp = res;
}
+#endif
else
{
flp = va_arg (ap, float *);
*flp = res;
}
Index: stdlib/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdlib/current/ChangeLog,v
retrieving revision 1.8
diff -u -5 -p -r1.8 ChangeLog
--- stdlib/current/ChangeLog 15 Mar 2004 15:22:22 -0000 1.8
+++ stdlib/current/ChangeLog 18 Aug 2004 14:05:52 -0000
@@ -1,5 +1,15 @@
+2004-08-18 Fredrik Hederstierna <fredrik@wespot.com>
+2004-08-18 Jonathan Larmour <jifl@eCosCentric.com>
+
+ * src/strtoll.cxx, src/strtoull.cxx: New files. Support for long long
+ string conversion.
+ * cdl/stdlib.cdl (CYGFUN_LIBC_STDLIB_CONV_LONGLONG): New option
+ to build above new files configurably.
+ * include/atox.inl: Prototype new functions from above. Add atoll()
+ inline.
+
2004-02-17 Jonathan Larmour <jifl@eCosCentric.com>
* src/rand.cxx (srand): Use correct thread data type.
(rand): Ditto.
Index: stdlib/current/cdl/stdlib.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdlib/current/cdl/stdlib.cdl,v
retrieving revision 1.5
diff -u -5 -p -r1.5 stdlib.cdl
--- stdlib/current/cdl/stdlib.cdl 24 Feb 2003 14:28:02 -0000 1.5
+++ stdlib/current/cdl/stdlib.cdl 18 Aug 2004 14:05:53 -0000
@@ -210,10 +210,22 @@ cdl_package CYGPKG_LIBC_STDLIB {
strtod() (and consequently atof()) to convert
from string to double precision floating point
numbers. Disabling this option removes the
dependency on the math library package."
}
+
+ cdl_option CYGFUN_LIBC_STDLIB_CONV_LONGLONG {
+ display "Provides long long conversion functions"
+ default_value 1
+ compile strtoll.cxx strtoull.cxx
+ description "
+ Enabling this option will provide support for the strtoll(),
+ strtoull() and atoll() conversion functions, which are
+ the long long variants of the standard versions of these
+ functions. Supporting this requires extra code and compile
+ time."
+ }
cdl_option CYGNUM_LIBC_BSEARCH_TRACE_LEVEL {
display "bsearch() tracing level"
flavor data
legal_values 0 to 1
Index: stdlib/current/include/atox.inl
===================================================================
RCS file: /cvs/ecos/ecos/packages/language/c/libc/stdlib/current/include/atox.inl,v
retrieving revision 1.3
diff -u -5 -p -r1.3 atox.inl
--- stdlib/current/include/atox.inl 23 May 2002 23:07:20 -0000 1.3
+++ stdlib/current/include/atox.inl 18 Aug 2004 14:05:53 -0000
@@ -78,10 +78,13 @@ extern int
atoi( const char * /* int_str */ );
extern long
atol( const char * /* long_str */ );
+extern long long
+atoll( const char * /* long_long_str */ );
+
#ifdef CYGFUN_LIBC_strtod
extern double
strtod( const char * /* double_str */, char ** /* endptr */ );
#endif
@@ -91,10 +94,20 @@ strtol( const char * /* long_str */, cha
extern unsigned long
strtoul( const char * /* ulong_str */, char ** /* endptr */,
int /* base */ );
+#ifdef CYGFUN_LIBC_STDLIB_CONV_LONGLONG
+extern long long
+strtoll( const char * /* long_long_str */, char ** /* endptr */,
+ int /* base */ );
+
+extern unsigned long long
+strtoull( const char * /* ulong_long_str */, char ** /* endptr */,
+ int /* base */ );
+#endif
+
#ifdef __cplusplus
} /* extern "C" */
#endif
/* INLINE FUNCTIONS */
@@ -155,8 +168,26 @@ atol( const char *__nptr )
CYG_REPORT_RETVAL( __retval );
return __retval;
} /* atol() */
+#ifdef CYGFUN_LIBC_STDLIB_CONV_LONGLONG
+CYGPRI_LIBC_STDLIB_ATOX_INLINE long long
+atoll( const char *__nptr )
+{
+ long long __retval;
+
+ CYG_REPORT_FUNCNAMETYPE( "atoll", "returning %lld" );
+
+ CYG_CHECK_DATA_PTR( __nptr, "__nptr is an invalid pointer!" );
+
+ __retval = strtoll( __nptr, (char **)NULL, 10 );
+
+ CYG_REPORT_RETVAL( __retval );
+
+ return __retval;
+} /* atoll() */
+#endif
+
#endif /* CYGONCE_LIBC_STDLIB_ATOX_INL multiple inclusion protection */
/* EOF atox.inl */
Index: stdlib/current/src/strtoll.cxx
===================================================================
RCS file: stdlib/current/src/strtoll.cxx
diff -N stdlib/current/src/strtoll.cxx
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ stdlib/current/src/strtoll.cxx 18 Aug 2004 14:05:53 -0000
@@ -0,0 +1,199 @@
+//===========================================================================
+//
+// strtoll.cxx
+//
+// String to long long int conversion function
+//
+//===========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//===========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): jlarmour
+// Contributors: Fredrik Hederstierna, converted file from long to long long.
+// Date: 2000-04-30, 2004-02-19
+// Purpose:
+// Description:
+// Usage:
+//
+//####DESCRIPTIONEND####
+//
+//===========================================================================
+//
+// This code is based on original code with the following copyright:
+//
+/*-
+ * 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. 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.
+ */
+
+
+// CONFIGURATION
+
+#include <pkgconf/libc_stdlib.h> // Configuration header
+
+// INCLUDES
+
+#include <cyg/infra/cyg_type.h> // Common type definitions and support
+#include <cyg/infra/cyg_trac.h> // Tracing support
+#include <cyg/infra/cyg_ass.h> // Assertion support
+#include <limits.h> // Definition of LONG_LONG_MIN and LONG_LONG_MAX
+#include <ctype.h> // Definition of many ctype functions
+#include <errno.h> // Error code definitions
+#include <stdlib.h> // Header for all stdlib functions
+ // (like this one)
+
+
+// FUNCTIONS
+
+//
+// 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
+strtoll( const char *nptr, char **endptr, int base )
+{
+ const char *s = nptr;
+ unsigned long long acc;
+ int c;
+ unsigned long long cutoff;
+ int neg = 0, any, cutlim;
+
+ CYG_REPORT_FUNCNAMETYPE( "strtoll", "returning long long %lld" );
+ CYG_REPORT_FUNCARG3( "nptr=%08x, endptr=%08x, base=%d",
+ nptr, endptr, base );
+ CYG_CHECK_DATA_PTR( nptr, "nptr is not a valid pointer!" );
+
+ if (endptr != NULL)
+ CYG_CHECK_DATA_PTR( endptr, "endptr is not a valid pointer!" );
+
+ //
+ // 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 long 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;
+ errno = ERANGE;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != 0)
+ *endptr = (char *) (any ? s - 1 : nptr);
+
+ CYG_REPORT_RETVAL ( acc );
+
+ return acc;
+} // strtoll()
+
+// EOF strtoll.cxx
Index: stdlib/current/src/strtoull.cxx
===================================================================
RCS file: stdlib/current/src/strtoull.cxx
diff -N stdlib/current/src/strtoull.cxx
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ stdlib/current/src/strtoull.cxx 18 Aug 2004 14:05:53 -0000
@@ -0,0 +1,175 @@
+//===========================================================================
+//
+// strtoull.cxx
+//
+// String to unsigned long long int conversion function
+//
+//===========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//===========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): jlarmour
+// Contributors: Fredrik Hederstierna, converted file from long to long long.
+// Date: 2000-04-30, 2004-02-19
+// Purpose:
+// Description:
+// Usage:
+//
+//####DESCRIPTIONEND####
+//
+//===========================================================================
+//
+// This code is based on original code with the following copyright:
+//
+/*
+ * 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. 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.
+ */
+
+
+// CONFIGURATION
+
+#include <pkgconf/libc_stdlib.h> // Configuration header
+
+// INCLUDES
+
+#include <cyg/infra/cyg_type.h> // Common type definitions and support
+#include <cyg/infra/cyg_trac.h> // Tracing support
+#include <cyg/infra/cyg_ass.h> // Assertion support
+#include <limits.h> // Definition of ULONG_LONG_MAX
+#include <ctype.h> // Definition of many ctype functions
+#include <errno.h> // Error code definitions
+#include <stdlib.h> // Header for all stdlib functions
+ // (like this one)
+
+
+// FUNCTIONS
+
+//
+// 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
+strtoull( const char *nptr, char **endptr, int base )
+{
+ const char *s = nptr;
+ unsigned long long acc;
+ int c;
+ unsigned long long cutoff;
+ int neg = 0, any, cutlim;
+
+ CYG_REPORT_FUNCNAMETYPE( "strtoull", "returning long long %lld" );
+ CYG_REPORT_FUNCARG3( "nptr=%08x, endptr=%08x, base=%d",
+ nptr, endptr, base );
+ CYG_CHECK_DATA_PTR( nptr, "nptr is not a valid pointer!" );
+
+ if (endptr != NULL)
+ CYG_CHECK_DATA_PTR( endptr, "endptr is not a valid pointer!" );
+ //
+ // See strtoll 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;
+ errno = ERANGE;
+ } else if (neg)
+ acc = -acc;
+ if (endptr != 0)
+ *endptr = (char *) (any ? s - 1 : nptr);
+
+ CYG_REPORT_RETVAL( acc );
+
+ return acc;
+} // strtoull()
+
+// EOF strtoull.cxx