source: rtems/cpukit/libmisc/stringto/stringtolong.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.1 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup libmisc_conv_help Conversion Helpers
5 *
6 * @brief Convert String to 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/*
31 *  Instantiate an error checking wrapper for strtol (long)
32 */
33
34rtems_status_code rtems_string_to_long (
35  const char *s,
36  long *n,
37  char **endptr,
38  int base
39)
40{
41  long result;
42  char *end;
43
44  if ( !n )
45    return RTEMS_INVALID_ADDRESS;
46
47  errno = 0;
48  *n = 0;
49
50  result = strtol( s, &end, base );
51
52  if ( endptr )
53    *endptr = end;
54
55  if ( end == s )
56    return RTEMS_NOT_DEFINED;
57
58  if ( ( errno == ERANGE ) &&
59    (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
60      return RTEMS_INVALID_NUMBER;
61
62  *n = result;
63
64  return RTEMS_SUCCESSFUL;
65}
Note: See TracBrowser for help on using the repository browser.