Changeset 0e867af1 in rtems


Ignore:
Timestamp:
Jan 31, 2011, 4:25:13 PM (9 years ago)
Author:
Ralf Corsepius <ralf.corsepius@…>
Branches:
4.11, master
Children:
0ef1009
Parents:
10df690
Message:

2011-01-31 Ralf Corsepius <ralf.corsepius@…>

  • libmisc/stringto/stringtoint.c, libmisc/stringto/stringtounsignedint.c, libmisc/stringto/stringtounsignedchar.c: Rework.
Location:
cpukit
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r10df690 r0e867af1  
    112011-01-31      Ralf Corsepius <ralf.corsepius@rtems.org>
     2
     3        * libmisc/stringto/stringtoint.c,
     4        libmisc/stringto/stringtounsignedint.c,
     5        libmisc/stringto/stringtounsignedchar.c: Rework.
    26
    37        * libmisc/stringto/stringtopointer.c: Rework.
  • cpukit/libmisc/stringto/stringtoint.c

    r10df690 r0e867af1  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtol (int)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE int
    21 #define STRING_TO_NAME rtems_string_to_int
    22 #define STRING_TO_METHOD strtol
    23 #define STRING_TO_MAX LONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_int (
     29  const char *s,
     30  int *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtol( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( (result == LONG_MAX) && (errno == ERANGE) )
     53    return RTEMS_INVALID_NUMBER;
     54
     55  if ( (result == LONG_MIN) && (errno == ERANGE) )
     56    return RTEMS_INVALID_NUMBER;
     57
     58#if (INT_MAX < LONG_MAX)
     59  if ( result > INT_MAX ) {
     60    errno = ERANGE;
     61    return RTEMS_INVALID_NUMBER;
     62  }
     63#endif
     64
     65#if (INT_MIN < LONG_MIN)
     66  if ( result < INT_MIN ) {
     67    errno = ERANGE;
     68    return RTEMS_INVALID_NUMBER;
     69  }
     70#endif
     71
     72  *n = result;
     73
     74  return RTEMS_SUCCESSFUL;
     75}
  • cpukit/libmisc/stringto/stringtounsignedchar.c

    r10df690 r0e867af1  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    17  *  Instantiate an error checking wrapper for strtol (unsigned char)
     25 *  Instantiate an error checking wrapper for strtoul (unsigned char)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned char
    21 #define STRING_TO_NAME rtems_string_to_unsigned_char
    22 #define STRING_TO_METHOD strtoul
    23 #define STRING_TO_MAX ULONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_unsigned_char (
     29  const char *s,
     30  unsigned char *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  unsigned long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtoul( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( (result == ULONG_MAX) && (errno == ERANGE) )
     53    return RTEMS_INVALID_NUMBER;
     54
     55  if ( (result == 0) && (errno == ERANGE) )
     56    return RTEMS_INVALID_NUMBER;
     57
     58#if (UCHAR_MAX < ULONG_MAX)
     59  if ( result > UCHAR_MAX ) {
     60    errno = ERANGE;
     61    return RTEMS_INVALID_NUMBER;
     62  }
     63#endif
     64
     65  *n = result;
     66
     67  return RTEMS_SUCCESSFUL;
     68}
  • cpukit/libmisc/stringto/stringtounsignedint.c

    r10df690 r0e867af1  
    22 *  COPYRIGHT (c) 2009.
    33 *  On-Line Applications Research Corporation (OAR).
     4 *
     5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
    46 *
    57 *  The license and distribution terms for this file may be
     
    1416#endif
    1517
     18#include <errno.h>
     19#include <stdlib.h>
     20#include <limits.h>
     21
     22#include <rtems/stringto.h>
     23
    1624/*
    1725 *  Instantiate an error checking wrapper for strtoul (unsigned int)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned int
    21 #define STRING_TO_NAME rtems_string_to_unsigned_int
    22 #define STRING_TO_METHOD strtoul
    23 #define STRING_TO_MAX ULONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_unsigned_int (
     29  const char *s,
     30  unsigned int *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  unsigned long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtoul( s, &end, base );
     45
     46  if ( endptr )
     47    *endptr = end;
     48
     49  if ( end == s )
     50    return RTEMS_NOT_DEFINED;
     51
     52  if ( (result == ULONG_MAX) && (errno == ERANGE) )
     53    return RTEMS_INVALID_NUMBER;
     54
     55  if ( (result == 0) && (errno == ERANGE) )
     56    return RTEMS_INVALID_NUMBER;
     57
     58#if (UINT_MAX < ULONG_MAX)
     59  if ( result > UINT_MAX ) {
     60    errno = ERANGE;
     61    return RTEMS_INVALID_NUMBER;
     62  }
     63#endif
     64
     65  *n = result;
     66
     67  return RTEMS_SUCCESSFUL;
     68}
Note: See TracChangeset for help on using the changeset viewer.