source: rtems/cpukit/libmisc/stringto/stringtounsignedint.c @ 148e3de6

4.115
Last change on this file since 148e3de6 was 148e3de6, checked in by Mathew Kallada <matkallada@…>, on 12/19/12 at 14:51:38

libmisc: Doxygen Enhancement Task #2

http://www.google-melange.com/gci/task/view/google/gci2012/7959228

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Convert String to Unsigned Int (with validation)
5 * @ingroup libmisc_conv_help Conversion Helpers
6 */
7
8/*
9 *  COPYRIGHT (c) 2009.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 */
18
19#ifdef HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <errno.h>
24#include <stdlib.h>
25#include <limits.h>
26
27#include <rtems/stringto.h>
28
29/*
30 *  Instantiate an error checking wrapper for strtoul (unsigned int)
31 */
32
33rtems_status_code rtems_string_to_unsigned_int (
34  const char *s,
35  unsigned int *n,
36  char **endptr,
37  int base
38)
39{
40  unsigned long result;
41  char *end;
42
43  if ( !n )
44    return RTEMS_INVALID_ADDRESS;
45
46  errno = 0;
47  *n = 0;
48
49  result = strtoul( s, &end, base );
50
51  if ( endptr )
52    *endptr = end;
53
54  if ( end == s )
55    return RTEMS_NOT_DEFINED;
56
57  if ( ( errno == ERANGE ) &&
58    (( result == 0 ) || ( result == ULONG_MAX )))
59      return RTEMS_INVALID_NUMBER;
60
61#if (UINT_MAX < ULONG_MAX)
62  if ( result > UINT_MAX ) {
63    errno = ERANGE;
64    return RTEMS_INVALID_NUMBER;
65  }
66#endif
67
68  *n = result;
69
70  return RTEMS_SUCCESSFUL;
71}
Note: See TracBrowser for help on using the repository browser.