change log for rtems (2011-02-01)

rtems-vc at rtems.org rtems-vc at rtems.org
Wed Feb 2 03:10:22 UTC 2011


 *ralf* (on branch rtems-4-10-branch):
Backport from CVS-HEAD.

M 1.2346.2.76  cpukit/ChangeLog
M 1.85.2.1  cpukit/libmisc/Makefile.am
M 1.3.2.1  cpukit/libmisc/stringto/stringto.h
R    1.7  cpukit/libmisc/stringto/stringto_template.h
M 1.2.2.1  cpukit/libmisc/stringto/stringtodouble.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtofloat.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtoint.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtolong.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtolonglong.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtopointer.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtounsignedchar.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtounsignedint.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtounsignedlong.c
M 1.2.2.1  cpukit/libmisc/stringto/stringtounsignedlonglong.c

diff -u rtems/cpukit/ChangeLog:1.2346.2.75 rtems/cpukit/ChangeLog:1.2346.2.76
--- rtems/cpukit/ChangeLog:1.2346.2.75	Fri Jan 21 13:40:27 2011
+++ rtems/cpukit/ChangeLog	Tue Feb  1 20:30:08 2011
@@ -1,3 +1,39 @@
+2011-02-01	Ralf Corsepius <ralf.corsepius at rtems.org>
+
+	* libmisc/stringto/stringtounsignedchar.c, 
+	libmisc/stringto/stringtounsignedint.c: Reformat range check.
+	* libmisc/Makefile.am: Add stringto/stringtolongdouble.c.
+	* libmisc/stringto/stringtolongdouble.c: New.
+	* libmisc/stringto/stringto.h: Rename header-guard.
+	Add rtems_string_to_long_double.
+	* libmisc/stringto/stringtoint.c: Reformat range check.
+	Add check for result==0.
+	* libmisc/stringto/stringtofloat.c: Reformat range check.
+	Add check for result = -HUGE_VALF.
+	* libmisc/stringto/stringtodouble.c: Reformat range check.
+	Add check for result = -HUGE_VAL.
+	* libmisc/stringto/stringtolonglong.c: Reformat range check.
+	c99 portability improvements. Add check for result==0.
+	* libmisc/stringto/stringtounsignedlonglong.c: Reformat range check.
+	c99 portability improvements.
+	* libmisc/stringto/stringtounsignedlong.c: Reformat range check.
+	* libmisc/stringto/stringtolong.c:  Reformat range check.
+	Add check for result==0.
+
+2011-02-01	Ralf Corsepius <ralf.corsepius at rtems.org>
+	
+	* libmisc/Makefile.am: Remove stringto/stringto_template.h.
+	* libmisc/stringto/stringto_template.h: Remove.
+
+	* libmisc/stringto/stringtodouble.c,
+	libmisc/stringto/stringtofloat.c: Rework.
+
+	* libmisc/stringto/stringtolong.c,
+	libmisc/stringto/stringtolonglong.c,
+	libmisc/stringto/stringtounsignedlong.c,
+	libmisc/stringto/stringtounsignedlonglong.c:
+	Rework.
+
 2011-01-21	Eric Norum <wenorum at lbl.gov>
 
 	* libmisc/capture/capture.c: Avoid using TCB of task just deleted.

diff -u rtems/cpukit/libmisc/Makefile.am:1.85 rtems/cpukit/libmisc/Makefile.am:1.85.2.1
--- rtems/cpukit/libmisc/Makefile.am:1.85	Mon May 31 08:56:37 2010
+++ rtems/cpukit/libmisc/Makefile.am	Tue Feb  1 20:30:09 2011
@@ -135,10 +135,11 @@
 noinst_LIBRARIES += libstringto.a
 libstringto_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/stringto
 libstringto_a_SOURCES = stringto/stringtodouble.c stringto/stringtofloat.c \
+    stringto/stringtolongdouble.c \
     stringto/stringtoint.c stringto/stringtolong.c stringto/stringtolonglong.c \
     stringto/stringtopointer.c stringto/stringtounsignedint.c \
     stringto/stringtounsignedchar.c stringto/stringtounsignedlong.c \
-    stringto/stringtounsignedlonglong.c stringto/stringto_template.h
+    stringto/stringtounsignedlonglong.c
 
 ## fsmount
 noinst_LIBRARIES += libfsmount.a

diff -u rtems/cpukit/libmisc/stringto/stringto.h:1.3 rtems/cpukit/libmisc/stringto/stringto.h:1.3.2.1
--- rtems/cpukit/libmisc/stringto/stringto.h:1.3	Tue Dec  1 16:16:10 2009
+++ rtems/cpukit/libmisc/stringto/stringto.h	Tue Feb  1 20:30:09 2011
@@ -9,8 +9,8 @@
  *  $Id$
  */
 
-#ifndef __STRING_TO_A_TYPE_h__
-#define __STRING_TO_A_TYPE_h__
+#ifndef _RTEMS_STRINGTO_H
+#define _RTEMS_STRINGTO_H
 
 #include <rtems.h>
 
@@ -224,4 +224,23 @@
   char        **endptr
 );
 
+/**
+ *  @brief Convert String to long double (with validation)
+ *
+ *  This method converts a string to a long double with range validation.
+ *
+ *  @param[in] s is the string to convert
+ *  @param[in] n points to the variable to place the converted output in
+ *  @param[in] endptr is used to keep track of the position in the string
+ *
+ *  @return This method returns RTEMS_SUCCESSFUL on successful conversion
+ *          and *n is filled in.  Otherwise, the status indicates the
+ *          source of the error.
+ */
+rtems_status_code rtems_string_to_long_double(
+  const char   *s,
+  long double  *n,
+  char        **endptr
+);
+
 #endif

diff -u rtems/cpukit/libmisc/stringto/stringtodouble.c:1.2 rtems/cpukit/libmisc/stringto/stringtodouble.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtodouble.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtodouble.c	Tue Feb  1 20:30:09 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,13 +15,44 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <rtems/stringto.h>
+
 /*
  *  Instantiate an error checking wrapper for strtod (double)
  */
-#define STRING_TO_FLOAT
-#define STRING_TO_TYPE double
-#define STRING_TO_NAME rtems_string_to_double
-#define STRING_TO_METHOD strtod
-#define STRING_TO_MAX HUGE_VAL
-#include "stringto_template.h"
 
+rtems_status_code rtems_string_to_double (
+  const char *s,
+  double *n,
+  char **endptr
+)
+{
+  double result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtod( s, &end );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == HUGE_VAL ) || ( result == -HUGE_VAL )))
+      return RTEMS_INVALID_NUMBER;
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtofloat.c:1.2 rtems/cpukit/libmisc/stringto/stringtofloat.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtofloat.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtofloat.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,12 +15,44 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <math.h>
+
+#include <rtems/stringto.h>
+
 /*
  *  Instantiate an error checking wrapper for strtof (float)
  */
-#define STRING_TO_FLOAT
-#define STRING_TO_TYPE float
-#define STRING_TO_NAME rtems_string_to_float
-#define STRING_TO_METHOD strtof
-#define STRING_TO_MAX HUGE_VALF
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_float (
+  const char *s,
+  float *n,
+  char **endptr
+)
+{
+  float result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtof( s, &end );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == HUGE_VALF ) || ( result == -HUGE_VALF )))
+      return RTEMS_INVALID_NUMBER;
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtoint.c:1.2 rtems/cpukit/libmisc/stringto/stringtoint.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtoint.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtoint.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,12 +15,59 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
 /*
  *  Instantiate an error checking wrapper for strtol (int)
  */
-#define STRING_TO_INTEGER
-#define STRING_TO_TYPE int
-#define STRING_TO_NAME rtems_string_to_int
-#define STRING_TO_METHOD strtol
-#define STRING_TO_MAX LONG_MAX
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_int (
+  const char *s,
+  int *n,
+  char **endptr,
+  int base
+)
+{
+  long result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtol( s, &end, base );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
+      return RTEMS_INVALID_NUMBER;
+
+#if (INT_MAX < LONG_MAX)
+  if ( result > INT_MAX ) {
+    errno = ERANGE;
+    return RTEMS_INVALID_NUMBER;
+  }
+#endif
+
+#if (INT_MIN < LONG_MIN)
+  if ( result < INT_MIN ) {
+    errno = ERANGE;
+    return RTEMS_INVALID_NUMBER;
+  }
+#endif
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtolong.c:1.2 rtems/cpukit/libmisc/stringto/stringtolong.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtolong.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtolong.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,13 +15,45 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
 /*
  *  Instantiate an error checking wrapper for strtol (long)
  */
-#define STRING_TO_INTEGER
-#define STRING_TO_TYPE long int
-#define STRING_TO_NAME rtems_string_to_long
-#define STRING_TO_METHOD strtol
-#define STRING_TO_MIN LONG_MIN
-#define STRING_TO_MAX LONG_MAX
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_long (
+  const char *s,
+  long *n,
+  char **endptr,
+  int base
+)
+{
+  long result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtol( s, &end, base );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
+      return RTEMS_INVALID_NUMBER;
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtolonglong.c:1.2 rtems/cpukit/libmisc/stringto/stringtolonglong.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtolonglong.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtolonglong.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,13 +15,54 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/* c99 has LLONG_MAX instead of LONG_LONG_MAX */
+#ifndef LONG_LONG_MAX
+#define LONG_LONG_MAX	LLONG_MAX
+#endif
+/* c99 has LLONG_MIN instead of LONG_LONG_MIN */
+#ifndef LONG_LONG_MIN
+#define LONG_LONG_MIN	LLONG_MIN
+#endif
+
 /*
  *  Instantiate an error checking wrapper for strtoll (long long)
  */
-#define STRING_TO_INTEGER
-#define STRING_TO_TYPE long long
-#define STRING_TO_NAME rtems_string_to_long_long
-#define STRING_TO_METHOD strtoll
-#define STRING_TO_MIN LONG_LONG_MIN
-#define STRING_TO_MAX LONG_LONG_MAX
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_long_long (
+  const char *s,
+  long long *n,
+  char **endptr,
+  int base
+)
+{
+  long long result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtoll( s, &end, base );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == LONG_LONG_MAX ) || ( result == LONG_LONG_MIN )))
+      return RTEMS_INVALID_NUMBER;
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtopointer.c:1.2 rtems/cpukit/libmisc/stringto/stringtopointer.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtopointer.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtopointer.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,17 +15,33 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <stdint.h>
+
+#include <rtems/stringto.h>
+
 /*
- *  Instantiate an error checking wrapper for strtoul which is
- *  used to input a (void *)
- *
- *  NOTE: This is only an appropriate implementation when unsigned long
- *        can represent a void *
+ *  Instantiate an error checking wrapper for strtoul/strtoull (void *)
  */
-#define STRING_TO_POINTER
-#define STRING_TO_TYPE void *
-#define STRING_TO_INPUT_TYPE unsigned long
-#define STRING_TO_NAME rtems_string_to_pointer
-#define STRING_TO_METHOD strtoul
-#define STRING_TO_MAX ULONG_MAX
-#include "stringto_template.h"
+
+#if (UINTPTR_MAX == ULONG_MAX)
+#define STRTOFUNC(a,b,c)	rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
+#elif (UINTPTR_MAX == ULONG_LONG_MAX)
+#define STRTOFUNC(a,b,c)	rtems_string_to_unsigned_long_long(a, (unsigned long long*) b, c, 0)
+#elif (UINTPTR_MAX == UINT_MAX)
+#define STRTOFUNC(a,b,c)	rtems_string_to_unsigned_int(a, (unsigned int*) b, c, 0)
+#else
+/* Fallback to unsigned long */
+#define STRTOFUNC(a,b,c)	rtems_string_to_unsigned_long(a, (unsigned long*) b, c, 0)
+#endif
+
+rtems_status_code rtems_string_to_pointer (
+  const char *s,
+  void **n,
+  char **endptr
+)
+{
+  return STRTOFUNC( s, n, endptr );
+}

diff -u rtems/cpukit/libmisc/stringto/stringtounsignedchar.c:1.2 rtems/cpukit/libmisc/stringto/stringtounsignedchar.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtounsignedchar.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtounsignedchar.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,12 +15,52 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
 /*
- *  Instantiate an error checking wrapper for strtol (unsigned char)
+ *  Instantiate an error checking wrapper for strtoul (unsigned char)
  */
-#define STRING_TO_INTEGER
-#define STRING_TO_TYPE unsigned char
-#define STRING_TO_NAME rtems_string_to_unsigned_char
-#define STRING_TO_METHOD strtoul
-#define STRING_TO_MAX ULONG_MAX
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_unsigned_char (
+  const char *s,
+  unsigned char *n,
+  char **endptr,
+  int base
+)
+{
+  unsigned long result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtoul( s, &end, base );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == ULONG_MAX )))
+      return RTEMS_INVALID_NUMBER;
+
+#if (UCHAR_MAX < ULONG_MAX)
+  if ( result > UCHAR_MAX ) {
+    errno = ERANGE;
+    return RTEMS_INVALID_NUMBER;
+  }
+#endif
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtounsignedint.c:1.2 rtems/cpukit/libmisc/stringto/stringtounsignedint.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtounsignedint.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtounsignedint.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,12 +15,52 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
 /*
  *  Instantiate an error checking wrapper for strtoul (unsigned int)
  */
-#define STRING_TO_INTEGER
-#define STRING_TO_TYPE unsigned int
-#define STRING_TO_NAME rtems_string_to_unsigned_int
-#define STRING_TO_METHOD strtoul
-#define STRING_TO_MAX ULONG_MAX
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_unsigned_int (
+  const char *s,
+  unsigned int *n,
+  char **endptr,
+  int base
+)
+{
+  unsigned long result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtoul( s, &end, base );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == ULONG_MAX )))
+      return RTEMS_INVALID_NUMBER;
+
+#if (UINT_MAX < ULONG_MAX)
+  if ( result > UINT_MAX ) {
+    errno = ERANGE;
+    return RTEMS_INVALID_NUMBER;
+  }
+#endif
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtounsignedlong.c:1.2 rtems/cpukit/libmisc/stringto/stringtounsignedlong.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtounsignedlong.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtounsignedlong.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,12 +15,45 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
 /*
  *  Instantiate an error checking wrapper for strtoul (unsigned long)
  */
-#define STRING_TO_INTEGER
-#define STRING_TO_TYPE unsigned long int
-#define STRING_TO_NAME rtems_string_to_unsigned_long
-#define STRING_TO_METHOD strtoul
-#define STRING_TO_MAX ULONG_MAX
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_unsigned_long (
+  const char *s,
+  unsigned long *n,
+  char **endptr,
+  int base
+)
+{
+  unsigned long result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtoul( s, &end, base );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == ULONG_MAX )))
+      return RTEMS_INVALID_NUMBER;
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}

diff -u rtems/cpukit/libmisc/stringto/stringtounsignedlonglong.c:1.2 rtems/cpukit/libmisc/stringto/stringtounsignedlonglong.c:1.2.2.1
--- rtems/cpukit/libmisc/stringto/stringtounsignedlonglong.c:1.2	Sun Mar 28 10:20:32 2010
+++ rtems/cpukit/libmisc/stringto/stringtounsignedlonglong.c	Tue Feb  1 20:30:10 2011
@@ -2,6 +2,8 @@
  *  COPYRIGHT (c) 2009.
  *  On-Line Applications Research Corporation (OAR).
  *
+ *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
+ *
  *  The license and distribution terms for this file may be
  *  found in the file LICENSE in this distribution or at
  *  http://www.rtems.com/license/LICENSE.
@@ -13,12 +15,50 @@
 #include "config.h"
 #endif
 
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+
+#include <rtems/stringto.h>
+
+/* c99 has ULLONG_MAX instead of ULONG_LONG_MAX */
+#ifndef ULONG_LONG_MAX
+#define ULONG_LONG_MAX	ULLONG_MAX
+#endif
+
 /*
  *  Instantiate an error checking wrapper for strtoull (unsigned long long)
  */
-#define STRING_TO_INTEGER
-#define STRING_TO_TYPE unsigned long long
-#define STRING_TO_NAME rtems_string_to_unsigned_long_long
-#define STRING_TO_METHOD strtoull
-#define STRING_TO_MAX ULONG_LONG_MAX
-#include "stringto_template.h"
+
+rtems_status_code rtems_string_to_unsigned_long_long (
+  const char *s,
+  unsigned long long *n,
+  char **endptr,
+  int base
+)
+{
+  unsigned long long result;
+  char *end;
+
+  if ( !n )
+    return RTEMS_INVALID_ADDRESS;
+
+  errno = 0;
+  *n = 0;
+
+  result = strtoull( s, &end, base );
+
+  if ( endptr )
+    *endptr = end;
+
+  if ( end == s )
+    return RTEMS_NOT_DEFINED;
+
+  if ( ( errno == ERANGE ) && 
+    (( result == 0 ) || ( result == ULONG_LONG_MAX )))
+      return RTEMS_INVALID_NUMBER;
+
+  *n = result;
+
+  return RTEMS_SUCCESSFUL;
+}



--

Generated by Deluxe Loginfo [http://www.codewiz.org/projects/index.html#loginfo] 2.122 by Bernardo Innocenti <bernie at develer.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/vc/attachments/20110201/f0529896/attachment-0001.html>


More information about the vc mailing list