[PATCH] implementation of inttypes.h and test related to its methods

aadit0402 aadit0402 at gmail.com
Thu Jun 1 23:35:37 UTC 2017


---
 cpukit/Makefile.am                           |   1 +
 cpukit/configure.ac                          |   1 +
 cpukit/inttypes/Makefile.am                  |  14 +++
 cpukit/inttypes/imaxabs.c                    |  40 +++++++++
 cpukit/inttypes/imaxdiv.c                    |  50 +++++++++++
 cpukit/inttypes/strtoimax.c                  | 117 +++++++++++++++++++++++++
 cpukit/inttypes/strtoumax.c                  | 116 +++++++++++++++++++++++++
 cpukit/inttypes/wcstoimax.c                  | 125 +++++++++++++++++++++++++++
 cpukit/inttypes/wcstoumax.c                  | 119 +++++++++++++++++++++++++
 testsuites/samples/Makefile.am               |   1 +
 testsuites/samples/configure.ac              |   1 +
 testsuites/samples/psxinttypes01/Makefile.am |  22 +++++
 testsuites/samples/psxinttypes01/init.c      |  69 +++++++++++++++
 testsuites/samples/psxinttypes01/psxid01.doc |  35 ++++++++
 testsuites/samples/psxinttypes01/psxid01.scn |  38 ++++++++
 15 files changed, 749 insertions(+)
 create mode 100644 cpukit/inttypes/Makefile.am
 create mode 100644 cpukit/inttypes/imaxabs.c
 create mode 100644 cpukit/inttypes/imaxdiv.c
 create mode 100644 cpukit/inttypes/strtoimax.c
 create mode 100644 cpukit/inttypes/strtoumax.c
 create mode 100644 cpukit/inttypes/wcstoimax.c
 create mode 100644 cpukit/inttypes/wcstoumax.c
 create mode 100644 testsuites/samples/psxinttypes01/Makefile.am
 create mode 100644 testsuites/samples/psxinttypes01/init.c
 create mode 100644 testsuites/samples/psxinttypes01/psxid01.doc
 create mode 100644 testsuites/samples/psxinttypes01/psxid01.scn

diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index ae5ed9b..045017e 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -7,6 +7,7 @@ include $(top_srcdir)/automake/multilib.am
 _SUBDIRS = . score rtems sapi posix
 _SUBDIRS += dev
 _SUBDIRS += dtc/libfdt
+_SUBDIRS += inttypes
 _SUBDIRS += libcrypt
 _SUBDIRS += libcsupport libblock libfs
 _SUBDIRS += libdrvmgr
diff --git a/cpukit/configure.ac b/cpukit/configure.ac
index b0aa9a0..ad0865b 100644
--- a/cpukit/configure.ac
+++ b/cpukit/configure.ac
@@ -461,6 +461,7 @@ score/cpu/sparc64/Makefile
 score/cpu/v850/Makefile
 score/cpu/no_cpu/Makefile
 posix/Makefile
+inttypes/Makefile
 libblock/Makefile
 libdrvmgr/Makefile
 libfs/Makefile
diff --git a/cpukit/inttypes/Makefile.am b/cpukit/inttypes/Makefile.am
new file mode 100644
index 0000000..c90b872
--- /dev/null
+++ b/cpukit/inttypes/Makefile.am
@@ -0,0 +1,14 @@
+include $(top_srcdir)/automake/multilib.am
+include $(top_srcdir)/automake/compile.am
+
+
+noinst_LIBRARIES = libinttypes.a
+
+libinttypes_a_SOURCES = imaxdiv.c imaxabs.c strtoimax.c strtoumax.c wcstoimax.c wcstoumax.c
+
+libinttypes_a_CPPFLAGS = $(AM_CPPFLAGS) 
+
+
+#include $(srcdir)/preinstall.am
+include $(top_srcdir)/automake/subdirs.am
+include $(top_srcdir)/automake/local.am
diff --git a/cpukit/inttypes/imaxabs.c b/cpukit/inttypes/imaxabs.c
new file mode 100644
index 0000000..525e9c0
--- /dev/null
+++ b/cpukit/inttypes/imaxabs.c
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2001 Mike Barcroft <mike at 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.
+ */
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+#include <stdio.h>
+
+#include <rtems/inttypes.h>
+
+
+intmax_t
+imaxabs(intmax_t j)
+{
+  return (j < 0 ? -j : j);
+}
diff --git a/cpukit/inttypes/imaxdiv.c b/cpukit/inttypes/imaxdiv.c
new file mode 100644
index 0000000..7992caa
--- /dev/null
+++ b/cpukit/inttypes/imaxdiv.c
@@ -0,0 +1,50 @@
+/*-
+ * Copyright (c) 2001 Mike Barcroft <mike at 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.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <stdint.h>
+
+#include <rtems/inttypes.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);
+}
diff --git a/cpukit/inttypes/strtoimax.c b/cpukit/inttypes/strtoimax.c
new file mode 100644
index 0000000..9971f73
--- /dev/null
+++ b/cpukit/inttypes/strtoimax.c
@@ -0,0 +1,117 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+    This source code was extracted from the Q8 package created and
+    placed in the PUBLIC DOMAIN by Doug Gwyn <gwyn at arl.mil>
+    last edit:	1999/11/05	gwyn at arl.mil
+
+	Implements subclause 7.8.2 of ISO/IEC 9899:1999 (E).
+
+	This particular implementation requires the matching <inttypes.h>.
+	It also assumes that character codes for A..Z and a..z are in
+	contiguous ascending order; this is true for ASCII but not EBCDIC.
+*/
+#include <stdlib.h>
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+/* Helper macros */
+
+/* convert digit character to number, in any base */
+#define ToNumber(c)	(isdigit(c) ? (c) - '0' : \
+			 isupper(c) ? (c) - 'A' + 10 : \
+			 islower(c) ? (c) - 'a' + 10 : \
+			 -1		/* "invalid" flag */ \
+			)
+/* validate converted digit character for specific base */
+#define valid(n, b)	((n) >= 0 && (n) < (b))
+
+intmax_t
+strtoimax(nptr, endptr, base)
+	register const char * __restrict__	nptr;
+	char ** __restrict__			endptr;
+	register int				base;
+	{
+	register uintmax_t	accum;	/* accumulates converted value */
+	register int		n;	/* numeral from digit character */
+	int			minus;	/* set iff minus sign seen */
+	int			toobig;	/* set iff value overflows */
+	if ( endptr != NULL )
+		*endptr = (char *)nptr;	/* in case no conversion's performed */
+
+	if ( base < 0 || base == 1 || base > 36 )
+		{
+		errno = EDOM;
+		return 0;		/* unspecified behavior */
+		}
+
+	/* skip initial, possibly empty sequence of white-space characters */
+
+	while ( isspace(*nptr) )
+		++nptr;
+
+	/* process subject sequence: */
+
+	/* optional sign */
+	if ( (minus = *nptr == '-') || *nptr == '+' )
+		++nptr;
+
+	if ( base == 0 ) {
+		if ( *nptr == '0' ) {
+			if ( nptr[1] == 'X' || nptr[1] == 'x' )
+				base = 16;
+			else
+				base = 8;
+		}
+		else
+				base = 10;
+	}
+	/* optional "0x" or "0X" for base 16 */
+
+	if ( base == 16 && *nptr == '0' && (nptr[1] == 'X' || nptr[1] == 'x') )
+		nptr += 2;		/* skip past this prefix */
+
+	/* check whether there is at least one valid digit */
+
+	n = ToNumber(*nptr);
+	++nptr;
+
+	if ( !valid(n, base) )
+		return 0;		/* subject seq. not of expected form */
+
+	accum = n;
+
+	for ( toobig = 0; n = ToNumber(*nptr), valid(n, base); ++nptr )
+		if ( accum > (uintmax_t)(INTMAX_MAX / base + 2) ) /* major wrap-around */
+			toobig = 1;	/* but keep scanning */
+		else
+			accum = base * accum + n;
+
+	if ( endptr != NULL )
+		*endptr = (char *)nptr;	/* points to first not-valid-digit */
+
+	if ( minus )
+		{
+		if ( accum > (uintmax_t)INTMAX_MAX + 1 )
+			toobig = 1;
+		}
+	else
+	if ( accum > (uintmax_t)INTMAX_MAX )
+		toobig = 1;
+
+	if ( toobig )
+		{
+		errno = ERANGE;
+		return minus ? INTMAX_MIN : INTMAX_MAX;
+		}
+	else
+		return (intmax_t)(minus ? -accum : accum);
+	}
+
+long long __attribute__ ((alias ("strtoimax")))
+strtoll (const char* __restrict__ nptr, char ** __restrict__ endptr, int base);
+
diff --git a/cpukit/inttypes/strtoumax.c b/cpukit/inttypes/strtoumax.c
new file mode 100644
index 0000000..3612a23
--- /dev/null
+++ b/cpukit/inttypes/strtoumax.c
@@ -0,0 +1,116 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+    This source code was extracted from the Q8 package created and
+    placed in the PUBLIC DOMAIN by Doug Gwyn <gwyn at arl.mil>
+    last edit:	1999/11/05	gwyn at arl.mil
+
+	Implements subclause 7.8.2 of ISO/IEC 9899:1999 (E).
+
+	This particular implementation requires the matching <inttypes.h>.
+	It also assumes that character codes for A..Z and a..z are in
+	contiguous ascending order; this is true for ASCII but not EBCDIC.
+*/
+#include <stdlib.h>
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+/* Helper macros */
+
+/* convert digit character to number, in any base */
+#define ToNumber(c)	(isdigit(c) ? (c) - '0' : \
+			 isupper(c) ? (c) - 'A' + 10 : \
+			 islower(c) ? (c) - 'a' + 10 : \
+			 -1		/* "invalid" flag */ \
+			)
+/* validate converted digit character for specific base */
+#define valid(n, b)	((n) >= 0 && (n) < (b))
+
+uintmax_t
+strtoumax(nptr, endptr, base)
+	register const char * __restrict__	nptr;
+	char ** __restrict__			endptr;
+	register int				base;
+	{
+	register uintmax_t	accum;	/* accumulates converted value */
+	register uintmax_t	next;	/* for computing next value of accum */
+	register int		n;	/* numeral from digit character */
+	int			minus;	/* set iff minus sign seen (yes!) */
+	int			toobig;	/* set iff value overflows */
+
+	if ( endptr != NULL )
+		*endptr = (char *)nptr;	/* in case no conversion's performed */
+
+	if ( base < 0 || base == 1 || base > 36 )
+		{
+		errno = EDOM;
+		return 0;		/* unspecified behavior */
+		}
+
+	/* skip initial, possibly empty sequence of white-space characters */
+
+	while ( isspace(*nptr) )
+		++nptr;
+
+	/* process subject sequence: */
+
+	/* optional sign (yes!) */
+
+	if ( (minus = *nptr == '-') || *nptr == '+' )
+		++nptr;
+
+	if ( base == 0 )
+        {
+		if ( *nptr == '0' )
+            {
+			if ( nptr[1] == 'X' || nptr[1] == 'x' )
+				base = 16;
+			else
+				base = 8;
+		    }
+		else
+				base = 10;
+		}
+
+    /* optional "0x" or "0X" for base 16 */
+    
+	if ( base == 16 && *nptr == '0' && (nptr[1] == 'X' || nptr[1] == 'x') )
+		nptr += 2;		/* skip past this prefix */
+
+	/* check whether there is at least one valid digit */
+
+	n = ToNumber(*nptr);
+	++nptr;
+
+	if ( !valid(n, base) )
+		return 0;		/* subject seq. not of expected form */
+
+	accum = n;
+
+	for ( toobig = 0; n = ToNumber(*nptr), valid(n, base); ++nptr )
+		if ( accum > UINTMAX_MAX / base + 1	/* major wrap-around */
+		  || (next = base * accum + n) < accum	/* minor wrap-around */
+		   )
+			toobig = 1;	/* but keep scanning */
+		else
+			accum = next;
+
+	if ( endptr != NULL )
+		*endptr = (char *)nptr;	/* points to first not-valid-digit */
+
+	if ( toobig )
+		{
+		errno = ERANGE;
+		return UINTMAX_MAX;
+		}
+	else
+		return minus ? -accum : accum;	/* (yes!) */
+	}
+
+unsigned long long __attribute__ ((alias ("strtoumax")))
+strtoull (const char* __restrict__ nptr, char ** __restrict__ endptr, int base);
+
diff --git a/cpukit/inttypes/wcstoimax.c b/cpukit/inttypes/wcstoimax.c
new file mode 100644
index 0000000..24667bd
--- /dev/null
+++ b/cpukit/inttypes/wcstoimax.c
@@ -0,0 +1,125 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+    This source code was extracted from the Q8 package created and
+    placed in the PUBLIC DOMAIN by Doug Gwyn <gwyn at arl.mil>
+
+    last edit:	1999/11/05	gwyn at arl.mil
+
+	Implements subclause 7.8.2 of ISO/IEC 9899:1999 (E).
+
+	This particular implementation requires the matching <inttypes.h>.
+	It also assumes that character codes for A..Z and a..z are in
+	contiguous ascending order; this is true for ASCII but not EBCDIC.
+*/
+
+#include <wchar.h>
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+/* convert digit wide character to number, in any base */
+
+#define ToWNumber(c)	(iswdigit(c) ? (c) - L'0' : \
+			 iswupper(c) ? (c) - L'A' + 10 : \
+			 iswlower(c) ? (c) - L'a' + 10 : \
+			 -1		/* "invalid" flag */ \
+			)
+
+/* validate converted digit character for specific base */
+#define valid(n, b)	((n) >= 0 && (n) < (b))
+
+intmax_t
+wcstoimax(nptr, endptr, base)
+	register const wchar_t * __restrict__	nptr;
+	wchar_t ** __restrict__				endptr;
+	register int					base;
+	{
+	register uintmax_t	accum;	/* accumulates converted value */
+	register int		n;	/* numeral from digit character */
+	int			minus;	/* set iff minus sign seen */
+	int			toobig;	/* set iff value overflows */
+	printf("In wcstoimax function \n");
+	if ( endptr != NULL )
+		*endptr = (wchar_t *)nptr;	/* in case no conv performed */
+
+	if ( base < 0 || base == 1 || base > 36 )
+		{
+		errno = EDOM;
+		return 0;		/* unspecified behavior */
+		}
+
+	/* skip initial, possibly empty sequence of white-space w.characters */
+
+	while ( iswspace(*nptr) )
+		++nptr;
+
+	/* process subject sequence: */
+
+	/* optional sign */
+
+	if ( (minus = *nptr == L'-') || *nptr == L'+' )
+		++nptr;
+
+	if ( base == 0 )
+        {
+		if ( *nptr == L'0' )
+            {
+			if ( nptr[1] == L'X' || nptr[1] == L'x' )
+				base = 16;
+			else
+				base = 8;
+            }
+		else
+				base = 10;
+        }
+	/* optional "0x" or "0X" for base 16 */
+
+	if ( base == 16 && *nptr == L'0'
+	  && (nptr[1] == L'X' || nptr[1] == L'x')
+	   )
+		nptr += 2;		/* skip past this prefix */
+
+	/* check whether there is at least one valid digit */
+
+	n = ToWNumber(*nptr);
+	++nptr;
+
+	if ( !valid(n, base) )
+		return 0;		/* subject seq. not of expected form */
+
+	accum = n;
+
+	for ( toobig = 0; n = ToWNumber(*nptr), valid(n, base); ++nptr )
+		if ( accum > (uintmax_t)(INTMAX_MAX / base + 2) ) /* major wrap-around */
+			toobig = 1;	/* but keep scanning */
+		else
+			accum = base * accum + n;
+
+	if ( endptr != NULL )
+		*endptr = (wchar_t *)nptr;	/* -> first not-valid-digit */
+
+	if ( minus )
+		{
+		if ( accum > (uintmax_t)INTMAX_MAX + 1 )
+			toobig = 1;
+		}
+	else
+	if ( accum > (uintmax_t)INTMAX_MAX )
+		toobig = 1;
+
+	if ( toobig )
+		{
+		errno = ERANGE;
+		return minus ? INTMAX_MIN : INTMAX_MAX;
+		}
+	else
+		return (intmax_t)(minus ? -accum : accum);
+	}
+
+long long __attribute__ ((alias ("wcstoimax")))
+wcstoll (const wchar_t* __restrict__ nptr, wchar_t ** __restrict__ endptr, int base);
+
diff --git a/cpukit/inttypes/wcstoumax.c b/cpukit/inttypes/wcstoumax.c
new file mode 100644
index 0000000..a796a62
--- /dev/null
+++ b/cpukit/inttypes/wcstoumax.c
@@ -0,0 +1,119 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+/*
+    This source code was extracted from the Q8 package created and
+    placed in the PUBLIC DOMAIN by Doug Gwyn <gwyn at arl.mil>
+
+    last edit:	1999/11/05	gwyn at arl.mil
+
+	Implements subclause 7.8.2 of ISO/IEC 9899:1999 (E).
+
+	This particular implementation requires the matching <inttypes.h>.
+	It also assumes that character codes for A..Z and a..z are in
+	contiguous ascending order; this is true for ASCII but not EBCDIC.
+*/
+
+#include <wchar.h>
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+/* convert digit wide character to number, in any base */
+
+#define ToWNumber(c)	(iswdigit(c) ? (c) - L'0' : \
+			 iswupper(c) ? (c) - L'A' + 10 : \
+			 iswlower(c) ? (c) - L'a' + 10 : \
+			 -1		/* "invalid" flag */ \
+			)
+
+/* validate converted digit character for specific base */
+#define valid(n, b)	((n) >= 0 && (n) < (b))
+
+uintmax_t
+wcstoumax(nptr, endptr, base)
+	register const wchar_t * __restrict__	nptr;
+	wchar_t ** __restrict__				endptr;
+	register int					base;
+	{
+	register uintmax_t	accum;	/* accumulates converted value */
+	register uintmax_t	next;	/* for computing next value of accum */
+	register int		n;	/* numeral from digit character */
+	int			minus;	/* set iff minus sign seen (yes!) */
+	int			toobig;	/* set iff value overflows */
+	
+	if ( endptr != NULL )
+		*endptr = (wchar_t *)nptr;	/* in case no conv performed */
+
+	if ( base < 0 || base == 1 || base > 36 )
+		{
+		errno = EDOM;
+		return 0;		/* unspecified behavior */
+		}
+
+	/* skip initial, possibly empty sequence of white-space w.characters */
+
+	while ( iswspace(*nptr) )
+		++nptr;
+
+	/* process subject sequence: */
+
+	/* optional sign */
+
+	if ( (minus = *nptr == L'-') || *nptr == L'+' )
+		++nptr;
+
+	if ( base == 0 )
+        {
+		if ( *nptr == L'0' )
+            {
+			if ( nptr[1] == L'X' || nptr[1] == L'x' )
+				base = 16;
+			else
+				base = 8;
+            }
+		else
+				base = 10;
+        }
+	/* optional "0x" or "0X" for base 16 */
+	
+	if ( base == 16 && *nptr == L'0'
+	  && (nptr[1] == L'X' || nptr[1] == L'x')
+	   )
+		nptr += 2;		/* skip past this prefix */
+
+	/* check whether there is at least one valid digit */
+
+	n = ToWNumber(*nptr);
+	++nptr;
+
+	if ( !valid(n, base) )
+		return 0;		/* subject seq. not of expected form */
+
+	accum = n;
+
+	for ( toobig = 0; n = ToWNumber(*nptr), valid(n, base); ++nptr )
+		if ( accum > UINTMAX_MAX / base + 1	/* major wrap-around */
+		  || (next = base * accum + n) < accum	/* minor wrap-around */
+		   )
+			toobig = 1;	/* but keep scanning */
+		else
+			accum = next;
+
+	if ( endptr != NULL )
+		*endptr = (wchar_t *)nptr;	/* -> first not-valid-digit */
+
+	if ( toobig )
+		{
+		errno = ERANGE;
+		return UINTMAX_MAX;
+		}
+	else
+		return minus ? -accum : accum;	/* (yes!) */
+	}
+
+unsigned long long __attribute__ ((alias ("wcstoumax")))
+wcstoull (const wchar_t* __restrict__ nptr, wchar_t ** __restrict__ endptr, int base);
+
diff --git a/testsuites/samples/Makefile.am b/testsuites/samples/Makefile.am
index 85e89a5..fd16f57 100644
--- a/testsuites/samples/Makefile.am
+++ b/testsuites/samples/Makefile.am
@@ -8,6 +8,7 @@ _SUBDIRS += hello
 _SUBDIRS += minimum
 _SUBDIRS += nsecs
 _SUBDIRS += paranoia
+_SUBDIRS += psxinttypes01
 _SUBDIRS += ticker
 _SUBDIRS += unlimited
 
diff --git a/testsuites/samples/configure.ac b/testsuites/samples/configure.ac
index ffe1bad..3d0ef5b 100644
--- a/testsuites/samples/configure.ac
+++ b/testsuites/samples/configure.ac
@@ -74,6 +74,7 @@ minimum/Makefile
 nsecs/Makefile
 paranoia/Makefile
 pppd/Makefile
+psxinttypes01/Makefile
 ticker/Makefile
 unlimited/Makefile
 ])
diff --git a/testsuites/samples/psxinttypes01/Makefile.am b/testsuites/samples/psxinttypes01/Makefile.am
new file mode 100644
index 0000000..56a85aa
--- /dev/null
+++ b/testsuites/samples/psxinttypes01/Makefile.am
@@ -0,0 +1,22 @@
+AUTOMAKE_OPTIONS = subdir-objects
+rtems_tests_PROGRAMS = psxinttypes01
+psxinttypes01_SOURCES = init.c 
+
+##dist_rtems_tests_DATA = psxinttypes01.scn
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+
+AM_CPPFLAGS += -I$(top_srcdir)/include
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(psxinttypes01_OBJECTS) $(psxinttypes01_LDADD)
+LINK_LIBS = $(psxinttypes01_LDLIBS)  /home/aditya/development/b-sparc/sparc-rtems4.12/c/erc32/cpukit/inttypes/libinttypes.a
+
+psxinttypes01$(EXEEXT): $(psxinttypes01_OBJECTS) $(psxinttypes01_DEPENDENCIES)
+	@rm -f psxinttypes01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/samples/psxinttypes01/init.c b/testsuites/samples/psxinttypes01/init.c
new file mode 100644
index 0000000..bda6879
--- /dev/null
+++ b/testsuites/samples/psxinttypes01/init.c
@@ -0,0 +1,69 @@
+/*This is the test for inttypes library. It covers these functions : 
+imaxabs(), imaxdiv(), strtoimax(), strtoumax(), wcstoimax(), wcstoumax().
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/inttypes.h>
+#include <rtems/printer.h>
+#include <rtems/test.h>
+#include <stdlib.h>
+
+/* forward declarations to avoid warnings */
+rtems_task Init(rtems_task_argument argument);
+const char rtems_test_name[] = "PSXINTTYPE 01";
+rtems_printer rtems_test_printer;
+/*
+ * RTEMS Startup Task
+ */
+rtems_task Init(
+  rtems_task_argument ignored
+)
+{
+  rtems_print_printer_printf(&rtems_test_printer);
+  rtems_test_begin();
+  char* endptr;
+  uintmax_t j,k;                                       
+  int base = 10;                                     
+  char *nptr;
+  wchar_t *nptr1, *endptr1;
+  intmax_t m;
+  nptr1 = L"10110134932";                               
+  nptr = "20690239864abc";
+  m = wcstoimax(nptr1, &endptr1, base);                                     
+  printf("string = %s\n", nptr);                     
+  j = strtoumax(nptr, &endptr, base); 
+  printf("wcstoimax = %jd\n", m);
+  k = wcstoumax(nptr1, &endptr1, base);
+  printf("wcstoumax = %ju\n", k);                       
+  printf("strtoumax = %ju (base %d)\n", j, base);
+  printf("Stopped scan at %s\n\n", endptr);     
+  imaxdiv_t retrival = imaxdiv(27, 4);
+  printf(" Strtoimax values \n");
+  printf("%jd\n", strtoimax(" -123junk",&endptr,10)); /* base 10                    */
+  printf("%jd\n", strtoimax("11111111",&endptr,2));   /* base 2                     */
+  printf("%jd\n", strtoimax("XyZ",&endptr,36));       /* base 36                    */
+  printf("%jd\n", strtoimax("010",&endptr,0));        /* octal auto-detection       */
+  printf("%jd\n", strtoimax("10",&endptr,0));         /* decimal auto-detection     */
+  printf("%jd\n", strtoimax("0x10",&endptr,0));       /* hexadecimal auto-detection */
+  printf( "imaxabs_value = %jd\n", imaxabs(-1234));
+  printf("strtoimax value = %jd\n", strtoimax("11111111",&endptr,2));
+  printf( "imax div value = %jd\n", retrival.rem); 
+  rtems_test_end();
+  exit( 0 );
+}
+
+/* NOTICE: the clock driver is explicitly disabled */
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS            1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+    
diff --git a/testsuites/samples/psxinttypes01/psxid01.doc b/testsuites/samples/psxinttypes01/psxid01.doc
new file mode 100644
index 0000000..a8ce42a
--- /dev/null
+++ b/testsuites/samples/psxinttypes01/psxid01.doc
@@ -0,0 +1,35 @@
+#  COPYRIGHT (c) 1989-2010.
+#  On-Line Applications Research Corporation (OAR).
+#
+#  The license and distribution terms for this file may be
+#  found in the file LICENSE in this distribution or at
+#  http://www.rtems.org/license/LICENSE.
+#
+
+This file describes the directives and concepts tested by this test set.
+
+test set name:  psxid01
+
+directives:
+
+  getegid
+  getgid
+  setgid
+  setpgid
+  geteuid
+  getuid
+  setuid
+  geteuid
+  getuid
+  getpid
+  __getpid
+  getppid
+  setsid
+  getpgrp
+  getgroups
+  getlogin
+  getlogin_r
+
+concepts:
+
++ Fully exercise the above listed methods
diff --git a/testsuites/samples/psxinttypes01/psxid01.scn b/testsuites/samples/psxinttypes01/psxid01.scn
new file mode 100644
index 0000000..e0ea2a0
--- /dev/null
+++ b/testsuites/samples/psxinttypes01/psxid01.scn
@@ -0,0 +1,38 @@
+*** BEGIN OF TEST PSXID 1 ***
+getegid = 0
+getgid = 0
+setgid(5)
+getegid = 0
+getgid = 5
+setegid(5)
+getegid = 5
+getgid = 5
+setgid(0)
+setegid(0)
+setpgid(getpid(), 10) - ENOSYS
+
+geteuid = 0
+getuid = 0
+setuid(5)
+geteuid = 0
+getuid = 5
+seteuid(5)
+geteuid = 5
+getuid = 5
+seteuid(0)
+setuid(0)
+
+getpid = 1
+__getpid = 1
+getppid = 0
+setsid - EPERM
+getpgrp - return local node - OK
+getpgrp returned 1
+
+setuid(5)
+getlogin() -- ()
+setuid(0)
+getlogin() -- (root)
+getlogin_r(NULL, LOGIN_NAME_MAX) -- EFAULT
+getlogin_r(buffer, 0) -- ERANGE
+*** END OF TEST PSXID 1 ***
-- 
2.7.4



More information about the devel mailing list