mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-20 09:29:50 +08:00
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:
@@ -9,18 +9,31 @@
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <rtems/stringto.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <math.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
|
||||
@@ -52,27 +65,33 @@
|
||||
#define ZERO 0
|
||||
#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,
|
||||
STRING_TO_TYPE *n,
|
||||
char **endptr
|
||||
#if defined(STRING_TO_INTEGER)
|
||||
#if defined(STRING_TO_INTEGER) && !defined(STRING_TO_POINTER)
|
||||
,
|
||||
int base
|
||||
#endif
|
||||
)
|
||||
{
|
||||
STRING_TO_TYPE result;
|
||||
char *end;
|
||||
STRING_TO_INPUT_TYPE result;
|
||||
char *end;
|
||||
|
||||
if ( !n )
|
||||
return false;
|
||||
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
|
||||
@@ -83,25 +102,25 @@ bool STRING_TO_NAME (
|
||||
|
||||
/* nothing was converted */
|
||||
if ( end == s )
|
||||
return false;
|
||||
return RTEMS_NOT_DEFINED;
|
||||
|
||||
/* there was a conversion error */
|
||||
if ( (result == ZERO) && errno )
|
||||
return false;
|
||||
return RTEMS_INVALID_NUMBER;
|
||||
|
||||
#ifdef STRING_TO_MAX
|
||||
/* there was an overflow */
|
||||
if ( (result == STRING_TO_MAX) && (errno == ERANGE))
|
||||
return false;
|
||||
return RTEMS_INVALID_NUMBER;
|
||||
#endif
|
||||
|
||||
#ifdef STRING_TO_MIN
|
||||
/* there was an underflow */
|
||||
if ( (result == STRING_TO_MIN) && (errno == ERANGE))
|
||||
return false;
|
||||
return RTEMS_INVALID_NUMBER;
|
||||
#endif
|
||||
|
||||
*n = (STRING_TO_TYPE) result;
|
||||
return true;
|
||||
return RTEMS_SUCCESSFUL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user