diff options
| author | dholland <dholland@NetBSD.org> | 2009-07-23 02:54:27 +0000 |
|---|---|---|
| committer | dholland <dholland@NetBSD.org> | 2009-07-23 02:54:27 +0000 |
| commit | 3cfdfcef434187d6327d644fc5b8304ff779ea81 (patch) | |
| tree | 4d08595dd04a84d3d0dab532d9bb60b3eddd4d2d /lib/libc/stdlib | |
| parent | 6687b6883dbb59a6659809fa530451b7bbd04857 (diff) | |
Clarify the description of the errno behavior, based on the recent
thread in tech-userlevel.
Diffstat (limited to 'lib/libc/stdlib')
| -rw-r--r-- | lib/libc/stdlib/strtol.3 | 23 | ||||
| -rw-r--r-- | lib/libc/stdlib/strtoul.3 | 23 |
2 files changed, 28 insertions, 18 deletions
diff --git a/lib/libc/stdlib/strtol.3 b/lib/libc/stdlib/strtol.3 index 849181e9215..9d2c90d9374 100644 --- a/lib/libc/stdlib/strtol.3 +++ b/lib/libc/stdlib/strtol.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: strtol.3,v 1.24 2009/05/21 09:13:35 wiz Exp $ +.\" $NetBSD: strtol.3,v 1.25 2009/07/23 02:54:27 dholland Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -193,17 +193,22 @@ argument is not supported then is set to .Er EINVAL and the functions return 0. +.Pp +If no error occurs, +.Va errno +is left unchanged. +This behavior (which is unlike most library functions) is guaranteed +by the pertinent standards. .Sh EXAMPLES -Ensuring that a string is a valid number (i.e., in range and containing no -trailing characters) requires clearing +Because the return value of +.Fn strtol +cannot be used unambiguously to detect an error, .Va errno -beforehand explicitly since +is left unchanged after a successful call. +To ensure that a string is a valid number (i.e., in range and containing no +trailing characters), clear .Va errno -is not changed on a successful call to -.Fn strtol , -and the return value of -.Fn strtol -cannot be used unambiguously to signal an error: +beforehand explicitly, then check it afterwards: .Bd -literal -offset indent char *ep; long lval; diff --git a/lib/libc/stdlib/strtoul.3 b/lib/libc/stdlib/strtoul.3 index 95469ecc032..8171d87a0d7 100644 --- a/lib/libc/stdlib/strtoul.3 +++ b/lib/libc/stdlib/strtoul.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: strtoul.3,v 1.21 2009/05/21 09:13:35 wiz Exp $ +.\" $NetBSD: strtoul.3,v 1.22 2009/07/23 02:54:27 dholland Exp $ .\" .\" Copyright (c) 1990, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -191,17 +191,22 @@ argument is not supported then is set to .Er EINVAL and the functions return 0. +.Pp +If no error occurs, +.Va errno +is left unchanged. +This behavior (which is unlike most library functions) is guaranteed +by the pertinent standards. .Sh EXAMPLES -Ensuring that a string is a valid number (i.e., in range and containing no -trailing characters) requires clearing +Because the return value of +.Fn strtoul +cannot be used unambiguously to detect an error, .Va errno -beforehand explicitly since +is left unchanged after a successful call. +To ensure that a string is a valid number (i.e., in range and containing no +trailing characters), clear .Va errno -is not changed on a successful call to -.Fn strtoul , -and the return value of -.Fn strtoul -cannot be used unambiguously to signal an error: +beforehand explicitly, then check it afterwards: .Bd -literal -offset indent char *ep; unsigned long ulval; |
