public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Importing inttypes methods
@ 2017-07-25 19:51 Aditya Upadhyay
  2017-07-26 11:08 ` Corinna Vinschen
  0 siblings, 1 reply; 21+ messages in thread
From: Aditya Upadhyay @ 2017-07-25 19:51 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 238 bytes --]

Hello All,

I have ported the inttypes methods from freeBSD. I have made all the
possible changes whatever my mentors suggested me. I am requesting you
to please review the same. Is this ok for master ?

Thanks & Regards,
Aditya Upadhyay

[-- Attachment #2: 0001-Importing-imaxabs-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 2580 bytes --]

From 958467f21049d9873db44847c805a589d5fc076e Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Wed, 26 Jul 2017 00:59:48 +0530
Subject: [PATCH 1/6] Importing imaxabs inttypes method from FreeBSD.

---
 newlib/libc/stdlib/Makefile.am |  1 +
 newlib/libc/stdlib/imaxabs.c   | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100644 newlib/libc/stdlib/imaxabs.c

diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index ebae00ab0..be8833604 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -32,6 +32,7 @@ GENERAL_SOURCES = \
 	gdtoa-hexnan.c	\
 	getenv.c  	\
 	getenv_r.c	\
+	imaxabs.c	\
 	itoa.c          \
 	labs.c 		\
 	ldiv.c  	\
diff --git a/newlib/libc/stdlib/imaxabs.c b/newlib/libc/stdlib/imaxabs.c
new file mode 100644
index 000000000..e43864606
--- /dev/null
+++ b/newlib/libc/stdlib/imaxabs.c
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/imaxabs.c 86368 2001-11-15 02:05:03Z mike $");
+
+#include <inttypes.h>
+#include <stdint.h>
+intmax_t
+imaxabs(intmax_t j)
+{
+	return (j < 0 ? -j : j);
+}
-- 
2.13.0


[-- Attachment #3: 0002-Importing-imaxdiv-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 2893 bytes --]

From b5d0bc8ea11d08e2e3ffe0a8e2039e8841db79b8 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Wed, 26 Jul 2017 01:00:26 +0530
Subject: [PATCH 2/6] Importing imaxdiv inttypes method from FreeBSD.

---
 newlib/libc/stdlib/Makefile.am |  1 +
 newlib/libc/stdlib/imaxdiv.c   | 48 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
 create mode 100644 newlib/libc/stdlib/imaxdiv.c

diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index be8833604..7aaa7fdfa 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -33,6 +33,7 @@ GENERAL_SOURCES = \
 	getenv.c  	\
 	getenv_r.c	\
 	imaxabs.c	\
+	imaxdiv.c	\
 	itoa.c          \
 	labs.c 		\
 	ldiv.c  	\
diff --git a/newlib/libc/stdlib/imaxdiv.c b/newlib/libc/stdlib/imaxdiv.c
new file mode 100644
index 000000000..eb3e99ad6
--- /dev/null
+++ b/newlib/libc/stdlib/imaxdiv.c
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/imaxdiv.c 301115 2016-06-01 10:14:25Z ache $");
+
+#include <inttypes.h>
+#include <stdint.h>
+
+/* See comments in div.c for implementation details. */
+imaxdiv_t
+imaxdiv(intmax_t numer, intmax_t denom)
+{
+	imaxdiv_t retval;
+
+	retval.quot = numer / denom;
+	retval.rem = numer % denom;
+#if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
+	if (numer >= 0 && retval.rem < 0) {
+		retval.quot++;
+		retval.rem -= denom;
+	}
+#endif
+	return (retval);
+}
-- 
2.13.0


[-- Attachment #4: 0003-Importing-strtoimax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 7300 bytes --]

From e809ff91e535424e5e57eeb9d71a6b2f030ccfd9 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Wed, 26 Jul 2017 01:07:20 +0530
Subject: [PATCH 3/6] Importing strtoimax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   9 +++
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/strtoimax.c | 156 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+)
 create mode 100644 newlib/libc/stdlib/strtoimax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 25c6e99fa..2af18e3ba 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -16,10 +16,15 @@
 #include <newlib.h>
 #include <sys/config.h>
 #include <sys/_intsup.h>
+#include "_ansi.h"
 #include <stdint.h>
 #define __need_wchar_t
 #include <stddef.h>
 
+#if __POSIX_VISIBLE >= 200809
+#include <xlocale.h>
+#endif
+
 #define __STRINGIFY(a) #a
 
 /* 8-bit types */
@@ -309,12 +314,16 @@ typedef struct {
   intmax_t	rem;
 } imaxdiv_t;
 
+struct _reent;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 extern intmax_t  imaxabs(intmax_t j);
 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
+extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict, int, locale_t);
+extern intmax_t  _strtoimax_r(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 7aaa7fdfa..64a9d435a 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -59,6 +59,7 @@ GENERAL_SOURCES = \
 	sb_charsets.c	\
 	strtod.c	\
 	strtodg.c	\
+	strtoimax.c	\
 	strtol.c	\
 	strtorx.c	\
 	strtoul.c	\
diff --git a/newlib/libc/stdlib/strtoimax.c b/newlib/libc/stdlib/strtoimax.c
new file mode 100644
index 000000000..d041c300c
--- /dev/null
+++ b/newlib/libc/stdlib/strtoimax.c
@@ -0,0 +1,156 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtol.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoimax.c 251672 2013-06-13 00:19:30Z emaste $");
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a string to an intmax_t integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+/*
+ *Reentrant version of strtoimax.
+ */
+intmax_t
+_strtoimax_r(struct _reent *rptr, const char * __restrict nptr,
+	     char ** __restrict endptr, int base, locale_t loc)
+{
+	const char *s = (const unsigned char *)nptr;
+	uintmax_t acc;
+	char c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	do {
+		c = *s++;
+	} while (isspace_l(c, loc));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for intmax_t is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
+	 *
+	 * Set 'any' if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? -(uintmax_t)INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? INTMAX_MIN : INTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
+intmax_t
+strtoimax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
+	    locale_t loc)
+{
+	return _strtoimax_r(_REENT, nptr, endptr, base, loc);
+}
+intmax_t
+strtoimax(const char* __restrict nptr, char** __restrict endptr, int base)
+{
+	return _strtoimax_r(_REENT, nptr, endptr, base, __get_current_locale());
+}		
-- 
2.13.0


[-- Attachment #5: 0004-Importing-strtoumax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6135 bytes --]

From 371360152a2238d5e78cfc0703bbad28845460e4 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Wed, 26 Jul 2017 01:09:01 +0530
Subject: [PATCH 4/6] Importing strtoumax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   2 +
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/strtoumax.c | 138 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 newlib/libc/stdlib/strtoumax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 2af18e3ba..bcae94ea6 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -325,6 +325,8 @@ extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
 extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict, int, locale_t);
 extern intmax_t  _strtoimax_r(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
+extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, int, locale_t);
+extern uintmax_t _strtoumax_r(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 64a9d435a..1ccd2c488 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -63,6 +63,7 @@ GENERAL_SOURCES = \
 	strtol.c	\
 	strtorx.c	\
 	strtoul.c	\
+	strtoumax.c	\
 	utoa.c          \
 	wcstod.c	\
 	wcstol.c	\
diff --git a/newlib/libc/stdlib/strtoumax.c b/newlib/libc/stdlib/strtoumax.c
new file mode 100644
index 000000000..240a6afed
--- /dev/null
+++ b/newlib/libc/stdlib/strtoumax.c
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtoul.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoumax.c 251672 2013-06-13 00:19:30Z emaste $");
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a string to a uintmax_t integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+/*
+ *Reentrant version of strtoumax.
+ */
+uintmax_t
+_strtoumax_r(struct _reent *rptr, const char * __restrict nptr, 
+	     char ** __restrict endptr, int base, locale_t loc)
+{
+	const char *s = (const unsigned char *)nptr;
+	uintmax_t acc;
+	char c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (isspace_l(c, loc));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = UINTMAX_MAX / base;
+	cutlim = UINTMAX_MAX % base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = UINTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
+uintmax_t
+strtoumax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
+	    locale_t loc)
+{
+	return _strtoumax_r(_REENT, nptr, endptr, base, loc);
+}
+uintmax_t
+strtoumax(const char* __restrict nptr, char** __restrict endptr, int base)
+{
+	return _strtoumax_r(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.13.0


[-- Attachment #6: 0005-Importing-wcstoimax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6298 bytes --]

From 2cf8b8dca53b8c5c8026e6a039f9d82f58234ab3 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Wed, 26 Jul 2017 01:11:02 +0530
Subject: [PATCH 5/6] Importing wcstoimax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   2 +
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/wcstoimax.c | 145 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 newlib/libc/stdlib/wcstoimax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index bcae94ea6..a4ea2cbf9 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -328,6 +328,8 @@ extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
 extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, int, locale_t);
 extern uintmax_t _strtoumax_r(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
+extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
+extern intmax_t  _wcstoimax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
 
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 1ccd2c488..b687c0fa2 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -66,6 +66,7 @@ GENERAL_SOURCES = \
 	strtoumax.c	\
 	utoa.c          \
 	wcstod.c	\
+	wcstoimax.c	\
 	wcstol.c	\
 	wcstoul.c	\
 	wcstombs.c	\
diff --git a/newlib/libc/stdlib/wcstoimax.c b/newlib/libc/stdlib/wcstoimax.c
new file mode 100644
index 000000000..0994bcb94
--- /dev/null
+++ b/newlib/libc/stdlib/wcstoimax.c
@@ -0,0 +1,145 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtol.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoimax.c,v 1.8 2002/09/06 11:23:59 tjr Exp ");
+#endif
+__FBSDID("$FreeBSD: head/lib/libc/locale/wcstoimax.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <reent.h>
+#include <stdint.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a wide character string to an intmax_t integer.
+ */
+
+/*
+ *Reentrant version of wcstoimax.
+ */
+intmax_t
+_wcstoimax_r(struct _reent *rptr, const wchar_t * __restrict nptr, 
+	     wchar_t ** __restrict endptr, int base, locale_t loc)
+{
+	const wchar_t *s = nptr;
+	uintmax_t acc;
+	wchar_t c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (iswspace_l(c, loc));
+	if (c == L'-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == L'+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == L'0' && (*s == L'x' || *s == L'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == L'0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = neg ? -(uintmax_t)INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+#ifdef notyet
+		if (iswdigit_l(c, loc))
+			c = digittoint_l(c, loc);
+		else
+#endif
+		if (c >= L'0' && c <= L'9')
+			c -= L'0';
+		else if (c >= L'A' && c <= L'Z')
+			c -= L'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= L'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? INTMAX_MIN : INTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
+intmax_t
+wcstoimax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+    	    int base, locale_t loc)
+{
+	return _wcstoimax_r(_REENT, nptr, endptr, base, loc);
+}
+intmax_t
+wcstoimax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
+{
+	return _wcstoimax_r(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.13.0


[-- Attachment #7: 0006-Importing-wcstoumax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6201 bytes --]

From 06570e2bd1f1a3763e3b7ae89c335ffc8f24837b Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Wed, 26 Jul 2017 01:12:09 +0530
Subject: [PATCH 6/6] Importing wcstoumax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   2 +
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/wcstoumax.c | 144 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+)
 create mode 100644 newlib/libc/stdlib/wcstoumax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index a4ea2cbf9..2cba659fb 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -331,6 +331,8 @@ extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
 extern intmax_t  _wcstoimax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
+extern uintmax_t wcstoumax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
+extern uintmax_t _wcstoumax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
 
 #ifdef __cplusplus
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index b687c0fa2..f9bab0b64 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -69,6 +69,7 @@ GENERAL_SOURCES = \
 	wcstoimax.c	\
 	wcstol.c	\
 	wcstoul.c	\
+	wcstoumax.c	\
 	wcstombs.c	\
 	wcstombs_r.c	\
 	wctomb.c	\
diff --git a/newlib/libc/stdlib/wcstoumax.c b/newlib/libc/stdlib/wcstoumax.c
new file mode 100644
index 000000000..da58532b9
--- /dev/null
+++ b/newlib/libc/stdlib/wcstoumax.c
@@ -0,0 +1,144 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtoul.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoumax.c,v 1.8 2002/09/06 11:23:59 tjr Exp ");
+#endif
+__FBSDID("$FreeBSD: head/lib/libc/locale/wcstoumax.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a wide character string to a uintmax_t integer.
+ */
+
+/*
+ *Reentrant version of wcstoumax.
+ */
+uintmax_t
+_wcstoumax_r(struct _reent *rptr,const wchar_t * __restrict nptr, 
+	     wchar_t ** __restrict endptr, int base, locale_t loc)
+{
+	const wchar_t *s = nptr;
+	uintmax_t acc;
+	wchar_t c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (iswspace_l(c, loc));
+	if (c == L'-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == L'+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == L'0' && (*s == L'x' || *s == L'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == L'0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = UINTMAX_MAX / base;
+	cutlim = UINTMAX_MAX % base;
+	for ( ; ; c = *s++) {
+#ifdef notyet
+		if (iswdigit_l(c, loc))
+			c = digittoint_l(c, loc);
+		else
+#endif
+		if (c >= L'0' && c <= L'9')
+			c -= L'0';
+		else if (c >= L'A' && c <= L'Z')
+			c -= L'A' - 10;
+		else if (c >= L'a' && c <= L'z')
+			c -= L'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = UINTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
+uintmax_t
+wcstoumax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+    	    int base, locale_t loc)
+{
+	return _wcstoumax_r(_REENT, nptr, endptr, base, loc);
+}
+uintmax_t
+wcstoumax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
+{
+	return _wcstoumax_r(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.13.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-25 19:51 Importing inttypes methods Aditya Upadhyay
@ 2017-07-26 11:08 ` Corinna Vinschen
  2017-07-26 12:02   ` Sebastian Huber
  2017-07-26 12:02   ` Aditya Upadhyay
  0 siblings, 2 replies; 21+ messages in thread
From: Corinna Vinschen @ 2017-07-26 11:08 UTC (permalink / raw)
  To: Aditya Upadhyay; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 1121 bytes --]

On Jul 26 01:20, Aditya Upadhyay wrote:
> Hello All,
> 
> I have ported the inttypes methods from freeBSD. I have made all the
> possible changes whatever my mentors suggested me. I am requesting you
> to please review the same. Is this ok for master ?

The patches apply and build.  This looks 99% good now, thank you.

Just one last minor problem, which is my fault, not yours:

You named the reentrant functions _strtoimax_r, _wcstoumax_r, etc.,
which is basically right.

However, the *other*, equivalent reentrant, locale-specific functions
for other datatypes are all named with a trailing l: _strtol_l,
_wcstoull_l, etc.  In retrospect, this wasn't the brightest idea,
but the API has been exported this way, so I'm reluctant to change
it after the fact.

Would you mind to call your new functions with trailing 'l' rather
than 'r', too, to use the same naming convention, please?

Oh, btw., please make sure the patches have no trailing whitespace.
That's not really a problem, but `git am' complains about them.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-26 11:08 ` Corinna Vinschen
@ 2017-07-26 12:02   ` Sebastian Huber
  2017-07-26 12:02   ` Aditya Upadhyay
  1 sibling, 0 replies; 21+ messages in thread
From: Sebastian Huber @ 2017-07-26 12:02 UTC (permalink / raw)
  To: newlib

On 26/07/17 13:08, Corinna Vinschen wrote:

> Oh, btw., please make sure the patches have no trailing whitespace.
> That's not really a problem, but `git am' complains about them.

I think we should keep the trailing white space if it is already in the 
original file.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber@embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-26 11:08 ` Corinna Vinschen
  2017-07-26 12:02   ` Sebastian Huber
@ 2017-07-26 12:02   ` Aditya Upadhyay
  2017-07-26 21:24     ` Aditya Upadhyay
  1 sibling, 1 reply; 21+ messages in thread
From: Aditya Upadhyay @ 2017-07-26 12:02 UTC (permalink / raw)
  To: newlib

On Wed, Jul 26, 2017 at 4:38 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Jul 26 01:20, Aditya Upadhyay wrote:
>> Hello All,
>>
>> I have ported the inttypes methods from freeBSD. I have made all the
>> possible changes whatever my mentors suggested me. I am requesting you
>> to please review the same. Is this ok for master ?
>
> The patches apply and build.  This looks 99% good now, thank you.
>
Thanks.
> Just one last minor problem, which is my fault, not yours:
>
> You named the reentrant functions _strtoimax_r, _wcstoumax_r, etc.,
> which is basically right.
>
> However, the *other*, equivalent reentrant, locale-specific functions
> for other datatypes are all named with a trailing l: _strtol_l,
> _wcstoull_l, etc.  In retrospect, this wasn't the brightest idea,
> but the API has been exported this way, so I'm reluctant to change
> it after the fact.
>
> Would you mind to call your new functions with trailing 'l' rather
> than 'r', too, to use the same naming convention, please?
>
I will keep your points in mind whenever i will port a new function.
> Oh, btw., please make sure the patches have no trailing whitespace.
> That's not really a problem, but `git am' complains about them.
>
>
> Thanks,
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-26 12:02   ` Aditya Upadhyay
@ 2017-07-26 21:24     ` Aditya Upadhyay
  2017-07-27 12:32       ` Corinna Vinschen
  0 siblings, 1 reply; 21+ messages in thread
From: Aditya Upadhyay @ 2017-07-26 21:24 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]

This is the modified patches for inttypes methods. I have changed the
method name with trailing _l . Do i need to send the patch for imaxabs
and imaxdiv method again ? I am attaching patch v2 for strtoimax,
strtoumax, wcstoimax and wcstoumax.
Please review the same.

Thanks & Regards,
Aditya Upadhyay

On Wed, Jul 26, 2017 at 5:32 PM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
> On Wed, Jul 26, 2017 at 4:38 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> On Jul 26 01:20, Aditya Upadhyay wrote:
>>> Hello All,
>>>
>>> I have ported the inttypes methods from freeBSD. I have made all the
>>> possible changes whatever my mentors suggested me. I am requesting you
>>> to please review the same. Is this ok for master ?
>>
>> The patches apply and build.  This looks 99% good now, thank you.
>>
> Thanks.
>> Just one last minor problem, which is my fault, not yours:
>>
>> You named the reentrant functions _strtoimax_r, _wcstoumax_r, etc.,
>> which is basically right.
>>
>> However, the *other*, equivalent reentrant, locale-specific functions
>> for other datatypes are all named with a trailing l: _strtol_l,
>> _wcstoull_l, etc.  In retrospect, this wasn't the brightest idea,
>> but the API has been exported this way, so I'm reluctant to change
>> it after the fact.
>>
>> Would you mind to call your new functions with trailing 'l' rather
>> than 'r', too, to use the same naming convention, please?
>>
> I will keep your points in mind whenever i will port a new function.
>> Oh, btw., please make sure the patches have no trailing whitespace.
>> That's not really a problem, but `git am' complains about them.
>>
>>
>> Thanks,
>> Corinna
>>
>> --
>> Corinna Vinschen
>> Cygwin Maintainer
>> Red Hat

[-- Attachment #2: v2-0001-importing-strtoimax-inttypes-methods-with-fixed-t.patch --]
[-- Type: text/x-patch, Size: 2344 bytes --]

From 5772bf5cc3ed2b5f0b98f568eff2c919841b9938 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 02:30:23 +0530
Subject: [PATCH v2 1/4] importing strtoimax inttypes methods with fixed
 trailed l.

---
 newlib/libc/include/inttypes.h | 2 +-
 newlib/libc/stdlib/strtoimax.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 2cba659fb..cabcefbec 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -323,7 +323,7 @@ extern "C" {
 extern intmax_t  imaxabs(intmax_t j);
 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
 extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict, int, locale_t);
-extern intmax_t  _strtoimax_r(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
+extern intmax_t  _strtoimax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
 extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, int, locale_t);
 extern uintmax_t _strtoumax_r(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
diff --git a/newlib/libc/stdlib/strtoimax.c b/newlib/libc/stdlib/strtoimax.c
index d041c300c..e7f0d329f 100644
--- a/newlib/libc/stdlib/strtoimax.c
+++ b/newlib/libc/stdlib/strtoimax.c
@@ -57,7 +57,7 @@ __FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoimax.c 251672 2013-06-13 00:19:30Z
  *Reentrant version of strtoimax.
  */
 intmax_t
-_strtoimax_r(struct _reent *rptr, const char * __restrict nptr,
+_strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
 	     char ** __restrict endptr, int base, locale_t loc)
 {
 	const char *s = (const unsigned char *)nptr;
@@ -147,10 +147,10 @@ intmax_t
 strtoimax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
 	    locale_t loc)
 {
-	return _strtoimax_r(_REENT, nptr, endptr, base, loc);
+	return _strtoimax_l(_REENT, nptr, endptr, base, loc);
 }
 intmax_t
 strtoimax(const char* __restrict nptr, char** __restrict endptr, int base)
 {
-	return _strtoimax_r(_REENT, nptr, endptr, base, __get_current_locale());
+	return _strtoimax_l(_REENT, nptr, endptr, base, __get_current_locale());
 }		
-- 
2.13.0


[-- Attachment #3: v2-0002-importing-strtoumax-inttypes-methods-with-fixed-t.patch --]
[-- Type: text/x-patch, Size: 2511 bytes --]

From e0eda0ce0df697d51443d916f947b9a576753705 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 02:33:38 +0530
Subject: [PATCH v2 2/4] importing strtoumax inttypes methods with fixed
 trailed l.

---
 newlib/libc/include/inttypes.h | 2 +-
 newlib/libc/stdlib/strtoumax.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index cabcefbec..6e94a5385 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -326,7 +326,7 @@ extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict, int, loca
 extern intmax_t  _strtoimax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
 extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, int, locale_t);
-extern uintmax_t _strtoumax_r(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
+extern uintmax_t _strtoumax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
 extern intmax_t  _wcstoimax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
diff --git a/newlib/libc/stdlib/strtoumax.c b/newlib/libc/stdlib/strtoumax.c
index 240a6afed..b2426a580 100644
--- a/newlib/libc/stdlib/strtoumax.c
+++ b/newlib/libc/stdlib/strtoumax.c
@@ -57,7 +57,7 @@ __FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoumax.c 251672 2013-06-13 00:19:30Z
  *Reentrant version of strtoumax.
  */
 uintmax_t
-_strtoumax_r(struct _reent *rptr, const char * __restrict nptr, 
+_strtoumax_l(struct _reent *rptr, const char * __restrict nptr, 
 	     char ** __restrict endptr, int base, locale_t loc)
 {
 	const char *s = (const unsigned char *)nptr;
@@ -129,10 +129,10 @@ uintmax_t
 strtoumax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
 	    locale_t loc)
 {
-	return _strtoumax_r(_REENT, nptr, endptr, base, loc);
+	return _strtoumax_l(_REENT, nptr, endptr, base, loc);
 }
 uintmax_t
 strtoumax(const char* __restrict nptr, char** __restrict endptr, int base)
 {
-	return _strtoumax_r(_REENT, nptr, endptr, base, __get_current_locale());
+	return _strtoumax_l(_REENT, nptr, endptr, base, __get_current_locale());
 }
-- 
2.13.0


[-- Attachment #4: v2-0003-importing-wcstoimax-inttypes-methods-with-fixed-t.patch --]
[-- Type: text/x-patch, Size: 2537 bytes --]

From 0b63ccd01d3fa913bd28a0478f8917071153995a Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 02:34:29 +0530
Subject: [PATCH v2 3/4] importing wcstoimax inttypes methods with fixed
 trailed l.

---
 newlib/libc/include/inttypes.h | 2 +-
 newlib/libc/stdlib/wcstoimax.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 6e94a5385..5ca0bfcd2 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -329,7 +329,7 @@ extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, int, loca
 extern uintmax_t _strtoumax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
-extern intmax_t  _wcstoimax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
+extern intmax_t  _wcstoimax_l(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
 extern uintmax_t _wcstoumax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
diff --git a/newlib/libc/stdlib/wcstoimax.c b/newlib/libc/stdlib/wcstoimax.c
index 0994bcb94..dd350e6be 100644
--- a/newlib/libc/stdlib/wcstoimax.c
+++ b/newlib/libc/stdlib/wcstoimax.c
@@ -58,7 +58,7 @@ __FBSDID("$FreeBSD: head/lib/libc/locale/wcstoimax.c 314436 2017-02-28 23:42:47Z
  *Reentrant version of wcstoimax.
  */
 intmax_t
-_wcstoimax_r(struct _reent *rptr, const wchar_t * __restrict nptr, 
+_wcstoimax_l(struct _reent *rptr, const wchar_t * __restrict nptr, 
 	     wchar_t ** __restrict endptr, int base, locale_t loc)
 {
 	const wchar_t *s = nptr;
@@ -136,10 +136,10 @@ intmax_t
 wcstoimax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
     	    int base, locale_t loc)
 {
-	return _wcstoimax_r(_REENT, nptr, endptr, base, loc);
+	return _wcstoimax_l(_REENT, nptr, endptr, base, loc);
 }
 intmax_t
 wcstoimax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
 {
-	return _wcstoimax_r(_REENT, nptr, endptr, base, __get_current_locale());
+	return _wcstoimax_l(_REENT, nptr, endptr, base, __get_current_locale());
 }
-- 
2.13.0


[-- Attachment #5: v2-0004-importing-wcstoumax-inttypes-methods-with-fixed-t.patch --]
[-- Type: text/x-patch, Size: 2365 bytes --]

From cafa77e418bc3eca5ad417b481b586400e79790c Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 02:34:52 +0530
Subject: [PATCH v2 4/4] importing wcstoumax inttypes methods with fixed
 trailed l.

---
 newlib/libc/include/inttypes.h | 2 +-
 newlib/libc/stdlib/wcstoumax.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 5ca0bfcd2..532976ad7 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -332,7 +332,7 @@ extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict, int
 extern intmax_t  _wcstoimax_l(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
-extern uintmax_t _wcstoumax_r(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
+extern uintmax_t _wcstoumax_l(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
 
 #ifdef __cplusplus
diff --git a/newlib/libc/stdlib/wcstoumax.c b/newlib/libc/stdlib/wcstoumax.c
index da58532b9..dfa25bd0e 100644
--- a/newlib/libc/stdlib/wcstoumax.c
+++ b/newlib/libc/stdlib/wcstoumax.c
@@ -58,7 +58,7 @@ __FBSDID("$FreeBSD: head/lib/libc/locale/wcstoumax.c 314436 2017-02-28 23:42:47Z
  *Reentrant version of wcstoumax.
  */
 uintmax_t
-_wcstoumax_r(struct _reent *rptr,const wchar_t * __restrict nptr, 
+_wcstoumax_l(struct _reent *rptr,const wchar_t * __restrict nptr, 
 	     wchar_t ** __restrict endptr, int base, locale_t loc)
 {
 	const wchar_t *s = nptr;
@@ -135,10 +135,10 @@ uintmax_t
 wcstoumax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
     	    int base, locale_t loc)
 {
-	return _wcstoumax_r(_REENT, nptr, endptr, base, loc);
+	return _wcstoumax_l(_REENT, nptr, endptr, base, loc);
 }
 uintmax_t
 wcstoumax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
 {
-	return _wcstoumax_r(_REENT, nptr, endptr, base, __get_current_locale());
+	return _wcstoumax_l(_REENT, nptr, endptr, base, __get_current_locale());
 }
-- 
2.13.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-26 21:24     ` Aditya Upadhyay
@ 2017-07-27 12:32       ` Corinna Vinschen
  2017-07-27 14:00         ` Aditya Upadhyay
  0 siblings, 1 reply; 21+ messages in thread
From: Corinna Vinschen @ 2017-07-27 12:32 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 506 bytes --]

On Jul 27 02:54, Aditya Upadhyay wrote:
> This is the modified patches for inttypes methods.

Sigh.  No, it's not.  This is, again, just a patch on top of your other
patch.  *Please* review your patchset before sending it, this looks like
missing a `commit --amend' again.

> I have changed the
> method name with trailing _l . Do i need to send the patch for imaxabs
> and imaxdiv method again ?

No, these were fine.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-27 12:32       ` Corinna Vinschen
@ 2017-07-27 14:00         ` Aditya Upadhyay
  2017-07-28 10:43           ` Corinna Vinschen
  0 siblings, 1 reply; 21+ messages in thread
From: Aditya Upadhyay @ 2017-07-27 14:00 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 993 bytes --]

Hi,

I apologize for the inconvenience caused. Actually i am new to git and
still learning commands. I am trying my best and want to assure you
that i will be familiar with the git soon. I will try not to repeat
the same mistakes again in future.
I am attaching the fresh new patches for last 4 methods with all
possible changes. I am requesting you to please review the patches.


Thanks,
Aditya

On Thu, Jul 27, 2017 at 6:02 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Jul 27 02:54, Aditya Upadhyay wrote:
>> This is the modified patches for inttypes methods.
>
> Sigh.  No, it's not.  This is, again, just a patch on top of your other
> patch.  *Please* review your patchset before sending it, this looks like
> missing a `commit --amend' again.
>
>> I have changed the
>> method name with trailing _l . Do i need to send the patch for imaxabs
>> and imaxdiv method again ?
>
> No, these were fine.
>
>
> Thanks,
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat

[-- Attachment #2: 0001-Importing-strtoimax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 7300 bytes --]

From 3aedaf9ce785f4d8c5db4941b6ec8881b2bd02b0 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 18:53:20 +0530
Subject: [PATCH 1/4] Importing strtoimax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   9 +++
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/strtoimax.c | 156 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 166 insertions(+)
 create mode 100644 newlib/libc/stdlib/strtoimax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 25c6e99fa..a59505d58 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -16,10 +16,15 @@
 #include <newlib.h>
 #include <sys/config.h>
 #include <sys/_intsup.h>
+#include "_ansi.h"
 #include <stdint.h>
 #define __need_wchar_t
 #include <stddef.h>
 
+#if __POSIX_VISIBLE >= 200809
+#include <xlocale.h>
+#endif
+
 #define __STRINGIFY(a) #a
 
 /* 8-bit types */
@@ -309,12 +314,16 @@ typedef struct {
   intmax_t	rem;
 } imaxdiv_t;
 
+struct _reent;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 extern intmax_t  imaxabs(intmax_t j);
 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
+extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict, int, locale_t);
+extern intmax_t  _strtoimax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 7aaa7fdfa..64a9d435a 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -59,6 +59,7 @@ GENERAL_SOURCES = \
 	sb_charsets.c	\
 	strtod.c	\
 	strtodg.c	\
+	strtoimax.c	\
 	strtol.c	\
 	strtorx.c	\
 	strtoul.c	\
diff --git a/newlib/libc/stdlib/strtoimax.c b/newlib/libc/stdlib/strtoimax.c
new file mode 100644
index 000000000..e7f0d329f
--- /dev/null
+++ b/newlib/libc/stdlib/strtoimax.c
@@ -0,0 +1,156 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtol.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoimax.c 251672 2013-06-13 00:19:30Z emaste $");
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a string to an intmax_t integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+/*
+ *Reentrant version of strtoimax.
+ */
+intmax_t
+_strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
+	     char ** __restrict endptr, int base, locale_t loc)
+{
+	const char *s = (const unsigned char *)nptr;
+	uintmax_t acc;
+	char c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	do {
+		c = *s++;
+	} while (isspace_l(c, loc));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for intmax_t is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
+	 *
+	 * Set 'any' if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? -(uintmax_t)INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? INTMAX_MIN : INTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
+intmax_t
+strtoimax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
+	    locale_t loc)
+{
+	return _strtoimax_l(_REENT, nptr, endptr, base, loc);
+}
+intmax_t
+strtoimax(const char* __restrict nptr, char** __restrict endptr, int base)
+{
+	return _strtoimax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}		
-- 
2.13.0


[-- Attachment #3: 0002-Importing-strtoumax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6135 bytes --]

From 5192a1f713cf392f32edffa6e956272e73279eec Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 18:57:47 +0530
Subject: [PATCH 2/4] Importing strtoumax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   2 +
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/strtoumax.c | 138 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 141 insertions(+)
 create mode 100644 newlib/libc/stdlib/strtoumax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index a59505d58..48e37cd5b 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -325,6 +325,8 @@ extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
 extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict, int, locale_t);
 extern intmax_t  _strtoimax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
+extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, int, locale_t);
+extern uintmax_t _strtoumax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 64a9d435a..1ccd2c488 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -63,6 +63,7 @@ GENERAL_SOURCES = \
 	strtol.c	\
 	strtorx.c	\
 	strtoul.c	\
+	strtoumax.c	\
 	utoa.c          \
 	wcstod.c	\
 	wcstol.c	\
diff --git a/newlib/libc/stdlib/strtoumax.c b/newlib/libc/stdlib/strtoumax.c
new file mode 100644
index 000000000..b2426a580
--- /dev/null
+++ b/newlib/libc/stdlib/strtoumax.c
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtoul.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoumax.c 251672 2013-06-13 00:19:30Z emaste $");
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a string to a uintmax_t integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+/*
+ *Reentrant version of strtoumax.
+ */
+uintmax_t
+_strtoumax_l(struct _reent *rptr, const char * __restrict nptr, 
+	     char ** __restrict endptr, int base, locale_t loc)
+{
+	const char *s = (const unsigned char *)nptr;
+	uintmax_t acc;
+	char c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (isspace_l(c, loc));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = UINTMAX_MAX / base;
+	cutlim = UINTMAX_MAX % base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = UINTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
+uintmax_t
+strtoumax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
+	    locale_t loc)
+{
+	return _strtoumax_l(_REENT, nptr, endptr, base, loc);
+}
+uintmax_t
+strtoumax(const char* __restrict nptr, char** __restrict endptr, int base)
+{
+	return _strtoumax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.13.0


[-- Attachment #4: 0003-Importing-wcstoimax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6298 bytes --]

From 21736fa9aa0b455adf935de65286ca00b5635331 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 19:00:16 +0530
Subject: [PATCH 3/4] Importing wcstoimax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   2 +
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/wcstoimax.c | 145 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 newlib/libc/stdlib/wcstoimax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 48e37cd5b..f7cd28027 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -328,6 +328,8 @@ extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
 extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, int, locale_t);
 extern uintmax_t _strtoumax_l(struct _reent *, const char *__restrict, char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
+extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
+extern intmax_t  _wcstoimax_l(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
 
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 1ccd2c488..b687c0fa2 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -66,6 +66,7 @@ GENERAL_SOURCES = \
 	strtoumax.c	\
 	utoa.c          \
 	wcstod.c	\
+	wcstoimax.c	\
 	wcstol.c	\
 	wcstoul.c	\
 	wcstombs.c	\
diff --git a/newlib/libc/stdlib/wcstoimax.c b/newlib/libc/stdlib/wcstoimax.c
new file mode 100644
index 000000000..dd350e6be
--- /dev/null
+++ b/newlib/libc/stdlib/wcstoimax.c
@@ -0,0 +1,145 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtol.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoimax.c,v 1.8 2002/09/06 11:23:59 tjr Exp ");
+#endif
+__FBSDID("$FreeBSD: head/lib/libc/locale/wcstoimax.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <reent.h>
+#include <stdint.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a wide character string to an intmax_t integer.
+ */
+
+/*
+ *Reentrant version of wcstoimax.
+ */
+intmax_t
+_wcstoimax_l(struct _reent *rptr, const wchar_t * __restrict nptr, 
+	     wchar_t ** __restrict endptr, int base, locale_t loc)
+{
+	const wchar_t *s = nptr;
+	uintmax_t acc;
+	wchar_t c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (iswspace_l(c, loc));
+	if (c == L'-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == L'+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == L'0' && (*s == L'x' || *s == L'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == L'0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = neg ? -(uintmax_t)INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+#ifdef notyet
+		if (iswdigit_l(c, loc))
+			c = digittoint_l(c, loc);
+		else
+#endif
+		if (c >= L'0' && c <= L'9')
+			c -= L'0';
+		else if (c >= L'A' && c <= L'Z')
+			c -= L'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= L'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? INTMAX_MIN : INTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
+intmax_t
+wcstoimax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+    	    int base, locale_t loc)
+{
+	return _wcstoimax_l(_REENT, nptr, endptr, base, loc);
+}
+intmax_t
+wcstoimax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
+{
+	return _wcstoimax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.13.0


[-- Attachment #5: 0004-Importing-wcstoumax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6201 bytes --]

From 10f50395c72d68570bf6f2d379b65a3cbe441c10 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Thu, 27 Jul 2017 19:02:32 +0530
Subject: [PATCH 4/4] Importing wcstoumax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   2 +
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/wcstoumax.c | 144 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 147 insertions(+)
 create mode 100644 newlib/libc/stdlib/wcstoumax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index f7cd28027..532976ad7 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -331,6 +331,8 @@ extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
 extern intmax_t  _wcstoimax_l(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
+extern uintmax_t wcstoumax_l(const wchar_t *__restrict, wchar_t **_restrict, int, locale_t);
+extern uintmax_t _wcstoumax_l(struct _reent *, const wchar_t *__restrict, wchar_t **__restrict, int, locale_t);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
 
 #ifdef __cplusplus
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index b687c0fa2..f9bab0b64 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -69,6 +69,7 @@ GENERAL_SOURCES = \
 	wcstoimax.c	\
 	wcstol.c	\
 	wcstoul.c	\
+	wcstoumax.c	\
 	wcstombs.c	\
 	wcstombs_r.c	\
 	wctomb.c	\
diff --git a/newlib/libc/stdlib/wcstoumax.c b/newlib/libc/stdlib/wcstoumax.c
new file mode 100644
index 000000000..dfa25bd0e
--- /dev/null
+++ b/newlib/libc/stdlib/wcstoumax.c
@@ -0,0 +1,144 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtoul.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoumax.c,v 1.8 2002/09/06 11:23:59 tjr Exp ");
+#endif
+__FBSDID("$FreeBSD: head/lib/libc/locale/wcstoumax.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a wide character string to a uintmax_t integer.
+ */
+
+/*
+ *Reentrant version of wcstoumax.
+ */
+uintmax_t
+_wcstoumax_l(struct _reent *rptr,const wchar_t * __restrict nptr, 
+	     wchar_t ** __restrict endptr, int base, locale_t loc)
+{
+	const wchar_t *s = nptr;
+	uintmax_t acc;
+	wchar_t c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (iswspace_l(c, loc));
+	if (c == L'-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == L'+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == L'0' && (*s == L'x' || *s == L'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == L'0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = UINTMAX_MAX / base;
+	cutlim = UINTMAX_MAX % base;
+	for ( ; ; c = *s++) {
+#ifdef notyet
+		if (iswdigit_l(c, loc))
+			c = digittoint_l(c, loc);
+		else
+#endif
+		if (c >= L'0' && c <= L'9')
+			c -= L'0';
+		else if (c >= L'A' && c <= L'Z')
+			c -= L'A' - 10;
+		else if (c >= L'a' && c <= L'z')
+			c -= L'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = UINTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
+uintmax_t
+wcstoumax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+    	    int base, locale_t loc)
+{
+	return _wcstoumax_l(_REENT, nptr, endptr, base, loc);
+}
+uintmax_t
+wcstoumax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
+{
+	return _wcstoumax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.13.0


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-27 14:00         ` Aditya Upadhyay
@ 2017-07-28 10:43           ` Corinna Vinschen
  2017-07-28 11:02             ` Aditya Upadhyay
  0 siblings, 1 reply; 21+ messages in thread
From: Corinna Vinschen @ 2017-07-28 10:43 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1275 bytes --]

On Jul 27 19:30, Aditya Upadhyay wrote:
> Hi,
> 
> I apologize for the inconvenience caused. Actually i am new to git and
> still learning commands. I am trying my best and want to assure you
> that i will be familiar with the git soon. I will try not to repeat
> the same mistakes again in future.
> I am attaching the fresh new patches for last 4 methods with all
> possible changes. I am requesting you to please review the patches.

Patches are fine and what we talked about, but I realized belatedly
that we have a problem with the inttypes.h header file:

Your patch includes xlocale.h only if __POSIX_VISIBLE >= 200809.
However, you declare the _l functions unconditionally.  This will
break builds which don't define _POSIX_SOURCE to the right value.

Additionally, these functions are BSD-only at the moment.  They are
neither in glibc nor in POSIX.

So, what we should do here is this:

* Include xlocale.h only if __BSD_VISIBLE.
* Declare the _l functions only if __BSD_VISIBLE, too.

It's your choice now:  Do you want to recreate the below patches
accordingly, or shall I aplly the patches as they are, and you create
a followup patch just fixing inttypes.h?


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-28 10:43           ` Corinna Vinschen
@ 2017-07-28 11:02             ` Aditya Upadhyay
  2017-07-28 11:40               ` Gedare Bloom
  2017-07-28 18:24               ` Joel Sherrill
  0 siblings, 2 replies; 21+ messages in thread
From: Aditya Upadhyay @ 2017-07-28 11:02 UTC (permalink / raw)
  To: newlib

Just give a little time. I am creating a new patch set that fix the
BSD_VISIBLE problem.

Thanks,
Aditya


On Fri, Jul 28, 2017 at 4:13 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Jul 27 19:30, Aditya Upadhyay wrote:
>> Hi,
>>
>> I apologize for the inconvenience caused. Actually i am new to git and
>> still learning commands. I am trying my best and want to assure you
>> that i will be familiar with the git soon. I will try not to repeat
>> the same mistakes again in future.
>> I am attaching the fresh new patches for last 4 methods with all
>> possible changes. I am requesting you to please review the patches.
>
> Patches are fine and what we talked about, but I realized belatedly
> that we have a problem with the inttypes.h header file:
>
> Your patch includes xlocale.h only if __POSIX_VISIBLE >= 200809.
> However, you declare the _l functions unconditionally.  This will
> break builds which don't define _POSIX_SOURCE to the right value.
>
> Additionally, these functions are BSD-only at the moment.  They are
> neither in glibc nor in POSIX.
>
> So, what we should do here is this:
>
> * Include xlocale.h only if __BSD_VISIBLE.
> * Declare the _l functions only if __BSD_VISIBLE, too.
>
> It's your choice now:  Do you want to recreate the below patches
> accordingly, or shall I aplly the patches as they are, and you create
> a followup patch just fixing inttypes.h?
>
>
> Thanks,
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-28 11:02             ` Aditya Upadhyay
@ 2017-07-28 11:40               ` Gedare Bloom
  2017-07-28 13:08                 ` Corinna Vinschen
  2017-07-28 18:24               ` Joel Sherrill
  1 sibling, 1 reply; 21+ messages in thread
From: Gedare Bloom @ 2017-07-28 11:40 UTC (permalink / raw)
  To: Aditya Upadhyay; +Cc: newlib

On Fri, Jul 28, 2017 at 7:02 AM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
> Just give a little time. I am creating a new patch set that fix the
> BSD_VISIBLE problem.
>
> Thanks,
> Aditya
>
>
> On Fri, Jul 28, 2017 at 4:13 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> On Jul 27 19:30, Aditya Upadhyay wrote:
>>> Hi,
>>>
>>> I apologize for the inconvenience caused. Actually i am new to git and
>>> still learning commands. I am trying my best and want to assure you
>>> that i will be familiar with the git soon. I will try not to repeat
>>> the same mistakes again in future.
>>> I am attaching the fresh new patches for last 4 methods with all
>>> possible changes. I am requesting you to please review the patches.
>>
>> Patches are fine and what we talked about, but I realized belatedly
>> that we have a problem with the inttypes.h header file:
>>
>> Your patch includes xlocale.h only if __POSIX_VISIBLE >= 200809.
>> However, you declare the _l functions unconditionally.  This will
>> break builds which don't define _POSIX_SOURCE to the right value.
>>
>> Additionally, these functions are BSD-only at the moment.  They are
>> neither in glibc nor in POSIX.
>>
>> So, what we should do here is this:
>>
>> * Include xlocale.h only if __BSD_VISIBLE.
>> * Declare the _l functions only if __BSD_VISIBLE, too.
>>
>> It's your choice now:  Do you want to recreate the below patches
>> accordingly, or shall I aplly the patches as they are, and you create
>> a followup patch just fixing inttypes.h?
>>
Corinna, good catch. I mentioned this issue to Joel but it dropped out
the bottom some how. Is it only (for example) the strtoimax_l() that
needs to be guarded, or also the _strtoimax_l? (I suspect only the
strtoimax_l, but want to be clear before the next round of patches
lands here.)

Aditya, Please do make the fixes to the VISIBLE, and also separate the
commits/patches that (1) add unmodified BSD source files from (2) the
commit that modifies the source file and adds it the build system.
Send a complete -v3 patch set with these changes. This set should
include all of your inttypes.h changes, since you will be changing the
first few patches (imaxabs, etc.) to separate the source import from
its use accordingly.

-Gedare

>>
>> Thanks,
>> Corinna
>>
>> --
>> Corinna Vinschen
>> Cygwin Maintainer
>> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-28 11:40               ` Gedare Bloom
@ 2017-07-28 13:08                 ` Corinna Vinschen
  2017-07-28 14:28                   ` Gedare Bloom
  0 siblings, 1 reply; 21+ messages in thread
From: Corinna Vinschen @ 2017-07-28 13:08 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 2176 bytes --]

On Jul 28 07:40, Gedare Bloom wrote:
> On Fri, Jul 28, 2017 at 7:02 AM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
> > Just give a little time. I am creating a new patch set that fix the
> > BSD_VISIBLE problem.
> >
> > Thanks,
> > Aditya
> >
> >
> > On Fri, Jul 28, 2017 at 4:13 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> >> On Jul 27 19:30, Aditya Upadhyay wrote:
> >>> Hi,
> >>>
> >>> I apologize for the inconvenience caused. Actually i am new to git and
> >>> still learning commands. I am trying my best and want to assure you
> >>> that i will be familiar with the git soon. I will try not to repeat
> >>> the same mistakes again in future.
> >>> I am attaching the fresh new patches for last 4 methods with all
> >>> possible changes. I am requesting you to please review the patches.
> >>
> >> Patches are fine and what we talked about, but I realized belatedly
> >> that we have a problem with the inttypes.h header file:
> >>
> >> Your patch includes xlocale.h only if __POSIX_VISIBLE >= 200809.
> >> However, you declare the _l functions unconditionally.  This will
> >> break builds which don't define _POSIX_SOURCE to the right value.
> >>
> >> Additionally, these functions are BSD-only at the moment.  They are
> >> neither in glibc nor in POSIX.
> >>
> >> So, what we should do here is this:
> >>
> >> * Include xlocale.h only if __BSD_VISIBLE.
> >> * Declare the _l functions only if __BSD_VISIBLE, too.
> >>
> >> It's your choice now:  Do you want to recreate the below patches
> >> accordingly, or shall I aplly the patches as they are, and you create
> >> a followup patch just fixing inttypes.h?
> >>
> Corinna, good catch. I mentioned this issue to Joel but it dropped out
> the bottom some how. Is it only (for example) the strtoimax_l() that
> needs to be guarded, or also the _strtoimax_l? (I suspect only the
> strtoimax_l, but want to be clear before the next round of patches
> lands here.)

The reentrant prototypes use locale_t, so they depend on including
xlocale.h, too.  It's a bit uncommon but the simplest solution.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-28 13:08                 ` Corinna Vinschen
@ 2017-07-28 14:28                   ` Gedare Bloom
  2017-07-28 18:29                     ` Corinna Vinschen
  0 siblings, 1 reply; 21+ messages in thread
From: Gedare Bloom @ 2017-07-28 14:28 UTC (permalink / raw)
  To: newlib; +Cc: aditya upadhyay

On Fri, Jul 28, 2017 at 9:08 AM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Jul 28 07:40, Gedare Bloom wrote:
>> On Fri, Jul 28, 2017 at 7:02 AM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
>> > Just give a little time. I am creating a new patch set that fix the
>> > BSD_VISIBLE problem.
>> >
>> > Thanks,
>> > Aditya
>> >
>> >
>> > On Fri, Jul 28, 2017 at 4:13 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> >> On Jul 27 19:30, Aditya Upadhyay wrote:
>> >>> Hi,
>> >>>
>> >>> I apologize for the inconvenience caused. Actually i am new to git and
>> >>> still learning commands. I am trying my best and want to assure you
>> >>> that i will be familiar with the git soon. I will try not to repeat
>> >>> the same mistakes again in future.
>> >>> I am attaching the fresh new patches for last 4 methods with all
>> >>> possible changes. I am requesting you to please review the patches.
>> >>
>> >> Patches are fine and what we talked about, but I realized belatedly
>> >> that we have a problem with the inttypes.h header file:
>> >>
>> >> Your patch includes xlocale.h only if __POSIX_VISIBLE >= 200809.
>> >> However, you declare the _l functions unconditionally.  This will
>> >> break builds which don't define _POSIX_SOURCE to the right value.
>> >>
>> >> Additionally, these functions are BSD-only at the moment.  They are
>> >> neither in glibc nor in POSIX.
>> >>
>> >> So, what we should do here is this:
>> >>
>> >> * Include xlocale.h only if __BSD_VISIBLE.
>> >> * Declare the _l functions only if __BSD_VISIBLE, too.
>> >>
>> >> It's your choice now:  Do you want to recreate the below patches
>> >> accordingly, or shall I aplly the patches as they are, and you create
>> >> a followup patch just fixing inttypes.h?
>> >>
>> Corinna, good catch. I mentioned this issue to Joel but it dropped out
>> the bottom some how. Is it only (for example) the strtoimax_l() that
>> needs to be guarded, or also the _strtoimax_l? (I suspect only the
>> strtoimax_l, but want to be clear before the next round of patches
>> lands here.)
>
> The reentrant prototypes use locale_t, so they depend on including
> xlocale.h, too.  It's a bit uncommon but the simplest solution.
>
Since the non-reentrant version (e.g., strtoimax) wraps the re-entrant
one, then there is no support unless locale is available. Would it be
better to have a non-reentrant, nonolocale implementation in tandem
with the reentrant one, or do we not worry about it and don't support
these functions at all unless the POSIX_SOURCE is set properly and
BSD_VISIBLE?

I don't think these guards are being done in other parts of the stdlib
code where this kind of pattern exists. I looked for some similar
examples that might be useful as a template but did not easily find
anything. Any suggestions are welcome?

I would guess there is value to have a non-reentrant implementation in
the basic case, and it should be a reasonably simple matter to
refactor the existing functions to pull out a common helper for the
re-entrant and non-reentrant, since apparently the only difference is
the use of errno in the two cases.

Aditya, this would look something like....

static inline intmax_t strtoimax_helper(const char* __restrict nptr,
char** __restrict endptr, int base) {
... the first "blob" of _strtoimax_l goes here
}

intmax_t _strtoimax_l(...) {
    x = strtoimax_helper(...);
    ... reent->_errno handling code here.
}

intmax_t strtoimax(...) {
#ifdef BSD_VISiBLE
    _strtoimax_l(...)
#else
    x = strtoimax_helper(...);
    ... errno handling here.
#endif
}

Corinna, would that seem correct and desirable for this situation? Or
do I miss something.

Gedare

>
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-28 11:02             ` Aditya Upadhyay
  2017-07-28 11:40               ` Gedare Bloom
@ 2017-07-28 18:24               ` Joel Sherrill
  1 sibling, 0 replies; 21+ messages in thread
From: Joel Sherrill @ 2017-07-28 18:24 UTC (permalink / raw)
  To: Aditya Upadhyay, newlib



On 7/28/2017 6:02 AM, Aditya Upadhyay wrote:
> Just give a little time. I am creating a new patch set that fix the
> BSD_VISIBLE problem.

And just to be clear the standards based guards go in the .h
file. Not in the C body.

For example, any BSD specific methods have their
prototype wrapped in __BSD_VISIBLE. See strings.h
for an example.

--joel

> 
> Thanks,
> Aditya
> 
> 
> On Fri, Jul 28, 2017 at 4:13 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> On Jul 27 19:30, Aditya Upadhyay wrote:
>>> Hi,
>>>
>>> I apologize for the inconvenience caused. Actually i am new to git and
>>> still learning commands. I am trying my best and want to assure you
>>> that i will be familiar with the git soon. I will try not to repeat
>>> the same mistakes again in future.
>>> I am attaching the fresh new patches for last 4 methods with all
>>> possible changes. I am requesting you to please review the patches.
>>
>> Patches are fine and what we talked about, but I realized belatedly
>> that we have a problem with the inttypes.h header file:
>>
>> Your patch includes xlocale.h only if __POSIX_VISIBLE >= 200809.
>> However, you declare the _l functions unconditionally.  This will
>> break builds which don't define _POSIX_SOURCE to the right value.
>>
>> Additionally, these functions are BSD-only at the moment.  They are
>> neither in glibc nor in POSIX.
>>
>> So, what we should do here is this:
>>
>> * Include xlocale.h only if __BSD_VISIBLE.
>> * Declare the _l functions only if __BSD_VISIBLE, too.
>>
>> It's your choice now:  Do you want to recreate the below patches
>> accordingly, or shall I aplly the patches as they are, and you create
>> a followup patch just fixing inttypes.h?
>>
>>
>> Thanks,
>> Corinna
>>
>> --
>> Corinna Vinschen
>> Cygwin Maintainer
>> Red Hat

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill@OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35806
Support Available                (256) 722-9985

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-28 14:28                   ` Gedare Bloom
@ 2017-07-28 18:29                     ` Corinna Vinschen
  2017-07-29 12:40                       ` Gedare Bloom
  0 siblings, 1 reply; 21+ messages in thread
From: Corinna Vinschen @ 2017-07-28 18:29 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1752 bytes --]

On Jul 28 10:28, Gedare Bloom wrote:
> On Fri, Jul 28, 2017 at 9:08 AM, Corinna Vinschen <vinschen@redhat.com> wrote:
> > On Jul 28 07:40, Gedare Bloom wrote:
> >> Corinna, good catch. I mentioned this issue to Joel but it dropped out
> >> the bottom some how. Is it only (for example) the strtoimax_l() that
> >> needs to be guarded, or also the _strtoimax_l? (I suspect only the
> >> strtoimax_l, but want to be clear before the next round of patches
> >> lands here.)
> >
> > The reentrant prototypes use locale_t, so they depend on including
> > xlocale.h, too.  It's a bit uncommon but the simplest solution.
> >
> Since the non-reentrant version (e.g., strtoimax) wraps the re-entrant
> one, then there is no support unless locale is available. Would it be
> better to have a non-reentrant, nonolocale implementation in tandem
> with the reentrant one, or do we not worry about it and don't support
> these functions at all unless the POSIX_SOURCE is set properly and
> BSD_VISIBLE?

Good catch on your side, I really had to look it up now.  Here's how it
is in the other, similar cases like strtol:

There are actually four functions:

  strtol
  strtol_l
  _strtol_r  
  _strtol_l

_strtol_l is the internal implementation and *static*.  _strtol_r
is the exported reentrant function and consequentially not having
the locale_t parameter.

So, why not just keep it at that for now with strtoimax, etc?  It only
requires minimal changes and nobody using the reentrant functions
actually asked for a reentrant function with thread-local locale
parameter yet :}

As a result, the guards for the exported reentrant functions are not
required.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-28 18:29                     ` Corinna Vinschen
@ 2017-07-29 12:40                       ` Gedare Bloom
  2017-07-29 13:57                         ` Aditya Upadhyay
  0 siblings, 1 reply; 21+ messages in thread
From: Gedare Bloom @ 2017-07-29 12:40 UTC (permalink / raw)
  To: newlib; +Cc: aditya upadhyay

On Fri, Jul 28, 2017 at 2:29 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Jul 28 10:28, Gedare Bloom wrote:
>> On Fri, Jul 28, 2017 at 9:08 AM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> > On Jul 28 07:40, Gedare Bloom wrote:
>> >> Corinna, good catch. I mentioned this issue to Joel but it dropped out
>> >> the bottom some how. Is it only (for example) the strtoimax_l() that
>> >> needs to be guarded, or also the _strtoimax_l? (I suspect only the
>> >> strtoimax_l, but want to be clear before the next round of patches
>> >> lands here.)
>> >
>> > The reentrant prototypes use locale_t, so they depend on including
>> > xlocale.h, too.  It's a bit uncommon but the simplest solution.
>> >
>> Since the non-reentrant version (e.g., strtoimax) wraps the re-entrant
>> one, then there is no support unless locale is available. Would it be
>> better to have a non-reentrant, nonolocale implementation in tandem
>> with the reentrant one, or do we not worry about it and don't support
>> these functions at all unless the POSIX_SOURCE is set properly and
>> BSD_VISIBLE?
>
> Good catch on your side, I really had to look it up now.  Here's how it
> is in the other, similar cases like strtol:
>
> There are actually four functions:
>
>   strtol
>   strtol_l
>   _strtol_r
>   _strtol_l
>
> _strtol_l is the internal implementation and *static*.  _strtol_r
> is the exported reentrant function and consequentially not having
> the locale_t parameter.
>
> So, why not just keep it at that for now with strtoimax, etc?  It only
> requires minimal changes and nobody using the reentrant functions
> actually asked for a reentrant function with thread-local locale
> parameter yet :}
>
> As a result, the guards for the exported reentrant functions are not
> required.
>
OK. Aditya please pursue this direction for implementation. It will
take a bit more refactoring to get it right.

>
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-29 12:40                       ` Gedare Bloom
@ 2017-07-29 13:57                         ` Aditya Upadhyay
  2017-07-30  8:46                           ` Aditya Upadhyay
  0 siblings, 1 reply; 21+ messages in thread
From: Aditya Upadhyay @ 2017-07-29 13:57 UTC (permalink / raw)
  To: Gedare Bloom, newlib, joel

Yes,
I am following the direction.

Regards.
Aditya Upadhyay

On Sat, Jul 29, 2017 at 6:10 PM, Gedare Bloom <gedare@rtems.org> wrote:
> On Fri, Jul 28, 2017 at 2:29 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> On Jul 28 10:28, Gedare Bloom wrote:
>>> On Fri, Jul 28, 2017 at 9:08 AM, Corinna Vinschen <vinschen@redhat.com> wrote:
>>> > On Jul 28 07:40, Gedare Bloom wrote:
>>> >> Corinna, good catch. I mentioned this issue to Joel but it dropped out
>>> >> the bottom some how. Is it only (for example) the strtoimax_l() that
>>> >> needs to be guarded, or also the _strtoimax_l? (I suspect only the
>>> >> strtoimax_l, but want to be clear before the next round of patches
>>> >> lands here.)
>>> >
>>> > The reentrant prototypes use locale_t, so they depend on including
>>> > xlocale.h, too.  It's a bit uncommon but the simplest solution.
>>> >
>>> Since the non-reentrant version (e.g., strtoimax) wraps the re-entrant
>>> one, then there is no support unless locale is available. Would it be
>>> better to have a non-reentrant, nonolocale implementation in tandem
>>> with the reentrant one, or do we not worry about it and don't support
>>> these functions at all unless the POSIX_SOURCE is set properly and
>>> BSD_VISIBLE?
>>
>> Good catch on your side, I really had to look it up now.  Here's how it
>> is in the other, similar cases like strtol:
>>
>> There are actually four functions:
>>
>>   strtol
>>   strtol_l
>>   _strtol_r
>>   _strtol_l
>>
>> _strtol_l is the internal implementation and *static*.  _strtol_r
>> is the exported reentrant function and consequentially not having
>> the locale_t parameter.
>>
>> So, why not just keep it at that for now with strtoimax, etc?  It only
>> requires minimal changes and nobody using the reentrant functions
>> actually asked for a reentrant function with thread-local locale
>> parameter yet :}
>>
>> As a result, the guards for the exported reentrant functions are not
>> required.
>>
> OK. Aditya please pursue this direction for implementation. It will
> take a bit more refactoring to get it right.
>
>>
>> Corinna
>>
>> --
>> Corinna Vinschen
>> Cygwin Maintainer
>> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-29 13:57                         ` Aditya Upadhyay
@ 2017-07-30  8:46                           ` Aditya Upadhyay
  2017-07-30 15:41                             ` Gedare Bloom
  0 siblings, 1 reply; 21+ messages in thread
From: Aditya Upadhyay @ 2017-07-30  8:46 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 2549 bytes --]

I have declared all *_l methods within __BSD_VISIBLE guard in
inttypes.h. I am attaching the patches for rest of the inttypes
methods. Please review the same. Also i have tried to make the line
length < 80  in inttypes.h file.

Thanks & Regards,
Aditya

On Sat, Jul 29, 2017 at 7:27 PM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
> Yes,
> I am following the direction.
>
> Regards.
> Aditya Upadhyay
>
> On Sat, Jul 29, 2017 at 6:10 PM, Gedare Bloom <gedare@rtems.org> wrote:
>> On Fri, Jul 28, 2017 at 2:29 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>>> On Jul 28 10:28, Gedare Bloom wrote:
>>>> On Fri, Jul 28, 2017 at 9:08 AM, Corinna Vinschen <vinschen@redhat.com> wrote:
>>>> > On Jul 28 07:40, Gedare Bloom wrote:
>>>> >> Corinna, good catch. I mentioned this issue to Joel but it dropped out
>>>> >> the bottom some how. Is it only (for example) the strtoimax_l() that
>>>> >> needs to be guarded, or also the _strtoimax_l? (I suspect only the
>>>> >> strtoimax_l, but want to be clear before the next round of patches
>>>> >> lands here.)
>>>> >
>>>> > The reentrant prototypes use locale_t, so they depend on including
>>>> > xlocale.h, too.  It's a bit uncommon but the simplest solution.
>>>> >
>>>> Since the non-reentrant version (e.g., strtoimax) wraps the re-entrant
>>>> one, then there is no support unless locale is available. Would it be
>>>> better to have a non-reentrant, nonolocale implementation in tandem
>>>> with the reentrant one, or do we not worry about it and don't support
>>>> these functions at all unless the POSIX_SOURCE is set properly and
>>>> BSD_VISIBLE?
>>>
>>> Good catch on your side, I really had to look it up now.  Here's how it
>>> is in the other, similar cases like strtol:
>>>
>>> There are actually four functions:
>>>
>>>   strtol
>>>   strtol_l
>>>   _strtol_r
>>>   _strtol_l
>>>
>>> _strtol_l is the internal implementation and *static*.  _strtol_r
>>> is the exported reentrant function and consequentially not having
>>> the locale_t parameter.
>>>
>>> So, why not just keep it at that for now with strtoimax, etc?  It only
>>> requires minimal changes and nobody using the reentrant functions
>>> actually asked for a reentrant function with thread-local locale
>>> parameter yet :}
>>>
>>> As a result, the guards for the exported reentrant functions are not
>>> required.
>>>
>> OK. Aditya please pursue this direction for implementation. It will
>> take a bit more refactoring to get it right.
>>
>>>
>>> Corinna
>>>
>>> --
>>> Corinna Vinschen
>>> Cygwin Maintainer
>>> Red Hat

[-- Attachment #2: 0001-Importing-strtoimax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 7405 bytes --]

From 4846bf131a1b8eed9f5f65da8688427710581d33 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Sun, 30 Jul 2017 13:54:31 +0530
Subject: [PATCH 1/4] Importing strtoimax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |  13 ++++
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/strtoimax.c | 156 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 170 insertions(+)
 create mode 100644 newlib/libc/stdlib/strtoimax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 25c6e99..fee9a1b 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -16,10 +16,15 @@
 #include <newlib.h>
 #include <sys/config.h>
 #include <sys/_intsup.h>
+#include "_ansi.h"
 #include <stdint.h>
 #define __need_wchar_t
 #include <stddef.h>
 
+#if __BSD_VISIBLE
+#include <xlocale.h>
+#endif
+
 #define __STRINGIFY(a) #a
 
 /* 8-bit types */
@@ -309,13 +314,21 @@ typedef struct {
   intmax_t	rem;
 } imaxdiv_t;
 
+struct _reent;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#if __BSD_VISIBLE
+extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict,
+			     int, locale_t);
+#endif
 extern intmax_t  imaxabs(intmax_t j);
 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
 extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
+extern intmax_t  _strtoimax_l(struct _reent *, const char *__restrict,
+			      char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 7aaa7fd..64a9d43 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -59,6 +59,7 @@ GENERAL_SOURCES = \
 	sb_charsets.c	\
 	strtod.c	\
 	strtodg.c	\
+	strtoimax.c	\
 	strtol.c	\
 	strtorx.c	\
 	strtoul.c	\
diff --git a/newlib/libc/stdlib/strtoimax.c b/newlib/libc/stdlib/strtoimax.c
new file mode 100644
index 0000000..e7f0d32
--- /dev/null
+++ b/newlib/libc/stdlib/strtoimax.c
@@ -0,0 +1,156 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtol.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoimax.c 251672 2013-06-13 00:19:30Z emaste $");
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a string to an intmax_t integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+/*
+ *Reentrant version of strtoimax.
+ */
+intmax_t
+_strtoimax_l(struct _reent *rptr, const char * __restrict nptr,
+	     char ** __restrict endptr, int base, locale_t loc)
+{
+	const char *s = (const unsigned char *)nptr;
+	uintmax_t acc;
+	char c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	do {
+		c = *s++;
+	} while (isspace_l(c, loc));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for intmax_t is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
+	 *
+	 * Set 'any' if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? -(uintmax_t)INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? INTMAX_MIN : INTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
+intmax_t
+strtoimax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
+	    locale_t loc)
+{
+	return _strtoimax_l(_REENT, nptr, endptr, base, loc);
+}
+intmax_t
+strtoimax(const char* __restrict nptr, char** __restrict endptr, int base)
+{
+	return _strtoimax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}		
-- 
2.7.4


[-- Attachment #3: 0002-Importing-strtoumax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6264 bytes --]

From 6dde71902bf969394a84deac4a59622b519c81b4 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Sun, 30 Jul 2017 13:59:02 +0530
Subject: [PATCH 2/4] Importing strtoumax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   4 ++
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/strtoumax.c | 138 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 143 insertions(+)
 create mode 100644 newlib/libc/stdlib/strtoumax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index fee9a1b..6d0138e 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -323,6 +323,8 @@ extern "C" {
 #if __BSD_VISIBLE
 extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict,
 			     int, locale_t);
+extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, 
+			     int, locale_t);
 #endif
 extern intmax_t  imaxabs(intmax_t j);
 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
@@ -330,6 +332,8 @@ extern intmax_t  strtoimax(const char *__restrict, char **__restrict, int);
 extern intmax_t  _strtoimax_l(struct _reent *, const char *__restrict,
 			      char **__restrict, int, locale_t);
 extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
+extern uintmax_t _strtoumax_l(struct _reent *, const char *__restrict, 
+			      char **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
 
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 64a9d43..1ccd2c4 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -63,6 +63,7 @@ GENERAL_SOURCES = \
 	strtol.c	\
 	strtorx.c	\
 	strtoul.c	\
+	strtoumax.c	\
 	utoa.c          \
 	wcstod.c	\
 	wcstol.c	\
diff --git a/newlib/libc/stdlib/strtoumax.c b/newlib/libc/stdlib/strtoumax.c
new file mode 100644
index 0000000..b2426a5
--- /dev/null
+++ b/newlib/libc/stdlib/strtoumax.c
@@ -0,0 +1,138 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtoul.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/lib/libc/stdlib/strtoumax.c 251672 2013-06-13 00:19:30Z emaste $");
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <inttypes.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a string to a uintmax_t integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+
+/*
+ *Reentrant version of strtoumax.
+ */
+uintmax_t
+_strtoumax_l(struct _reent *rptr, const char * __restrict nptr, 
+	     char ** __restrict endptr, int base, locale_t loc)
+{
+	const char *s = (const unsigned char *)nptr;
+	uintmax_t acc;
+	char c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (isspace_l(c, loc));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = UINTMAX_MAX / base;
+	cutlim = UINTMAX_MAX % base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = UINTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
+uintmax_t
+strtoumax_l(const char * __restrict nptr, char ** __restrict endptr, int base,
+	    locale_t loc)
+{
+	return _strtoumax_l(_REENT, nptr, endptr, base, loc);
+}
+uintmax_t
+strtoumax(const char* __restrict nptr, char** __restrict endptr, int base)
+{
+	return _strtoumax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.7.4


[-- Attachment #4: 0003-Importing-wcstoimax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6494 bytes --]

From 2dd021f157ed893fa83a3a7db7b2e4cc806f89bb Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Sun, 30 Jul 2017 14:02:22 +0530
Subject: [PATCH 3/4] Importing wcstoimax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   4 ++
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/wcstoimax.c | 145 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 newlib/libc/stdlib/wcstoimax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 6d0138e..286c061 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -325,6 +325,8 @@ extern intmax_t  strtoimax_l(const char *__restrict, char **_restrict,
 			     int, locale_t);
 extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict, 
 			     int, locale_t);
+extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict,
+			     int, locale_t);
 #endif
 extern intmax_t  imaxabs(intmax_t j);
 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
@@ -335,6 +337,8 @@ extern uintmax_t strtoumax(const char *__restrict, char **__restrict, int);
 extern uintmax_t _strtoumax_l(struct _reent *, const char *__restrict, 
 			      char **__restrict, int, locale_t);
 extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int);
+extern intmax_t  _wcstoimax_l(struct _reent *, const wchar_t *__restrict, 
+			      wchar_t **__restrict, int, locale_t);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
 
 #ifdef __cplusplus
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 1ccd2c4..b687c0f 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -66,6 +66,7 @@ GENERAL_SOURCES = \
 	strtoumax.c	\
 	utoa.c          \
 	wcstod.c	\
+	wcstoimax.c	\
 	wcstol.c	\
 	wcstoul.c	\
 	wcstombs.c	\
diff --git a/newlib/libc/stdlib/wcstoimax.c b/newlib/libc/stdlib/wcstoimax.c
new file mode 100644
index 0000000..dd350e6
--- /dev/null
+++ b/newlib/libc/stdlib/wcstoimax.c
@@ -0,0 +1,145 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtol.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoimax.c,v 1.8 2002/09/06 11:23:59 tjr Exp ");
+#endif
+__FBSDID("$FreeBSD: head/lib/libc/locale/wcstoimax.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <reent.h>
+#include <stdint.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a wide character string to an intmax_t integer.
+ */
+
+/*
+ *Reentrant version of wcstoimax.
+ */
+intmax_t
+_wcstoimax_l(struct _reent *rptr, const wchar_t * __restrict nptr, 
+	     wchar_t ** __restrict endptr, int base, locale_t loc)
+{
+	const wchar_t *s = nptr;
+	uintmax_t acc;
+	wchar_t c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (iswspace_l(c, loc));
+	if (c == L'-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == L'+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == L'0' && (*s == L'x' || *s == L'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == L'0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = neg ? -(uintmax_t)INTMAX_MIN : INTMAX_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+#ifdef notyet
+		if (iswdigit_l(c, loc))
+			c = digittoint_l(c, loc);
+		else
+#endif
+		if (c >= L'0' && c <= L'9')
+			c -= L'0';
+		else if (c >= L'A' && c <= L'Z')
+			c -= L'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= L'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? INTMAX_MIN : INTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
+intmax_t
+wcstoimax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+    	    int base, locale_t loc)
+{
+	return _wcstoimax_l(_REENT, nptr, endptr, base, loc);
+}
+intmax_t
+wcstoimax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
+{
+	return _wcstoimax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.7.4


[-- Attachment #5: 0004-Importing-wcstoumax-inttypes-method-from-FreeBSD.patch --]
[-- Type: text/x-patch, Size: 6379 bytes --]

From 3aa41b6e9904f9a0a11d2c25787e4228b0d461b1 Mon Sep 17 00:00:00 2001
From: Aditya Upadhyay <aadit0402@gmail.com>
Date: Sun, 30 Jul 2017 14:06:39 +0530
Subject: [PATCH 4/4] Importing wcstoumax inttypes method from FreeBSD.

---
 newlib/libc/include/inttypes.h |   4 ++
 newlib/libc/stdlib/Makefile.am |   1 +
 newlib/libc/stdlib/wcstoumax.c | 144 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 149 insertions(+)
 create mode 100644 newlib/libc/stdlib/wcstoumax.c

diff --git a/newlib/libc/include/inttypes.h b/newlib/libc/include/inttypes.h
index 286c061..a661a86 100644
--- a/newlib/libc/include/inttypes.h
+++ b/newlib/libc/include/inttypes.h
@@ -327,6 +327,8 @@ extern uintmax_t strtoumax_l(const char *__restrict, char **_restrict,
 			     int, locale_t);
 extern intmax_t  wcstoimax_l(const wchar_t *__restrict, wchar_t **_restrict,
 			     int, locale_t);
+extern uintmax_t wcstoumax_l(const wchar_t *__restrict, wchar_t **_restrict, 
+			     int, locale_t);
 #endif
 extern intmax_t  imaxabs(intmax_t j);
 extern imaxdiv_t imaxdiv(intmax_t numer, intmax_t denomer);
@@ -340,6 +342,8 @@ extern intmax_t  wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int)
 extern intmax_t  _wcstoimax_l(struct _reent *, const wchar_t *__restrict, 
 			      wchar_t **__restrict, int, locale_t);
 extern uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int);
+extern uintmax_t _wcstoumax_l(struct _reent *, const wchar_t *__restrict, 
+			      wchar_t **__restrict, int, locale_t);
 
 #ifdef __cplusplus
 }
diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index b687c0f..f9bab0b 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -69,6 +69,7 @@ GENERAL_SOURCES = \
 	wcstoimax.c	\
 	wcstol.c	\
 	wcstoul.c	\
+	wcstoumax.c	\
 	wcstombs.c	\
 	wcstombs_r.c	\
 	wctomb.c	\
diff --git a/newlib/libc/stdlib/wcstoumax.c b/newlib/libc/stdlib/wcstoumax.c
new file mode 100644
index 0000000..dfa25bd
--- /dev/null
+++ b/newlib/libc/stdlib/wcstoumax.c
@@ -0,0 +1,144 @@
+/*-
+ * Copyright (c) 1992, 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:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "from @(#)strtoul.c	8.1 (Berkeley) 6/4/93";
+#endif /* LIBC_SCCS and not lint */
+__FBSDID("FreeBSD: src/lib/libc/stdlib/strtoumax.c,v 1.8 2002/09/06 11:23:59 tjr Exp ");
+#endif
+__FBSDID("$FreeBSD: head/lib/libc/locale/wcstoumax.c 314436 2017-02-28 23:42:47Z imp $");
+
+#include <errno.h>
+#include <inttypes.h>
+#include <stdlib.h>
+#include <wchar.h>
+#include <wctype.h>
+#include <stdint.h>
+#include <reent.h>
+#include "../locale/setlocale.h"
+
+/*
+ * Convert a wide character string to a uintmax_t integer.
+ */
+
+/*
+ *Reentrant version of wcstoumax.
+ */
+uintmax_t
+_wcstoumax_l(struct _reent *rptr,const wchar_t * __restrict nptr, 
+	     wchar_t ** __restrict endptr, int base, locale_t loc)
+{
+	const wchar_t *s = nptr;
+	uintmax_t acc;
+	wchar_t c;
+	uintmax_t cutoff;
+	int neg = 0, any, cutlim;
+	
+	/*
+	 * See strtoimax for comments as to the logic used.
+	 */
+	do {
+		c = *s++;
+	} while (iswspace_l(c, loc));
+	if (c == L'-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == L'+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == L'0' && (*s == L'x' || *s == L'X')) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == L'0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = UINTMAX_MAX / base;
+	cutlim = UINTMAX_MAX % base;
+	for ( ; ; c = *s++) {
+#ifdef notyet
+		if (iswdigit_l(c, loc))
+			c = digittoint_l(c, loc);
+		else
+#endif
+		if (c >= L'0' && c <= L'9')
+			c -= L'0';
+		else if (c >= L'A' && c <= L'Z')
+			c -= L'A' - 10;
+		else if (c >= L'a' && c <= L'z')
+			c -= L'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = UINTMAX_MAX;
+		rptr->_errno = ERANGE;
+	} else if (!any) {
+noconv:
+		rptr->_errno = EINVAL;
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (wchar_t *)(any ? s - 1 : nptr);
+	return (acc);
+}
+uintmax_t
+wcstoumax_l(const wchar_t * __restrict nptr, wchar_t ** __restrict endptr,
+    	    int base, locale_t loc)
+{
+	return _wcstoumax_l(_REENT, nptr, endptr, base, loc);
+}
+uintmax_t
+wcstoumax(const wchar_t* __restrict nptr, wchar_t** __restrict endptr, int base)
+{
+	return _wcstoumax_l(_REENT, nptr, endptr, base, __get_current_locale());
+}
-- 
2.7.4


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-30  8:46                           ` Aditya Upadhyay
@ 2017-07-30 15:41                             ` Gedare Bloom
  2017-07-31 10:08                               ` Corinna Vinschen
  0 siblings, 1 reply; 21+ messages in thread
From: Gedare Bloom @ 2017-07-30 15:41 UTC (permalink / raw)
  To: Aditya Upadhyay; +Cc: newlib

On Sun, Jul 30, 2017 at 4:45 AM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
> I have declared all *_l methods within __BSD_VISIBLE guard in
> inttypes.h. I am attaching the patches for rest of the inttypes
> methods. Please review the same. Also i have tried to make the line
> length < 80  in inttypes.h file.
>
> Thanks & Regards,
> Aditya
>
> On Sat, Jul 29, 2017 at 7:27 PM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
>> Yes,
>> I am following the direction.
>>
>> Regards.
>> Aditya Upadhyay
>>
>> On Sat, Jul 29, 2017 at 6:10 PM, Gedare Bloom <gedare@rtems.org> wrote:
>>> On Fri, Jul 28, 2017 at 2:29 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>>>> On Jul 28 10:28, Gedare Bloom wrote:
>>>>> On Fri, Jul 28, 2017 at 9:08 AM, Corinna Vinschen <vinschen@redhat.com> wrote:
>>>>> > On Jul 28 07:40, Gedare Bloom wrote:
>>>>> >> Corinna, good catch. I mentioned this issue to Joel but it dropped out
>>>>> >> the bottom some how. Is it only (for example) the strtoimax_l() that
>>>>> >> needs to be guarded, or also the _strtoimax_l? (I suspect only the
>>>>> >> strtoimax_l, but want to be clear before the next round of patches
>>>>> >> lands here.)
>>>>> >
>>>>> > The reentrant prototypes use locale_t, so they depend on including
>>>>> > xlocale.h, too.  It's a bit uncommon but the simplest solution.
>>>>> >
>>>>> Since the non-reentrant version (e.g., strtoimax) wraps the re-entrant
>>>>> one, then there is no support unless locale is available. Would it be
>>>>> better to have a non-reentrant, nonolocale implementation in tandem
>>>>> with the reentrant one, or do we not worry about it and don't support
>>>>> these functions at all unless the POSIX_SOURCE is set properly and
>>>>> BSD_VISIBLE?
>>>>
>>>> Good catch on your side, I really had to look it up now.  Here's how it
>>>> is in the other, similar cases like strtol:
>>>>
>>>> There are actually four functions:
>>>>
>>>>   strtol
>>>>   strtol_l
>>>>   _strtol_r
>>>>   _strtol_l
>>>>
>>>> _strtol_l is the internal implementation and *static*.  _strtol_r
>>>> is the exported reentrant function and consequentially not having
>>>> the locale_t parameter.
>>>>
>>>> So, why not just keep it at that for now with strtoimax, etc?  It only
>>>> requires minimal changes and nobody using the reentrant functions
>>>> actually asked for a reentrant function with thread-local locale
>>>> parameter yet :}
>>>>
All,

It looks like to me like the str*_l functions in stdlib.h currently
are actually being guarded by __GNU_VISIBLE rather than __BSD_VISIBLE.
You should see if these locale functions from BSD are in glibc, if so
then I believe GNU_VISIBLE is the more appropriate guard? Someone more
knowledgeable on the feature test macros might comment.

Aditya,

I think you have not quite followed this direction closely enough. You
should have some function like _strtoimax_r as the exported re-entrant
version without locale, and a static function _strtoimax_l for the
private implementation. Again, see strtol.c for an example. Please
rework each of your commits following that example as a pattern.  If
no one answers my question above, you should re-ask it as a separate
email in a few days, or ping this.

-Gedare

>>>> As a result, the guards for the exported reentrant functions are not
>>>> required.
>>>>
>>> OK. Aditya please pursue this direction for implementation. It will
>>> take a bit more refactoring to get it right.
>>>
>>>>
>>>> Corinna
>>>>
>>>> --
>>>> Corinna Vinschen
>>>> Cygwin Maintainer
>>>> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-30 15:41                             ` Gedare Bloom
@ 2017-07-31 10:08                               ` Corinna Vinschen
  2017-08-01  8:31                                 ` Aditya Upadhyay
  0 siblings, 1 reply; 21+ messages in thread
From: Corinna Vinschen @ 2017-07-31 10:08 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

On Jul 30 11:41, Gedare Bloom wrote:
> All,
> 
> It looks like to me like the str*_l functions in stdlib.h currently
> are actually being guarded by __GNU_VISIBLE rather than __BSD_VISIBLE.
> You should see if these locale functions from BSD are in glibc, if so
> then I believe GNU_VISIBLE is the more appropriate guard? Someone more
> knowledgeable on the feature test macros might comment.

Yes, the functions are guarded with __GNU_VISIBLE, just as in glibc.
No, the {str,wcs}to{i,u}max_l functions are not defined in glibc at all,
so they should be __BSD_VISIBLE.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-07-31 10:08                               ` Corinna Vinschen
@ 2017-08-01  8:31                                 ` Aditya Upadhyay
  2017-08-01 12:10                                   ` Gedare Bloom
  0 siblings, 1 reply; 21+ messages in thread
From: Aditya Upadhyay @ 2017-08-01  8:31 UTC (permalink / raw)
  To: newlib

On Mon, Jul 31, 2017 at 3:38 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
> On Jul 30 11:41, Gedare Bloom wrote:
>> All,
>>
>> It looks like to me like the str*_l functions in stdlib.h currently
>> are actually being guarded by __GNU_VISIBLE rather than __BSD_VISIBLE.
>> You should see if these locale functions from BSD are in glibc, if so
>> then I believe GNU_VISIBLE is the more appropriate guard? Someone more
>> knowledgeable on the feature test macros might comment.
>
> Yes, the functions are guarded with __GNU_VISIBLE, just as in glibc.
> No, the {str,wcs}to{i,u}max_l functions are not defined in glibc at all,
> so they should be __BSD_VISIBLE.
>
Do i need to modify the code of *max methods according to strtol
method or is this ok for master ?
>
> Corinna
>
> --
> Corinna Vinschen
> Cygwin Maintainer
> Red Hat

^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: Importing inttypes methods
  2017-08-01  8:31                                 ` Aditya Upadhyay
@ 2017-08-01 12:10                                   ` Gedare Bloom
  0 siblings, 0 replies; 21+ messages in thread
From: Gedare Bloom @ 2017-08-01 12:10 UTC (permalink / raw)
  To: Aditya Upadhyay; +Cc: newlib

On Tue, Aug 1, 2017 at 4:30 AM, Aditya Upadhyay <aadit0402@gmail.com> wrote:
> On Mon, Jul 31, 2017 at 3:38 PM, Corinna Vinschen <vinschen@redhat.com> wrote:
>> On Jul 30 11:41, Gedare Bloom wrote:
>>> All,
>>>
>>> It looks like to me like the str*_l functions in stdlib.h currently
>>> are actually being guarded by __GNU_VISIBLE rather than __BSD_VISIBLE.
>>> You should see if these locale functions from BSD are in glibc, if so
>>> then I believe GNU_VISIBLE is the more appropriate guard? Someone more
>>> knowledgeable on the feature test macros might comment.
>>
>> Yes, the functions are guarded with __GNU_VISIBLE, just as in glibc.
>> No, the {str,wcs}to{i,u}max_l functions are not defined in glibc at all,
>> so they should be __BSD_VISIBLE.
>>
> Do i need to modify the code of *max methods according to strtol
> method or is this ok for master ?
Aditya,

I don't quite understand your question. To rephrase Corinna's answer:
You should keep using the __BSD_VISIBLE as you have done, since the
new functions you port are not in glibc. You still need to rewrite
your code to take into consideration my other comments.

Gedare

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2017-08-01 12:10 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-25 19:51 Importing inttypes methods Aditya Upadhyay
2017-07-26 11:08 ` Corinna Vinschen
2017-07-26 12:02   ` Sebastian Huber
2017-07-26 12:02   ` Aditya Upadhyay
2017-07-26 21:24     ` Aditya Upadhyay
2017-07-27 12:32       ` Corinna Vinschen
2017-07-27 14:00         ` Aditya Upadhyay
2017-07-28 10:43           ` Corinna Vinschen
2017-07-28 11:02             ` Aditya Upadhyay
2017-07-28 11:40               ` Gedare Bloom
2017-07-28 13:08                 ` Corinna Vinschen
2017-07-28 14:28                   ` Gedare Bloom
2017-07-28 18:29                     ` Corinna Vinschen
2017-07-29 12:40                       ` Gedare Bloom
2017-07-29 13:57                         ` Aditya Upadhyay
2017-07-30  8:46                           ` Aditya Upadhyay
2017-07-30 15:41                             ` Gedare Bloom
2017-07-31 10:08                               ` Corinna Vinschen
2017-08-01  8:31                                 ` Aditya Upadhyay
2017-08-01 12:10                                   ` Gedare Bloom
2017-07-28 18:24               ` Joel Sherrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).