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

4.115
Last change on this file since c368bd6 was c368bd6, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/01/11 at 05:38:01

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

  • libmisc/stringto/stringtounsignedlonglong.c: Reformat range check. c99 portability improvements.
  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 2009.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  Copyright (c) 2011  Ralf Corsépius, Ulm, Germany.
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <errno.h>
19#include <stdlib.h>
20#include <limits.h>
21
22#include <rtems/stringto.h>
23
24/* c99 has ULLONG_MAX instead of ULONG_LONG_MAX */
25#ifndef ULONG_LONG_MAX
26#define ULONG_LONG_MAX  ULLONG_MAX
27#endif
28
29/*
30 *  Instantiate an error checking wrapper for strtoull (unsigned long long)
31 */
32
33rtems_status_code rtems_string_to_unsigned_long_long (
34  const char *s,
35  unsigned long long *n,
36  char **endptr,
37  int base
38)
39{
40  unsigned long long result;
41  char *end;
42
43  if ( !n )
44    return RTEMS_INVALID_ADDRESS;
45
46  errno = 0;
47  *n = 0;
48
49  result = strtoull( 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_LONG_MAX )))
59      return RTEMS_INVALID_NUMBER;
60
61  *n = result;
62
63  return RTEMS_SUCCESSFUL;
64}
Note: See TracBrowser for help on using the repository browser.