summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/atol.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2001-12-25 04:10:50 +0000
committerache <ache@FreeBSD.org>2001-12-25 04:10:50 +0000
commit091d3aa837daf60bd832f189e92df8ab66586197 (patch)
treef459d8eef7a900e7333840ef9c570e9ce81b1125 /lib/libc/stdlib/atol.c
parent91aada8d5feb4ccebe48ea3ab211000016c9aeaf (diff)
downloadFreeBSD-src-091d3aa837daf60bd832f189e92df8ab66586197.zip
FreeBSD-src-091d3aa837daf60bd832f189e92df8ab66586197.tar.gz
Preserve errno.
According to C99: "The functions atof, atoi, atol, and atoll need not affect the value of the integer expression errno on an error. If the value of the result cannot be represented, the behavior is undefined."
Diffstat (limited to 'lib/libc/stdlib/atol.c')
-rw-r--r--lib/libc/stdlib/atol.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/libc/stdlib/atol.c b/lib/libc/stdlib/atol.c
index 31bcaa6..b85b8b2 100644
--- a/lib/libc/stdlib/atol.c
+++ b/lib/libc/stdlib/atol.c
@@ -29,18 +29,26 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
+ *
+ * $FreeBSD$
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)atol.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
-#include <stddef.h>
+#include <errno.h>
#include <stdlib.h>
long
atol(str)
const char *str;
{
- return(strtol(str, (char **)NULL, 10));
+ long r;
+ int saverr;
+
+ saverr = errno;
+ r = strtol(str, (char **)NULL, 10);
+ errno = saverr;
+ return r;
}
OpenPOWER on IntegriCloud