4.115
Last change
on this file since 0e867af1 was
0e867af1,
checked in by Ralf Corsepius <ralf.corsepius@…>, on 01/31/11 at 16:25:13
|
2011-01-31 Ralf Corsepius <ralf.corsepius@…>
- libmisc/stringto/stringtoint.c,
libmisc/stringto/stringtounsignedint.c,
libmisc/stringto/stringtounsignedchar.c: Rework.
|
-
Property mode set to
100644
|
File size:
1.3 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 (int) |
---|
26 | */ |
---|
27 | |
---|
28 | rtems_status_code rtems_string_to_int ( |
---|
29 | const char *s, |
---|
30 | int *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 ( (result == LONG_MAX) && (errno == ERANGE) ) |
---|
53 | return RTEMS_INVALID_NUMBER; |
---|
54 | |
---|
55 | if ( (result == LONG_MIN) && (errno == ERANGE) ) |
---|
56 | return RTEMS_INVALID_NUMBER; |
---|
57 | |
---|
58 | #if (INT_MAX < LONG_MAX) |
---|
59 | if ( result > INT_MAX ) { |
---|
60 | errno = ERANGE; |
---|
61 | return RTEMS_INVALID_NUMBER; |
---|
62 | } |
---|
63 | #endif |
---|
64 | |
---|
65 | #if (INT_MIN < LONG_MIN) |
---|
66 | if ( result < INT_MIN ) { |
---|
67 | errno = ERANGE; |
---|
68 | return RTEMS_INVALID_NUMBER; |
---|
69 | } |
---|
70 | #endif |
---|
71 | |
---|
72 | *n = result; |
---|
73 | |
---|
74 | return RTEMS_SUCCESSFUL; |
---|
75 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.