source: rtems/cpukit/libmisc/stringto/stringtolonglong.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.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup libmisc_conv_help Conversion Helpers
5 *
6 * @brief Convert String to 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 LLONG_MAX instead of LONG_LONG_MAX */
31#ifndef LONG_LONG_MAX
32#define LONG_LONG_MAX   LLONG_MAX
33#endif
34/* c99 has LLONG_MIN instead of LONG_LONG_MIN */
35#ifndef LONG_LONG_MIN
36#define LONG_LONG_MIN   LLONG_MIN
37#endif
38
39/*
40 *  Instantiate an error checking wrapper for strtoll (long long)
41 */
42
43rtems_status_code rtems_string_to_long_long (
44  const char *s,
45  long long *n,
46  char **endptr,
47  int base
48)
49{
50  long long result;
51  char *end;
52
53  if ( !n )
54    return RTEMS_INVALID_ADDRESS;
55
56  errno = 0;
57  *n = 0;
58
59  result = strtoll( s, &end, base );
60
61  if ( endptr )
62    *endptr = end;
63
64  if ( end == s )
65    return RTEMS_NOT_DEFINED;
66
67  if ( ( errno == ERANGE ) &&
68    (( result == 0 ) || ( result == LONG_LONG_MAX ) || ( result == LONG_LONG_MIN )))
69      return RTEMS_INVALID_NUMBER;
70
71  *n = result;
72
73  return RTEMS_SUCCESSFUL;
74}
Note: See TracBrowser for help on using the repository browser.