source: rtems/cpukit/libmisc/stringto/stringtolong.c @ 0b416759

5
Last change on this file since 0b416759 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.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Convert String to 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/*
30 *  Instantiate an error checking wrapper for strtol (long)
31 */
32
33rtems_status_code rtems_string_to_long (
34  const char *s,
35  long *n,
36  char **endptr,
37  int base
38)
39{
40  long result;
41  char *end;
42
43  if ( !n )
44    return RTEMS_INVALID_ADDRESS;
45
46  errno = 0;
47  *n = 0;
48
49  result = strtol( 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 == LONG_MAX ) || ( result == LONG_MIN )))
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.