source: rtems/cpukit/libmisc/stringto/stringtolonglong.c @ 2f8f4950

4.115
Last change on this file since 2f8f4950 was 2f8f4950, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/01/11 at 02:32:46

2011-02-01 Ralf Corsepius <ralf.corsepius@…>

  • libmisc/stringto/stringtolong.c, libmisc/stringto/stringtolonglong.c, libmisc/stringto/stringtounsignedlong.c, libmisc/stringto/stringtounsignedlonglong.c: Rework.
  • Property mode set to 100644
File size: 1.1 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 strtoll (long long)
26 */
27
28rtems_status_code rtems_string_to_long_long (
29  const char *s,
30  long long *n,
31  char **endptr,
32  int base
33)
34{
35  long long result;
36  char *end;
37
38  if ( !n )
39    return RTEMS_INVALID_ADDRESS;
40
41  errno = 0;
42  *n = 0;
43
44  result = strtoll( s, &end, base );
45
46  if ( endptr )
47    *endptr = end;
48
49  if ( end == s )
50    return RTEMS_NOT_DEFINED;
51
52  if ( (result == LONG_LONG_MAX) && (errno == ERANGE) )
53    return RTEMS_INVALID_NUMBER;
54
55  if ( (result == LONG_LONG_MIN) && (errno == ERANGE) )
56    return RTEMS_INVALID_NUMBER;
57
58  *n = result;
59
60  return RTEMS_SUCCESSFUL;
61}
Note: See TracBrowser for help on using the repository browser.