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

Last change on this file was cfe8f7a, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 27, 2020 at 2:14:06 PM

doxygen: Switch @brief and @ingroup

This order change fixes the Latex documentation build via Doxygen.

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