source: rtems/cpukit/libmisc/stringto/stringtolong.c @ 97315f51

4.10
Last change on this file since 97315f51 was 97315f51, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/02/11 at 02:30:10

Backport from CVS-HEAD.

  • Property mode set to 100644
File size: 1.0 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/*
25 *  Instantiate an error checking wrapper for strtol (long)
26 */
27
28rtems_status_code rtems_string_to_long (
29  const char *s,
30  long *n,
31  char **endptr,
32  int base
33)
34{
35  long result;
36  char *end;
37
38  if ( !n )
39    return RTEMS_INVALID_ADDRESS;
40
41  errno = 0;
42  *n = 0;
43
44  result = strtol( s, &end, base );
45
46  if ( endptr )
47    *endptr = end;
48
49  if ( end == s )
50    return RTEMS_NOT_DEFINED;
51
52  if ( ( errno == ERANGE ) &&
53    (( result == 0 ) || ( result == LONG_MAX ) || ( result == LONG_MIN )))
54      return RTEMS_INVALID_NUMBER;
55
56  *n = result;
57
58  return RTEMS_SUCCESSFUL;
59}
Note: See TracBrowser for help on using the repository browser.