diff options
-rw-r--r-- | src/lib/libc/stdlib/strtol.3 | 51 | ||||
-rw-r--r-- | src/lib/libc/stdlib/strtoul.3 | 47 |
2 files changed, 61 insertions, 37 deletions
diff --git a/src/lib/libc/stdlib/strtol.3 b/src/lib/libc/stdlib/strtol.3 index c0a60979d9..742be4cbb7 100644 --- a/src/lib/libc/stdlib/strtol.3 +++ b/src/lib/libc/stdlib/strtol.3 | |||
@@ -29,9 +29,9 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" $OpenBSD: strtol.3,v 1.24 2013/08/14 06:32:28 jmc Exp $ | 32 | .\" $OpenBSD: strtol.3,v 1.25 2014/09/14 14:32:44 schwarze Exp $ |
33 | .\" | 33 | .\" |
34 | .Dd $Mdocdate: August 14 2013 $ | 34 | .Dd $Mdocdate: September 14 2014 $ |
35 | .Dt STRTOL 3 | 35 | .Dt STRTOL 3 |
36 | .Os | 36 | .Os |
37 | .Sh NAME | 37 | .Sh NAME |
@@ -45,14 +45,11 @@ | |||
45 | .In stdlib.h | 45 | .In stdlib.h |
46 | .Ft long | 46 | .Ft long |
47 | .Fn strtol "const char *nptr" "char **endptr" "int base" | 47 | .Fn strtol "const char *nptr" "char **endptr" "int base" |
48 | .Pp | ||
49 | .Ft long long | 48 | .Ft long long |
50 | .Fn strtoll "const char *nptr" "char **endptr" "int base" | 49 | .Fn strtoll "const char *nptr" "char **endptr" "int base" |
51 | .Pp | ||
52 | .In inttypes.h | 50 | .In inttypes.h |
53 | .Ft intmax_t | 51 | .Ft intmax_t |
54 | .Fn strtoimax "const char *nptr" "char **endptr" "int base" | 52 | .Fn strtoimax "const char *nptr" "char **endptr" "int base" |
55 | .Pp | ||
56 | .In sys/types.h | 53 | .In sys/types.h |
57 | .In limits.h | 54 | .In limits.h |
58 | .In stdlib.h | 55 | .In stdlib.h |
@@ -64,21 +61,21 @@ The | |||
64 | function converts the string in | 61 | function converts the string in |
65 | .Fa nptr | 62 | .Fa nptr |
66 | to a | 63 | to a |
67 | .Li long | 64 | .Vt long |
68 | value. | 65 | value. |
69 | The | 66 | The |
70 | .Fn strtoll | 67 | .Fn strtoll |
71 | function converts the string in | 68 | function converts the string in |
72 | .Fa nptr | 69 | .Fa nptr |
73 | to a | 70 | to a |
74 | .Li long long | 71 | .Vt long long |
75 | value. | 72 | value. |
76 | The | 73 | The |
77 | .Fn strtoimax | 74 | .Fn strtoimax |
78 | function converts the string in | 75 | function converts the string in |
79 | .Fa nptr | 76 | .Fa nptr |
80 | to an | 77 | to an |
81 | .Li intmax_t | 78 | .Vt intmax_t |
82 | value. | 79 | value. |
83 | The | 80 | The |
84 | .Fn strtoq | 81 | .Fn strtoq |
@@ -108,10 +105,10 @@ is taken as 10 (decimal) unless the next character is | |||
108 | in which case it is taken as 8 (octal). | 105 | in which case it is taken as 8 (octal). |
109 | .Pp | 106 | .Pp |
110 | The remainder of the string is converted to a | 107 | The remainder of the string is converted to a |
111 | .Li long , | 108 | .Vt long , |
112 | .Li long long , | 109 | .Vt long long , |
113 | or | 110 | or |
114 | .Li intmax_t , | 111 | .Vt intmax_t |
115 | value in the obvious manner, | 112 | value in the obvious manner, |
116 | stopping at the first character which is not a valid digit | 113 | stopping at the first character which is not a valid digit |
117 | in the given base. | 114 | in the given base. |
@@ -151,14 +148,7 @@ The | |||
151 | .Fn strtoimax , | 148 | .Fn strtoimax , |
152 | and | 149 | and |
153 | .Fn strtoq | 150 | .Fn strtoq |
154 | functions return the result of the conversion, | 151 | functions return the result of the conversion. |
155 | unless the value would underflow or overflow. | ||
156 | If no conversion could be performed, 0 is returned; | ||
157 | the global variable | ||
158 | .Va errno | ||
159 | is also set to | ||
160 | .Er EINVAL , | ||
161 | though this is not portable across all platforms. | ||
162 | If overflow or underflow occurs, | 152 | If overflow or underflow occurs, |
163 | .Va errno | 153 | .Va errno |
164 | is set to | 154 | is set to |
@@ -171,6 +161,14 @@ and the function return value is as follows: | |||
171 | .It Fn strtoimax Ta Dv INTMAX_MIN Ta Dv INTMAX_MAX | 161 | .It Fn strtoimax Ta Dv INTMAX_MIN Ta Dv INTMAX_MAX |
172 | .It Fn strtoq Ta Dv LLONG_MIN Ta Dv LLONG_MAX | 162 | .It Fn strtoq Ta Dv LLONG_MIN Ta Dv LLONG_MAX |
173 | .El | 163 | .El |
164 | .Pp | ||
165 | If there is no valid digit, 0 is returned. | ||
166 | If | ||
167 | .Ar base | ||
168 | is invalid, 0 is returned and the global variable | ||
169 | .Va errno | ||
170 | is set to | ||
171 | .Er EINVAL . | ||
174 | .Sh EXAMPLES | 172 | .Sh EXAMPLES |
175 | Ensuring that a string is a valid number (i.e., in range and containing no | 173 | Ensuring that a string is a valid number (i.e., in range and containing no |
176 | trailing characters) requires clearing | 174 | trailing characters) requires clearing |
@@ -212,9 +210,9 @@ If | |||
212 | is being used instead of | 210 | is being used instead of |
213 | .Xr atoi 3 , | 211 | .Xr atoi 3 , |
214 | error checking is further complicated because the desired return value is an | 212 | error checking is further complicated because the desired return value is an |
215 | .Li int | 213 | .Vt int |
216 | rather than a | 214 | rather than a |
217 | .Li long ; | 215 | .Vt long ; |
218 | however, on some architectures integers and long integers are the same size. | 216 | however, on some architectures integers and long integers are the same size. |
219 | Thus the following is necessary: | 217 | Thus the following is necessary: |
220 | .Bd -literal -offset indent | 218 | .Bd -literal -offset indent |
@@ -235,6 +233,10 @@ ival = lval; | |||
235 | .Ed | 233 | .Ed |
236 | .Sh ERRORS | 234 | .Sh ERRORS |
237 | .Bl -tag -width Er | 235 | .Bl -tag -width Er |
236 | .It Bq Er EINVAL | ||
237 | The value of | ||
238 | .Ar base | ||
239 | was neither between 2 and 36 inclusive nor the special value 0. | ||
238 | .It Bq Er ERANGE | 240 | .It Bq Er ERANGE |
239 | The given string was out of range; the value converted has been clamped. | 241 | The given string was out of range; the value converted has been clamped. |
240 | .El | 242 | .El |
@@ -255,6 +257,13 @@ and | |||
255 | .Fn strtoimax | 257 | .Fn strtoimax |
256 | functions conform to | 258 | functions conform to |
257 | .St -ansiC-99 . | 259 | .St -ansiC-99 . |
260 | Setting | ||
261 | .Va errno | ||
262 | to | ||
263 | .Dv EINVAL | ||
264 | is an extension to that standard required by | ||
265 | .St -p1003.1-2008 . | ||
266 | .Pp | ||
258 | The | 267 | The |
259 | .Fn strtoq | 268 | .Fn strtoq |
260 | function is a | 269 | function is a |
diff --git a/src/lib/libc/stdlib/strtoul.3 b/src/lib/libc/stdlib/strtoul.3 index 1353637d68..122ad7bb26 100644 --- a/src/lib/libc/stdlib/strtoul.3 +++ b/src/lib/libc/stdlib/strtoul.3 | |||
@@ -29,9 +29,9 @@ | |||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
31 | .\" | 31 | .\" |
32 | .\" $OpenBSD: strtoul.3,v 1.22 2013/08/14 06:32:28 jmc Exp $ | 32 | .\" $OpenBSD: strtoul.3,v 1.23 2014/09/14 14:32:44 schwarze Exp $ |
33 | .\" | 33 | .\" |
34 | .Dd $Mdocdate: August 14 2013 $ | 34 | .Dd $Mdocdate: September 14 2014 $ |
35 | .Dt STRTOUL 3 | 35 | .Dt STRTOUL 3 |
36 | .Os | 36 | .Os |
37 | .Sh NAME | 37 | .Sh NAME |
@@ -61,21 +61,21 @@ The | |||
61 | function converts the string in | 61 | function converts the string in |
62 | .Fa nptr | 62 | .Fa nptr |
63 | to an | 63 | to an |
64 | .Li unsigned long | 64 | .Vt unsigned long |
65 | value. | 65 | value. |
66 | The | 66 | The |
67 | .Fn strtoull | 67 | .Fn strtoull |
68 | function converts the string in | 68 | function converts the string in |
69 | .Fa nptr | 69 | .Fa nptr |
70 | to an | 70 | to an |
71 | .Li unsigned long long | 71 | .Vt unsigned long long |
72 | value. | 72 | value. |
73 | The | 73 | The |
74 | .Fn strtoumax | 74 | .Fn strtoumax |
75 | function converts the string in | 75 | function converts the string in |
76 | .Fa nptr | 76 | .Fa nptr |
77 | to a | 77 | to a |
78 | .Li umaxint_t | 78 | .Vt umaxint_t |
79 | value. | 79 | value. |
80 | The | 80 | The |
81 | .Fn strtouq | 81 | .Fn strtouq |
@@ -84,8 +84,7 @@ function is a deprecated equivalent of | |||
84 | and is provided for backwards compatibility with legacy programs. | 84 | and is provided for backwards compatibility with legacy programs. |
85 | The conversion is done according to the given | 85 | The conversion is done according to the given |
86 | .Fa base , | 86 | .Fa base , |
87 | which must be a number between 2 and 36 inclusive | 87 | which must be a number between 2 and 36 inclusive or the special value 0. |
88 | or the special value 0. | ||
89 | If the string in | 88 | If the string in |
90 | .Fa nptr | 89 | .Fa nptr |
91 | represents a negative number, it will be converted to its unsigned equivalent. | 90 | represents a negative number, it will be converted to its unsigned equivalent. |
@@ -111,9 +110,12 @@ is taken as 10 (decimal) unless the next character is | |||
111 | in which case it is taken as 8 (octal). | 110 | in which case it is taken as 8 (octal). |
112 | .Pp | 111 | .Pp |
113 | The remainder of the string is converted to an | 112 | The remainder of the string is converted to an |
114 | .Li unsigned long | 113 | .Vt unsigned long , |
115 | value in the obvious manner, stopping at the end of the string | 114 | .Vt unsigned long long , |
116 | or at the first character that does not produce a valid digit | 115 | or |
116 | .Vt uintmax_t | ||
117 | value in the obvious manner, | ||
118 | stopping at the first character which is not a valid digit | ||
117 | in the given base. | 119 | in the given base. |
118 | (In bases above 10, the letter | 120 | (In bases above 10, the letter |
119 | .Ql A | 121 | .Ql A |
@@ -172,12 +174,6 @@ and the global variable | |||
172 | .Va errno | 174 | .Va errno |
173 | is set to | 175 | is set to |
174 | .Er ERANGE . | 176 | .Er ERANGE . |
175 | If no conversion could be performed, 0 is returned; | ||
176 | the global variable | ||
177 | .Va errno | ||
178 | is also set to | ||
179 | .Er EINVAL , | ||
180 | though this is not portable across all platforms. | ||
181 | .Pp | 177 | .Pp |
182 | There is no way to determine if | 178 | There is no way to determine if |
183 | .Fn strtoul | 179 | .Fn strtoul |
@@ -185,6 +181,14 @@ has processed a negative number (and returned an unsigned value) short of | |||
185 | examining the string in | 181 | examining the string in |
186 | .Fa nptr | 182 | .Fa nptr |
187 | directly. | 183 | directly. |
184 | .Pp | ||
185 | If there is no valid digit, 0 is returned. | ||
186 | If | ||
187 | .Ar base | ||
188 | is invalid, 0 is returned and the global variable | ||
189 | .Va errno | ||
190 | is set to | ||
191 | .Er EINVAL . | ||
188 | .Sh EXAMPLES | 192 | .Sh EXAMPLES |
189 | Ensuring that a string is a valid number (i.e., in range and containing no | 193 | Ensuring that a string is a valid number (i.e., in range and containing no |
190 | trailing characters) requires clearing | 194 | trailing characters) requires clearing |
@@ -222,6 +226,10 @@ alternately, use | |||
222 | .Xr sscanf 3 . | 226 | .Xr sscanf 3 . |
223 | .Sh ERRORS | 227 | .Sh ERRORS |
224 | .Bl -tag -width Er | 228 | .Bl -tag -width Er |
229 | .It Bq Er EINVAL | ||
230 | The value of | ||
231 | .Ar base | ||
232 | was neither between 2 and 36 inclusive nor the special value 0. | ||
225 | .It Bq Er ERANGE | 233 | .It Bq Er ERANGE |
226 | The given string was out of range; the value converted has been clamped. | 234 | The given string was out of range; the value converted has been clamped. |
227 | .El | 235 | .El |
@@ -236,6 +244,13 @@ and | |||
236 | .Fn strtoumax | 244 | .Fn strtoumax |
237 | functions conform to | 245 | functions conform to |
238 | .St -ansiC-99 . | 246 | .St -ansiC-99 . |
247 | Setting | ||
248 | .Va errno | ||
249 | to | ||
250 | .Dv EINVAL | ||
251 | is an extension to that standard required by | ||
252 | .St -p1003.1-2008 . | ||
253 | .Pp | ||
239 | The | 254 | The |
240 | .Fn strtouq | 255 | .Fn strtouq |
241 | function is a | 256 | function is a |