Changeset 2f8f4950 in rtems


Ignore:
Timestamp:
Feb 1, 2011, 2:32:46 AM (8 years ago)
Author:
Ralf Corsepius <ralf.corsepius@…>
Branches:
4.11, master
Children:
8b9a33e8
Parents:
0566429
Message:

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

  • libmisc/stringto/stringtolong.c, libmisc/stringto/stringtolonglong.c, libmisc/stringto/stringtounsignedlong.c, libmisc/stringto/stringtounsignedlonglong.c: Rework.
Location:
cpukit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r0566429 r2f8f4950  
     12011-02-01      Ralf Corsepius <ralf.corsepius@rtems.org>
     2
     3        * libmisc/stringto/stringtolong.c,
     4        libmisc/stringto/stringtolonglong.c,
     5        libmisc/stringto/stringtounsignedlong.c,
     6        libmisc/stringto/stringtounsignedlonglong.c:
     7        Rework.
     8
    192011-01-31      Ralf Corsepius <ralf.corsepius@rtems.org>
    210
  • cpukit/libmisc/stringto/stringtolong.c

    r0566429 r2f8f4950  
    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 (long)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE long int
    21 #define STRING_TO_NAME rtems_string_to_long
    22 #define STRING_TO_METHOD strtol
    23 #define STRING_TO_MIN LONG_MIN
    24 #define STRING_TO_MAX LONG_MAX
    25 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_long (
     29  const char *s,
     30  long *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  *n = result;
     59
     60  return RTEMS_SUCCESSFUL;
     61}
  • cpukit/libmisc/stringto/stringtolonglong.c

    r0566429 r2f8f4950  
    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 strtoll (long long)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE long long
    21 #define STRING_TO_NAME rtems_string_to_long_long
    22 #define STRING_TO_METHOD strtoll
    23 #define STRING_TO_MIN LONG_LONG_MIN
    24 #define STRING_TO_MAX LONG_LONG_MAX
    25 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_long_long (
     29  const char *s,
     30  long long *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  long long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtoll( 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_LONG_MAX) && (errno == ERANGE) )
     53    return RTEMS_INVALID_NUMBER;
     54
     55  if ( (result == LONG_LONG_MIN) && (errno == ERANGE) )
     56    return RTEMS_INVALID_NUMBER;
     57
     58  *n = result;
     59
     60  return RTEMS_SUCCESSFUL;
     61}
  • cpukit/libmisc/stringto/stringtounsignedlong.c

    r0566429 r2f8f4950  
    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 long)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned long int
    21 #define STRING_TO_NAME rtems_string_to_unsigned_long
    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_long (
     29  const char *s,
     30  unsigned long *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  *n = result;
     59
     60  return RTEMS_SUCCESSFUL;
     61}
  • cpukit/libmisc/stringto/stringtounsignedlonglong.c

    r0566429 r2f8f4950  
    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 strtoull (unsigned long long)
    1826 */
    19 #define STRING_TO_INTEGER
    20 #define STRING_TO_TYPE unsigned long long
    21 #define STRING_TO_NAME rtems_string_to_unsigned_long_long
    22 #define STRING_TO_METHOD strtoull
    23 #define STRING_TO_MAX ULONG_LONG_MAX
    24 #include "stringto_template.h"
     27
     28rtems_status_code rtems_string_to_unsigned_long_long (
     29  const char *s,
     30  unsigned long long *n,
     31  char **endptr,
     32  int base
     33)
     34{
     35  unsigned long long result;
     36  char *end;
     37
     38  if ( !n )
     39    return RTEMS_INVALID_ADDRESS;
     40
     41  errno = 0;
     42  *n = 0;
     43
     44  result = strtoull( 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_LONG_MAX) && (errno == ERANGE) )
     53    return RTEMS_INVALID_NUMBER;
     54
     55  if ( (result == 0) && (errno == ERANGE) )
     56    return RTEMS_INVALID_NUMBER;
     57
     58  *n = result;
     59
     60  return RTEMS_SUCCESSFUL;
     61}
Note: See TracChangeset for help on using the changeset viewer.