2009-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>

* libmisc/Makefile.am, libmisc/shell/main_chmod.c,
	libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
	libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c,
	libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
	libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c,
	libmisc/shell/shell_script.c, libmisc/stringto/stringto.h,
	libmisc/stringto/stringto_template.h: Convert return type from bool
	to rtems_status_code and add rtems_string_to_pointer. Perform
	associated clean up and changes for return type change.
	* libmisc/stringto/stringtopointer.c: New file.
This commit is contained in:
Joel Sherrill
2009-07-23 14:32:34 +00:00
parent 73dfaf83a1
commit 48751ab095
15 changed files with 164 additions and 86 deletions

View File

@@ -1,3 +1,16 @@
2009-07-23 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/Makefile.am, libmisc/shell/main_chmod.c,
libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c,
libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c,
libmisc/shell/shell_script.c, libmisc/stringto/stringto.h,
libmisc/stringto/stringto_template.h: Convert return type from bool
to rtems_status_code and add rtems_string_to_pointer. Perform
associated clean up and changes for return type change.
* libmisc/stringto/stringtopointer.c: New file.
2009-07-22 Joel Sherrill <joel.sherrill@OARcorp.com> 2009-07-22 Joel Sherrill <joel.sherrill@OARcorp.com>
* posix/src/killinfo.c: Clean up. Avoid NULL pointer case. * posix/src/killinfo.c: Clean up. Avoid NULL pointer case.

View File

@@ -131,6 +131,7 @@ noinst_LIBRARIES += libstringto.a
libstringto_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/stringto libstringto_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir)/stringto
libstringto_a_SOURCES = stringto/stringtodouble.c stringto/stringtofloat.c \ libstringto_a_SOURCES = stringto/stringtodouble.c stringto/stringtofloat.c \
stringto/stringtoint.c stringto/stringtolong.c stringto/stringtolonglong.c \ stringto/stringtoint.c stringto/stringtolong.c stringto/stringtolonglong.c \
stringto/stringtopointer.c stringto/stringtounsignedint.c \
stringto/stringtounsignedchar.c stringto/stringtounsignedint.c \ stringto/stringtounsignedchar.c stringto/stringtounsignedint.c \
stringto/stringtounsignedlong.c stringto/stringtounsignedlonglong.c stringto/stringtounsignedlong.c stringto/stringtounsignedlonglong.c

View File

@@ -45,7 +45,7 @@ int rtems_shell_main_chmod(
/* /*
* Convert arguments into numbers * Convert arguments into numbers
*/ */
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
printf( "Mode argument (%s) is not a number\n", argv[1] ); printf( "Mode argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }

View File

@@ -31,34 +31,30 @@ int rtems_shell_main_mdump(
char *argv[] char *argv[]
) )
{ {
unsigned long tmp;
unsigned char n; unsigned char n;
unsigned char m; unsigned char m;
int max; int max;
int res; int res;
uintptr_t addr = 0; void *addr = NULL;
unsigned char *pb; unsigned char *pb;
if (argc > 1) { if (argc > 1) {
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
printf( "Address argument (%s) is not a number\n", argv[1] ); printf( "Address argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
addr = (uintptr_t) tmp;
} }
if (argc > 2) { if (argc > 2) {
if ( !rtems_string_to_int(argv[1], &max, NULL, 0) ) { if ( rtems_string_to_int(argv[1], &max, NULL, 0) ) {
printf( "Length argument (%s) is not a number\n", argv[1] ); printf( "Length argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
addr = (uintptr_t) tmp;
if (max <= 0) { if (max <= 0) {
max = 1; /* print 1 item if 0 or neg. */ max = 1; /* print 1 item if 0 or neg. */
res = 0; res = 0;
} } else {
else {
max--; max--;
res = max & 0xf;/* num bytes in last row */ res = max & 0xf;/* num bytes in last row */
max >>= 4; /* div by 16 */ max >>= 4; /* div by 16 */
@@ -68,14 +64,13 @@ int rtems_shell_main_mdump(
res = 0xf; /* 16 bytes print in last row */ res = 0xf; /* 16 bytes print in last row */
} }
} }
} } else {
else {
max = 20; max = 20;
res = 0xf; res = 0xf;
} }
pb = addr;
for (m=0; m<max; m++) { for (m=0; m<max; m++) {
pb = (unsigned char*) addr;
printf("%10p ", pb); printf("%10p ", pb);
for (n=0;n<=(m==(max-1)?res:0xf);n++) for (n=0;n<=(m==(max-1)?res:0xf);n++)
printf("%02X%c",pb[n],n==7?'-':' '); printf("%02X%c",pb[n],n==7?'-':' ');
@@ -85,7 +80,7 @@ int rtems_shell_main_mdump(
printf("%c", isprint(pb[n]) ? pb[n] : '.'); printf("%c", isprint(pb[n]) ? pb[n] : '.');
} }
printf("\n"); printf("\n");
addr += 16; pb += 16;
} }
return 0; return 0;
} }

View File

@@ -32,8 +32,8 @@ int rtems_shell_main_medit(
char *argv[] char *argv[]
) )
{ {
unsigned long tmp;
unsigned char *pb; unsigned char *pb;
void *tmpp;
int n; int n;
int i; int i;
@@ -45,11 +45,11 @@ int rtems_shell_main_medit(
/* /*
* Convert arguments into numbers * Convert arguments into numbers
*/ */
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_pointer(argv[1], &tmpp, NULL) ) {
printf( "Address argument (%s) is not a number\n", argv[1] ); printf( "Address argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
pb = (unsigned char *) tmp; pb = tmpp;
/* /*
* Now edit the memory * Now edit the memory
@@ -58,7 +58,7 @@ int rtems_shell_main_medit(
for (i=2 ; i<=argc ; i++) { for (i=2 ; i<=argc ; i++) {
unsigned char tmpc; unsigned char tmpc;
if ( !rtems_string_to_unsigned_char(argv[i], &tmpc, NULL, 0) ) { if ( rtems_string_to_unsigned_char(argv[i], &tmpc, NULL, 0) ) {
printf( "Value (%s) is not a number\n", argv[i] ); printf( "Value (%s) is not a number\n", argv[i] );
continue; continue;
} }

View File

@@ -31,7 +31,7 @@ int rtems_shell_main_mfill(
) )
{ {
unsigned long tmp; unsigned long tmp;
uintptr_t addr; void *addr;
size_t size; size_t size;
unsigned char value; unsigned char value;
@@ -43,19 +43,18 @@ int rtems_shell_main_mfill(
/* /*
* Convert arguments into numbers * Convert arguments into numbers
*/ */
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
printf( "Address argument (%s) is not a number\n", argv[1] ); printf( "Address argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
addr = (uintptr_t) tmp;
if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
printf( "Size argument (%s) is not a number\n", argv[2] ); printf( "Size argument (%s) is not a number\n", argv[2] );
return -1; return -1;
} }
size = (size_t) tmp; size = (size_t) tmp;
if ( !rtems_string_to_unsigned_char(argv[3], &value, NULL, 0) ) { if ( rtems_string_to_unsigned_char(argv[3], &value, NULL, 0) ) {
printf( "Value argument (%s) is not a number\n", argv[3] ); printf( "Value argument (%s) is not a number\n", argv[3] );
return -1; return -1;
} }
@@ -63,7 +62,7 @@ int rtems_shell_main_mfill(
/* /*
* Now fill the memory. * Now fill the memory.
*/ */
memset((unsigned char*)addr, size, value); memset(addr, size, value);
return 0; return 0;
} }

View File

@@ -33,8 +33,8 @@ int rtems_shell_main_mmove(
) )
{ {
unsigned long tmp; unsigned long tmp;
uintptr_t src; void *src;
uintptr_t dst; void *dst;
size_t length; size_t length;
if ( argc < 4 ) { if ( argc < 4 ) {
@@ -45,19 +45,17 @@ int rtems_shell_main_mmove(
/* /*
* Convert arguments into numbers * Convert arguments into numbers
*/ */
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_pointer(argv[1], &dst, NULL) ) {
printf( "Destination argument (%s) is not a number\n", argv[1] ); printf( "Destination argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
dst = (uintptr_t) tmp;
if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) { if ( rtems_string_to_pointer(argv[2], &src, NULL) ) {
printf( "Source argument (%s) is not a number\n", argv[2] ); printf( "Source argument (%s) is not a number\n", argv[2] );
return -1; return -1;
} }
src = (uintptr_t) tmp;
if ( !rtems_string_to_unsigned_long(argv[3], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[3], &tmp, NULL, 0) ) {
printf( "Length argument (%s) is not a number\n", argv[3] ); printf( "Length argument (%s) is not a number\n", argv[3] );
return -1; return -1;
} }
@@ -66,7 +64,7 @@ int rtems_shell_main_mmove(
/* /*
* Now copy the memory. * Now copy the memory.
*/ */
memcpy((unsigned char*)dst, (unsigned char*)src, length); memcpy(dst, src, length);
return 0; return 0;
} }

View File

@@ -64,7 +64,7 @@ int rtems_shell_main_msdos_format(
return 1; return 1;
} }
if ( !rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
printf( printf(
"sector per cluster argument (%s) is not a number\n", "sector per cluster argument (%s) is not a number\n",
argv[arg] argv[arg]
@@ -82,7 +82,7 @@ int rtems_shell_main_msdos_format(
return 1; return 1;
} }
if ( !rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
printf( printf(
"root directory size argument (%s) is not a number\n", "root directory size argument (%s) is not a number\n",
argv[arg] argv[arg]

View File

@@ -31,24 +31,22 @@ int rtems_shell_main_mwdump(
char *argv[] char *argv[]
) )
{ {
unsigned long tmp;
unsigned char n; unsigned char n;
unsigned char m; unsigned char m;
int max; int max;
int res; int res;
uintptr_t addr = 0; void *addr = 0;
unsigned char *pb; unsigned char *pb;
if ( argc > 1 ) { if ( argc > 1 ) {
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_pointer(argv[1], &addr, NULL) ) {
printf( "Address argument (%s) is not a number\n", argv[1] ); printf( "Address argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
addr = (uintptr_t) tmp;
} }
if ( argc > 2 ) { if ( argc > 2 ) {
if ( !rtems_string_to_int(argv[2], &max, NULL, 0) ) { if ( rtems_string_to_int(argv[2], &max, NULL, 0) ) {
printf( "Address argument (%s) is not a number\n", argv[1] ); printf( "Address argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
@@ -71,8 +69,8 @@ int rtems_shell_main_mwdump(
res = 0xf; res = 0xf;
} }
pb = addr;
for (m=0;m<max;m++) { for (m=0;m<max;m++) {
pb = (unsigned char *) addr;
printf("%10p ", pb); printf("%10p ", pb);
for (n=0;n<=(m==(max-1)?res:0xf);n+=2) for (n=0;n<=(m==(max-1)?res:0xf);n+=2)
printf("%04X%c",*((unsigned short*)(pb+n)),n==6?'-':' '); printf("%04X%c",*((unsigned short*)(pb+n)),n==6?'-':' ');
@@ -82,7 +80,7 @@ int rtems_shell_main_mwdump(
printf("%c", isprint(pb[n]) ? pb[n] : '.'); printf("%c", isprint(pb[n]) ? pb[n] : '.');
} }
printf("\n"); printf("\n");
addr += 16; pb += 16;
} }
return 0; return 0;
} }

View File

@@ -39,7 +39,7 @@ int rtems_shell_main_sleep(
/* /*
* Convert the seconds argument to a number * Convert the seconds argument to a number
*/ */
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
printf( "Seconds argument (%s) is not a number\n", argv[1] ); printf( "Seconds argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }
@@ -50,7 +50,7 @@ int rtems_shell_main_sleep(
*/ */
delay.tv_nsec = 0; delay.tv_nsec = 0;
if (argc == 3) { if (argc == 3) {
if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
printf( "Seconds argument (%s) is not a number\n", argv[1] ); printf( "Seconds argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }

View File

@@ -37,7 +37,7 @@ int rtems_shell_main_umask(
mode_t msk = umask(0); mode_t msk = umask(0);
if (argc == 2) { if (argc == 2) {
if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
printf( "Mask argument (%s) is not a number\n", argv[1] ); printf( "Mask argument (%s) is not a number\n", argv[1] );
return -1; return -1;
} }

View File

@@ -129,7 +129,7 @@ int rtems_shell_main_joel(
case 'p': { case 'p': {
const char *s = getopt_reent.optarg; const char *s = getopt_reent.optarg;
if ( !rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
printf( "Task Priority argument (%s) is not a number\n", s ); printf( "Task Priority argument (%s) is not a number\n", s );
return -1; return -1;
} }
@@ -139,7 +139,7 @@ int rtems_shell_main_joel(
case 's': { case 's': {
const char *s = getopt_reent.optarg; const char *s = getopt_reent.optarg;
if ( !rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) { if ( rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
printf( "Stack size argument (%s) is not a number\n", s ); printf( "Stack size argument (%s) is not a number\n", s );
return -1; return -1;
} }

View File

@@ -12,6 +12,28 @@
#ifndef __STRING_TO_A_TYPE_h__ #ifndef __STRING_TO_A_TYPE_h__
#define __STRING_TO_A_TYPE_h__ #define __STRING_TO_A_TYPE_h__
#include <rtems.h>
/**
* @brief Convert String to Pointer (with validation)
*
* This method converts a string to a pointer (void *) with
* basic numeric 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_pointer(
const char *s,
void **n,
char **endptr
);
/** /**
* @brief Convert String to Unsigned Character (with validation) * @brief Convert String to Unsigned Character (with validation)
* *
@@ -23,10 +45,11 @@
* @param[in] endptr is used to keep track of the position in the string * @param[in] endptr is used to keep track of the position in the string
* @param[in] base is the expected base of the number * @param[in] base is the expected base of the number
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_unsigned_char( rtems_status_code rtems_string_to_unsigned_char(
const char *s, const char *s,
unsigned char *n, unsigned char *n,
char **endptr, char **endptr,
@@ -43,10 +66,11 @@ bool rtems_string_to_unsigned_char(
* @param[in] endptr is used to keep track of the position in the string * @param[in] endptr is used to keep track of the position in the string
* @param[in] base is the expected base of the number * @param[in] base is the expected base of the number
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_int( rtems_status_code rtems_string_to_int(
const char *s, const char *s,
int *n, int *n,
char **endptr, char **endptr,
@@ -64,10 +88,11 @@ bool rtems_string_to_int(
* @param[in] endptr is used to keep track of the position in the string * @param[in] endptr is used to keep track of the position in the string
* @param[in] base is the expected base of the number * @param[in] base is the expected base of the number
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_long( rtems_status_code rtems_string_to_long(
const char *s, const char *s,
long *n, long *n,
char **endptr, char **endptr,
@@ -85,10 +110,11 @@ bool rtems_string_to_long(
* @param[in] endptr is used to keep track of the position in the string * @param[in] endptr is used to keep track of the position in the string
* @param[in] base is the expected base of the number * @param[in] base is the expected base of the number
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_unsigned_long( rtems_status_code rtems_string_to_unsigned_long(
const char *s, const char *s,
unsigned long *n, unsigned long *n,
char **endptr, char **endptr,
@@ -106,10 +132,11 @@ bool rtems_string_to_unsigned_long(
* @param[in] endptr is used to keep track of the position in the string * @param[in] endptr is used to keep track of the position in the string
* @param[in] base is the expected base of the number * @param[in] base is the expected base of the number
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_long_long( rtems_status_code rtems_string_to_long_long(
const char *s, const char *s,
long long *n, long long *n,
char **endptr, char **endptr,
@@ -127,10 +154,11 @@ bool rtems_string_to_long_long(
* @param[in] endptr is used to keep track of the position in the string * @param[in] endptr is used to keep track of the position in the string
* @param[in] base is the expected base of the number * @param[in] base is the expected base of the number
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_unsigned_long_long( rtems_status_code rtems_string_to_unsigned_long_long(
const char *s, const char *s,
unsigned long long *n, unsigned long long *n,
char **endptr, char **endptr,
@@ -146,10 +174,11 @@ bool rtems_string_to_unsigned_long_long(
* @param[in] n points to the variable to place the converted output in * @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 * @param[in] endptr is used to keep track of the position in the string
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_float( rtems_status_code rtems_string_to_float(
const char *s, const char *s,
float *n, float *n,
char **endptr char **endptr
@@ -164,10 +193,11 @@ bool rtems_string_to_float(
* @param[in] n points to the variable to place the converted output in * @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 * @param[in] endptr is used to keep track of the position in the string
* *
* @return This method returns true on successful conversion and *n is * @return This method returns RTEMS_SUCCESSFUL on successful conversion
* filled in. * and *n is filled in. Otherwise, the status indicates the
* source of the error.
*/ */
bool rtems_string_to_double( rtems_status_code rtems_string_to_double(
const char *s, const char *s,
double *n, double *n,
char **endptr char **endptr

View File

@@ -9,18 +9,31 @@
* $Id$ * $Id$
*/ */
#include <rtems/stringto.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h> #include <stdbool.h>
/*
* If we are doing floating point conversion, then we need math.h
*/
#if defined(STRING_TO_FLOAT)
#include <math.h> #include <math.h>
#endif
#include <rtems.h>
/* /*
* This file is designed to be included multiple times to instantiate * This file is designed to be included multiple times to instantiate
* it and should NOT be protected against multiple inclusions. * 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) #if !defined(STRING_TO_FLOAT) && !defined(STRING_TO_INTEGER)
#error "Neither STRING_TO_FLOAT nor STRING_TO_INTEGER defined" #error "Neither STRING_TO_FLOAT nor STRING_TO_INTEGER defined"
#endif #endif
@@ -52,27 +65,33 @@
#define ZERO 0 #define ZERO 0
#endif #endif
bool STRING_TO_NAME ( #if !defined(STRING_TO_INPUT_TYPE)
#define STRING_TO_INPUT_TYPE STRING_TO_TYPE
#endif
rtems_status_code STRING_TO_NAME (
const char *s, const char *s,
STRING_TO_TYPE *n, STRING_TO_TYPE *n,
char **endptr char **endptr
#if defined(STRING_TO_INTEGER) #if defined(STRING_TO_INTEGER) && !defined(STRING_TO_POINTER)
, ,
int base int base
#endif #endif
) )
{ {
STRING_TO_TYPE result; STRING_TO_INPUT_TYPE result;
char *end; char *end;
if ( !n ) if ( !n )
return false; return RTEMS_INVALID_ADDRESS;
errno = 0; errno = 0;
*n = 0; *n = 0;
#ifdef STRING_TO_FLOAT #ifdef STRING_TO_FLOAT
result = STRING_TO_METHOD( s, &end ); result = STRING_TO_METHOD( s, &end );
#elif defined(STRING_TO_POINTER)
result = STRING_TO_METHOD( s, &end, 16 );
#elif defined(STRING_TO_INTEGER) #elif defined(STRING_TO_INTEGER)
result = STRING_TO_METHOD( s, &end, base ); result = STRING_TO_METHOD( s, &end, base );
#endif #endif
@@ -83,25 +102,25 @@ bool STRING_TO_NAME (
/* nothing was converted */ /* nothing was converted */
if ( end == s ) if ( end == s )
return false; return RTEMS_NOT_DEFINED;
/* there was a conversion error */ /* there was a conversion error */
if ( (result == ZERO) && errno ) if ( (result == ZERO) && errno )
return false; return RTEMS_INVALID_NUMBER;
#ifdef STRING_TO_MAX #ifdef STRING_TO_MAX
/* there was an overflow */ /* there was an overflow */
if ( (result == STRING_TO_MAX) && (errno == ERANGE)) if ( (result == STRING_TO_MAX) && (errno == ERANGE))
return false; return RTEMS_INVALID_NUMBER;
#endif #endif
#ifdef STRING_TO_MIN #ifdef STRING_TO_MIN
/* there was an underflow */ /* there was an underflow */
if ( (result == STRING_TO_MIN) && (errno == ERANGE)) if ( (result == STRING_TO_MIN) && (errno == ERANGE))
return false; return RTEMS_INVALID_NUMBER;
#endif #endif
*n = (STRING_TO_TYPE) result; *n = (STRING_TO_TYPE) result;
return true; return RTEMS_SUCCESSFUL;
} }

View File

@@ -0,0 +1,25 @@
/*
* 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$
*/
/*
* 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 *
*/
#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"