aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/stdlib/strtoul.c
diff options
context:
space:
mode:
authorDavid Chisnall <theraven@FreeBSD.org>2011-11-20 14:45:42 +0000
committerDavid Chisnall <theraven@FreeBSD.org>2011-11-20 14:45:42 +0000
commit3c87aa1d3dc1d8dad3efad322852a8e1e76dee55 (patch)
tree909189922493cddbeeac84af2e316dc897661311 /lib/libc/stdlib/strtoul.c
parent9e134d91bf553c39d4590a9e373837326c465758 (diff)
downloadsrc-3c87aa1d3dc1d8dad3efad322852a8e1e76dee55.tar.gz
src-3c87aa1d3dc1d8dad3efad322852a8e1e76dee55.zip
Implement xlocale APIs from Darwin, mainly for use by libc++. This adds a
load of _l suffixed versions of various standard library functions that use the global locale, making them take an explicit locale parameter. Also adds support for per-thread locales. This work was funded by the FreeBSD Foundation. Please test any code you have that uses the C standard locale functions! Reviewed by: das (gdtoa changes) Approved by: dim (mentor)
Notes
Notes: svn path=/head/; revision=227753
Diffstat (limited to 'lib/libc/stdlib/strtoul.c')
-rw-r--r--lib/libc/stdlib/strtoul.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/libc/stdlib/strtoul.c b/lib/libc/stdlib/strtoul.c
index e8d1e114a0a4..0ae0661c2c08 100644
--- a/lib/libc/stdlib/strtoul.c
+++ b/lib/libc/stdlib/strtoul.c
@@ -2,6 +2,11 @@
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
+ * Copyright (c) 2011 The FreeBSD Foundation
+ * All rights reserved.
+ * Portions of this software were developed by David Chisnall
+ * under sponsorship from the FreeBSD Foundation.
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -37,6 +42,7 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
+#include "xlocale_private.h"
/*
* Convert a string to an unsigned long integer.
@@ -45,13 +51,14 @@ __FBSDID("$FreeBSD$");
* alphabets and digits are each contiguous.
*/
unsigned long
-strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
+strtoul_l(const char * __restrict nptr, char ** __restrict endptr, int base, locale_t locale)
{
const char *s;
unsigned long acc;
char c;
unsigned long cutoff;
int neg, any, cutlim;
+ FIX_LOCALE(locale);
/*
* See strtol for comments as to the logic used.
@@ -59,7 +66,7 @@ strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
s = nptr;
do {
c = *s++;
- } while (isspace((unsigned char)c));
+ } while (isspace_l((unsigned char)c, locale));
if (c == '-') {
neg = 1;
c = *s++;
@@ -116,3 +123,8 @@ noconv:
*endptr = (char *)(any ? s - 1 : nptr);
return (acc);
}
+unsigned long
+strtoul(const char * __restrict nptr, char ** __restrict endptr, int base)
+{
+ return strtoul_l(nptr, endptr, base, __get_locale());
+}