mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 15:15:44 +00:00
Backport from CVS-HEAD.
This commit is contained in:
@@ -1,3 +1,39 @@
|
||||
2011-02-01 Ralf Corsepius <ralf.corsepius@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@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@lbl.gov>
|
||||
|
||||
* libmisc/capture/capture.c: Avoid using TCB of task just deleted.
|
||||
|
||||
@@ -135,10 +135,11 @@ EXTRA_DIST += untar/README
|
||||
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
|
||||
|
||||
@@ -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 @@ rtems_status_code rtems_string_to_double(
|
||||
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
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* COPYRIGHT (c) 2009.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <rtems/stringto.h>
|
||||
|
||||
/*
|
||||
* If we are doing floating point conversion, then we need math.h
|
||||
*/
|
||||
#if defined(STRING_TO_FLOAT)
|
||||
#include <math.h>
|
||||
#endif
|
||||
|
||||
#include <rtems.h>
|
||||
|
||||
/*
|
||||
* This file is designed to be included multiple times to instantiate
|
||||
* it and should NOT be protected against multiple inclusions.
|
||||
*/
|
||||
|
||||
#if defined(STRING_TO_POINTER)
|
||||
#define STRING_TO_INTEGER
|
||||
#endif
|
||||
|
||||
#if !defined(STRING_TO_FLOAT) && !defined(STRING_TO_INTEGER)
|
||||
#error "Neither STRING_TO_FLOAT nor STRING_TO_INTEGER defined"
|
||||
#endif
|
||||
|
||||
#if defined(STRING_TO_FLOAT) && defined(STRING_TO_INTEGER)
|
||||
#error "Both STRING_TO_FLOAT nor STRING_TO_INTEGER defined"
|
||||
#endif
|
||||
|
||||
#ifndef STRING_TO_TYPE
|
||||
#error "STRING_TO_TYPE not defined"
|
||||
#endif
|
||||
|
||||
#ifndef STRING_TO_NAME
|
||||
#error "STRING_TO_NAME not defined"
|
||||
#endif
|
||||
|
||||
#ifndef STRING_TO_METHOD
|
||||
#error "STRING_TO_METHOD not defined"
|
||||
#endif
|
||||
|
||||
#ifndef STRING_TO_MAX
|
||||
#error "STRING_TO_MAX not defined"
|
||||
#endif
|
||||
|
||||
#undef ZERO
|
||||
#ifdef STRING_TO_FLOAT
|
||||
#define ZERO 0.0
|
||||
#elif defined(STRING_TO_INTEGER)
|
||||
#define ZERO 0
|
||||
#endif
|
||||
|
||||
#if !defined(STRING_TO_INPUT_TYPE)
|
||||
#define STRING_TO_INPUT_TYPE STRING_TO_TYPE
|
||||
#endif
|
||||
|
||||
rtems_status_code STRING_TO_NAME (
|
||||
const char *s,
|
||||
STRING_TO_TYPE *n,
|
||||
char **endptr
|
||||
#if defined(STRING_TO_INTEGER) && !defined(STRING_TO_POINTER)
|
||||
,
|
||||
int base
|
||||
#endif
|
||||
)
|
||||
{
|
||||
STRING_TO_INPUT_TYPE result;
|
||||
char *end;
|
||||
|
||||
if ( !n )
|
||||
return RTEMS_INVALID_ADDRESS;
|
||||
|
||||
errno = 0;
|
||||
*n = 0;
|
||||
|
||||
#ifdef STRING_TO_FLOAT
|
||||
result = STRING_TO_METHOD( s, &end );
|
||||
#elif defined(STRING_TO_POINTER)
|
||||
result = STRING_TO_METHOD( s, &end, 16 );
|
||||
#elif defined(STRING_TO_INTEGER)
|
||||
result = STRING_TO_METHOD( s, &end, base );
|
||||
#endif
|
||||
|
||||
/* If the user wants the end pointer back, then return it. */
|
||||
if ( endptr )
|
||||
*endptr = end;
|
||||
|
||||
/* nothing was converted */
|
||||
if ( end == s )
|
||||
return RTEMS_NOT_DEFINED;
|
||||
|
||||
/*
|
||||
* In theory, we should check this but newlib never returns anything
|
||||
* but range errors. So this is unreachable code based upon the newlib
|
||||
* implementation of strXXX methods as of 1 December 2009. --joel
|
||||
*/
|
||||
#if 0
|
||||
/* there was a conversion error */
|
||||
if ( (result == ZERO) && errno )
|
||||
return RTEMS_INVALID_NUMBER;
|
||||
#endif
|
||||
|
||||
#ifdef STRING_TO_MAX
|
||||
/* there was an overflow */
|
||||
if ( (result == STRING_TO_MAX) && (errno == ERANGE))
|
||||
return RTEMS_INVALID_NUMBER;
|
||||
#endif
|
||||
|
||||
#ifdef STRING_TO_MIN
|
||||
/* there was an underflow */
|
||||
if ( (result == STRING_TO_MIN) && (errno == ERANGE))
|
||||
return RTEMS_INVALID_NUMBER;
|
||||
#endif
|
||||
|
||||
#if defined(STRING_TO_POINTER)
|
||||
*n = (STRING_TO_TYPE) (uintptr_t)result;
|
||||
#else
|
||||
*n = (STRING_TO_TYPE) result;
|
||||
#endif
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user