4.10
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 | /* c99 has LLONG_MAX instead of LONG_LONG_MAX */ |
---|
25 | #ifndef LONG_LONG_MAX |
---|
26 | #define LONG_LONG_MAX LLONG_MAX |
---|
27 | #endif |
---|
28 | /* c99 has LLONG_MIN instead of LONG_LONG_MIN */ |
---|
29 | #ifndef LONG_LONG_MIN |
---|
30 | #define LONG_LONG_MIN LLONG_MIN |
---|
31 | #endif |
---|
32 | |
---|
33 | /* |
---|
34 | * Instantiate an error checking wrapper for strtoll (long long) |
---|
35 | */ |
---|
36 | |
---|
37 | rtems_status_code rtems_string_to_long_long ( |
---|
38 | const char *s, |
---|
39 | long long *n, |
---|
40 | char **endptr, |
---|
41 | int base |
---|
42 | ) |
---|
43 | { |
---|
44 | long long result; |
---|
45 | char *end; |
---|
46 | |
---|
47 | if ( !n ) |
---|
48 | return RTEMS_INVALID_ADDRESS; |
---|
49 | |
---|
50 | errno = 0; |
---|
51 | *n = 0; |
---|
52 | |
---|
53 | result = strtoll( s, &end, base ); |
---|
54 | |
---|
55 | if ( endptr ) |
---|
56 | *endptr = end; |
---|
57 | |
---|
58 | if ( end == s ) |
---|
59 | return RTEMS_NOT_DEFINED; |
---|
60 | |
---|
61 | if ( ( errno == ERANGE ) && |
---|
62 | (( result == 0 ) || ( result == LONG_LONG_MAX ) || ( result == LONG_LONG_MIN ))) |
---|
63 | return RTEMS_INVALID_NUMBER; |
---|
64 | |
---|
65 | *n = result; |
---|
66 | |
---|
67 | return RTEMS_SUCCESSFUL; |
---|
68 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.