source: rtems/cpukit/libmisc/stringto/stringtounsignedlonglong.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Convert String to Unsigned Long Long (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.org/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/* c99 has ULLONG_MAX instead of ULONG_LONG_MAX */
30#ifndef ULONG_LONG_MAX
31#define ULONG_LONG_MAX  ULLONG_MAX
32#endif
33
34/*
35 *  Instantiate an error checking wrapper for strtoull (unsigned long long)
36 */
37
38rtems_status_code rtems_string_to_unsigned_long_long (
39  const char *s,
40  unsigned long long *n,
41  char **endptr,
42  int base
43)
44{
45  unsigned long long result;
46  char *end;
47
48  if ( !n )
49    return RTEMS_INVALID_ADDRESS;
50
51  errno = 0;
52  *n = 0;
53
54  result = strtoull( s, &end, base );
55
56  if ( endptr )
57    *endptr = end;
58
59  if ( end == s )
60    return RTEMS_NOT_DEFINED;
61
62  if ( ( errno == ERANGE ) &&
63    (( result == 0 ) || ( result == ULONG_LONG_MAX )))
64      return RTEMS_INVALID_NUMBER;
65
66  *n = result;
67
68  return RTEMS_SUCCESSFUL;
69}
Note: See TracBrowser for help on using the repository browser.