[PATCH] Implementation of inttypes.h and test related to its methods.
Aditya Upadhyay
aadit0402 at gmail.com
Tue Jun 6 09:52:09 UTC 2017
---
cpukit/inttypes/imaxabs.c | 47 +++----
cpukit/inttypes/imaxdiv.c | 51 ++++----
cpukit/inttypes/strtoimax.c | 131 ++++++++++++--------
cpukit/inttypes/strtoumax.c | 111 +++++++++--------
cpukit/inttypes/wcstoimax.c | 137 ++++++++++++---------
cpukit/inttypes/wcstoumax.c | 99 +++++++++------
testsuites/psxtests/Makefile.am | 1 +
testsuites/psxtests/configure.ac | 1 +
testsuites/psxtests/psxinttypes01/Makefile.am | 22 ++++
testsuites/psxtests/psxinttypes01/init.c | 107 ++++++++++++++++
.../psxtests/psxinttypes01/psxinttypes01.scn | 9 ++
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 ------
17 files changed, 470 insertions(+), 412 deletions(-)
create mode 100644 testsuites/psxtests/psxinttypes01/Makefile.am
create mode 100644 testsuites/psxtests/psxinttypes01/init.c
create mode 100644 testsuites/psxtests/psxinttypes01/psxinttypes01.scn
delete mode 100644 testsuites/samples/psxinttypes01/Makefile.am
delete mode 100644 testsuites/samples/psxinttypes01/init.c
delete mode 100644 testsuites/samples/psxinttypes01/psxid01.doc
delete mode 100644 testsuites/samples/psxinttypes01/psxid01.scn
diff --git a/cpukit/inttypes/imaxabs.c b/cpukit/inttypes/imaxabs.c
index c1d25be..fe9331f 100644
--- a/cpukit/inttypes/imaxabs.c
+++ b/cpukit/inttypes/imaxabs.c
@@ -1,33 +1,36 @@
/*-
- * Copyright (c) 2001 Mike Barcroft <mike at FreeBSD.org>
- * All rights reserved.
+ * 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.
+ * 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.
+ * 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> /*intmax_t data type defined here */
+/* intmax_t data type defined here */
+
+#include <stdint.h>
#include <stdio.h>
#include <rtems/inttypes.h>
diff --git a/cpukit/inttypes/imaxdiv.c b/cpukit/inttypes/imaxdiv.c
index 97db900..765481e 100644
--- a/cpukit/inttypes/imaxdiv.c
+++ b/cpukit/inttypes/imaxdiv.c
@@ -1,50 +1,53 @@
/*-
- * Copyright (c) 2001 Mike Barcroft <mike at FreeBSD.org>
- * All rights reserved.
+ * 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.
+ * 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.
+ * 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> /* intmax_t data type defined here */
+/* intmax_t data type defined here */
+
+#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
index e7382dd..092a2a9 100644
--- a/cpukit/inttypes/strtoimax.c
+++ b/cpukit/inttypes/strtoimax.c
@@ -1,19 +1,21 @@
/**
- * 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 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 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.
+ */
- 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>
@@ -22,12 +24,14 @@
/* 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 */ \
+ -1 /* "invalid" flag */ \
)
/* validate converted digit character for specific base */
+
#define valid(n, b) ((n) >= 0 && (n) < (b))
intmax_t
@@ -37,85 +41,104 @@ strtoimax(
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 )
- {
+ register uintmax_t accum;
+ register int n;
+ int minus;
+ int toobig;
+
+ /* in case no conversion's performed */
+
+ if (endptr != NULL)
+ *endptr = (char *)nptr;
+
+ /* unspecified behavior */
+
+ if (base < 0 || base == 1 || base > 36){
errno = EDOM;
- return 0; /* unspecified behavior */
+ return 0;
}
/* skip initial, possibly empty sequence of white-space characters */
- while ( isspace(*nptr) )
+ while (isspace(*nptr))
++nptr;
/* process subject sequence: */
/* optional sign */
- if ( (minus = *nptr == '-') || *nptr == '+' )
+
+ if ((minus = *nptr == '-') || *nptr == '+')
++nptr;
- if ( base == 0 ) {
- if ( *nptr == '0' ) {
- if ( nptr[1] == 'X' || nptr[1] == 'x' )
+ if (base == 0) {
+ if (*nptr == '0') {
+ if (nptr[1] == 'X' || nptr[1] == 'x'){
base = 16;
- else
- base = 8;
+ }else{
+ base = 8;
}
- else
- base = 10;
+ }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 */
+ /* skip past this prefix */
+
+ if (base == 16 && *nptr == '0' && (nptr[1] == 'X' || nptr[1] == 'x'))
+ nptr += 2;
/* check whether there is at least one valid digit */
n = ToNumber(*nptr);
++nptr;
+
+ /* subject seq. not of expected form */
- if ( !valid(n, base) )
- return 0; /* subject seq. not of expected form */
+ if (!valid(n, base))
+ return 0;
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 */
+ for (toobig = 0; n = ToNumber(*nptr), valid(n, base); ++nptr)
+
+ /* major wrap-around */
+
+ if (accum > (uintmax_t)(INTMAX_MAX / base + 2))
+
+ /* but keep scanning */
+
+ toobig = 1;
else
accum = base * accum + n;
- if ( endptr != NULL )
- *endptr = (char *)nptr; /* points to first not-valid-digit */
+ /* points to first not-valid-digit */
+
+ if (endptr != NULL)
+ *endptr = (char *)nptr;
- if ( minus )
- {
- if ( accum > (uintmax_t)INTMAX_MAX + 1 )
+ if (minus){
+ if (accum > (uintmax_t)INTMAX_MAX + 1)
toobig = 1;
- }
+ }
else
- if ( accum > (uintmax_t)INTMAX_MAX )
+ 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);
+ 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);
+const char* __restrict__ nptr,
+char ** __restrict__ endptr, int base );
diff --git a/cpukit/inttypes/strtoumax.c b/cpukit/inttypes/strtoumax.c
index 70d15ee..48c818b 100644
--- a/cpukit/inttypes/strtoumax.c
+++ b/cpukit/inttypes/strtoumax.c
@@ -1,19 +1,21 @@
/**
- * 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 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.
+/*
+ * 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>
@@ -22,12 +24,14 @@
/* 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
@@ -37,19 +41,22 @@ strtoumax(
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 */
+ register uintmax_t accum;
+ register uintmax_t next;
+ register int n;
+ int minus;
+ int toobig;
+
+ /* in case no conversion's performed */
if ( endptr != NULL )
- *endptr = (char *)nptr; /* in case no conversion's performed */
+ *endptr = (char *)nptr;
+
+ /* unspecified behavior */
- if ( base < 0 || base == 1 || base > 36 )
- {
+ if ( base < 0 || base == 1 || base > 36 ){
errno = EDOM;
- return 0; /* unspecified behavior */
+ return 0;
}
/* skip initial, possibly empty sequence of white-space characters */
@@ -61,55 +68,63 @@ strtoumax(
/* optional sign (yes!) */
- if ( (minus = *nptr == '-') || *nptr == '+' )
+ if ((minus = *nptr == '-') || *nptr == '+')
++nptr;
- if ( base == 0 )
- {
- if ( *nptr == '0' )
- {
- if ( nptr[1] == 'X' || nptr[1] == 'x' )
- base = 16;
- else
- base = 8;
- }
+ if (base == 0){
+ if (*nptr == '0'){
+ if (nptr[1] == 'X' || nptr[1] == 'x')
+ base = 16;
else
- base = 10;
+ 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 */
+ if (base == 16 && *nptr == '0' && (nptr[1] == 'X' || nptr[1] == 'x'))
+
+ /* skip past this prefix */
+
+ nptr += 2;
/* check whether there is at least one valid digit */
n = ToNumber(*nptr);
++nptr;
+
+ /* subject seq. not of expected form */
if ( !valid(n, base) )
- return 0; /* subject seq. not of expected form */
+ return 0;
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 */
+
+ /* major wrap-around and minor wrap-around */
+
+ if (accum > UINTMAX_MAX / base + 1 || (next = base * accum + n) < accum)
+
+ /* but keep scanning */
+
+ toobig = 1;
else
accum = next;
- if ( endptr != NULL )
- *endptr = (char *)nptr; /* points to first not-valid-digit */
+ /* points to first not-valid-digit */
- if ( toobig )
- {
- errno = ERANGE;
- return UINTMAX_MAX;
- }
- else
- return minus ? -accum : accum; /* (yes!) */
+ if (endptr != NULL)
+ *endptr = (char *)nptr;
+
+ if (toobig){
+ errno = ERANGE;
+ return UINTMAX_MAX;
+ }
+ else
+ return minus ? -accum : accum; /* (yes!) */
}
unsigned long long
diff --git a/cpukit/inttypes/wcstoimax.c b/cpukit/inttypes/wcstoimax.c
index 2ba3547..4ec0e91 100644
--- a/cpukit/inttypes/wcstoimax.c
+++ b/cpukit/inttypes/wcstoimax.c
@@ -1,19 +1,17 @@
/**
- * 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 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.
+/*
+ * 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>
@@ -30,6 +28,7 @@
)
/* validate converted digit character for specific base */
+
#define valid(n, b) ((n) >= 0 && (n) < (b))
intmax_t
@@ -38,38 +37,50 @@ wcstoimax(
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 )
- {
+{
+ /* accumulates converted value */
+
+ register uintmax_t accum;
+
+ /* numeral from digit character */
+
+ register int n;
+
+ /* set iff minus sign seen */
+
+ int minus;
+
+ /* set iff value overflows */
+
+ int toobig;
+
+ /* in case no conv performed */
+
+ if (endptr != NULL)
+ *endptr = (wchar_t *)nptr;
+
+ /* unspecified behavior */
+
+ if (base < 0 || base == 1 || base > 36){
errno = EDOM;
- return 0; /* unspecified behavior */
+ return 0;
}
/* skip initial, possibly empty sequence of white-space w.characters */
- while ( iswspace(*nptr) )
+ while (iswspace(*nptr))
++nptr;
/* process subject sequence: */
/* optional sign */
- if ( (minus = *nptr == L'-') || *nptr == L'+' )
+ if ((minus = *nptr == L'-') || *nptr == L'+')
++nptr;
- if ( base == 0 )
- {
- if ( *nptr == L'0' )
- {
- if ( nptr[1] == L'X' || nptr[1] == L'x' )
+ if (base == 0){
+ if (*nptr == L'0'){
+ if (nptr[1] == L'X' || nptr[1] == L'x')
base = 16;
else
base = 8;
@@ -77,48 +88,58 @@ wcstoimax(
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 */
+ if ( base == 16 && *nptr == L'0' && (nptr[1] == L'X' || nptr[1] == L'x'))
+
+ /* skip past this prefix */
+
+ nptr += 2;
/* 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 */
+ /* subject seq. not of expected form */
+
+ if (!valid(n, base))
+ return 0;
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 */
+ for (toobig = 0; n = ToWNumber(*nptr), valid(n, base); ++nptr)
+
+ /* major wrap-around */
+
+ if (accum > (uintmax_t)(INTMAX_MAX / base + 2))
+
+ /* but keep scanning */
+
+ toobig = 1;
else
accum = base * accum + n;
- if ( endptr != NULL )
- *endptr = (wchar_t *)nptr; /* -> first not-valid-digit */
+ /* -> 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 (endptr != NULL)
+ *endptr = (wchar_t *)nptr;
- if ( toobig )
- {
- errno = ERANGE;
- return minus ? INTMAX_MIN : INTMAX_MAX;
- }
- else
- return (intmax_t)(minus ? -accum : accum);
+ 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
diff --git a/cpukit/inttypes/wcstoumax.c b/cpukit/inttypes/wcstoumax.c
index 36ea56b..890126e 100644
--- a/cpukit/inttypes/wcstoumax.c
+++ b/cpukit/inttypes/wcstoumax.c
@@ -3,17 +3,15 @@
* 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.
+/*
+ * 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>
@@ -39,39 +37,50 @@ wcstoumax(
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 */
+ /* accumulates converted value */
+
+ register uintmax_t accum, next;
+
+ /* numeral from digit character */
+
+ register int n;
+
+ /* set iff minus sign seen */
+
+ int minus;
+
+ /* set iff value overflows */
+
+ int toobig;
- if ( endptr != NULL )
- *endptr = (wchar_t *)nptr; /* in case no conv performed */
+ /* in case no conv performed */
+
+ if (endptr != NULL)
+ *endptr = (wchar_t *)nptr;
+
+ /* unspecified behavior */
- if ( base < 0 || base == 1 || base > 36 )
- {
+ if (base < 0 || base == 1 || base > 36){
errno = EDOM;
- return 0; /* unspecified behavior */
+ return 0;
}
/* skip initial, possibly empty sequence of white-space w.characters */
- while ( iswspace(*nptr) )
+ while (iswspace(*nptr))
++nptr;
/* process subject sequence: */
/* optional sign */
- if ( (minus = *nptr == L'-') || *nptr == L'+' )
+ if ((minus = *nptr == L'-') || *nptr == L'+')
++nptr;
- if ( base == 0 )
- {
- if ( *nptr == L'0' )
- {
- if ( nptr[1] == L'X' || nptr[1] == L'x' )
+ if (base == 0){
+ if (*nptr == L'0'){
+ if (nptr[1] == L'X' || nptr[1] == L'x')
base = 16;
else
base = 8;
@@ -79,33 +88,43 @@ wcstoumax(
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 */
+ if ( base == 16 && *nptr == L'0' && (nptr[1] == L'X' || nptr[1] == L'x'))
+
+ /* skip past this prefix */
+
+ nptr += 2;
/* 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 */
+ /* subject seq. not of expected form */
+
+ if (!valid(n, base))
+ return 0;
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 */
+ for (toobig = 0; n = ToWNumber(*nptr), valid(n, base); ++nptr)
+
+ /* minor wrap-around */
+
+ if (accum > UINTMAX_MAX / base + 1 || (next = base * accum + n) < accum)
+
+ /* but keep scanning */
+
+ toobig = 1;
else
accum = next;
-
+
+ /* -> first not-valid-digit */
+
if ( endptr != NULL )
- *endptr = (wchar_t *)nptr; /* -> first not-valid-digit */
+ *endptr = (wchar_t *)nptr;
if ( toobig )
{
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 7bcea46..8b246d8 100644
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -49,6 +49,7 @@ _SUBDIRS += psxfatal01
_SUBDIRS += psxfatal02
_SUBDIRS += psxgetattrnp01
endif
+_SUBDIRS += psxinttypes01
if HAS_POSIX
if HAS_CPLUSPLUS
_SUBDIRS += psxglobalcon01
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index 1de1312..4db7916 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -162,6 +162,7 @@ psxid01/Makefile
psximfs01/Makefile
psximfs02/Makefile
psxintrcritical01/Makefile
+psxinttypes01/Makefile
psxitimer/Makefile
psxkey01/Makefile
psxkey02/Makefile
diff --git a/testsuites/psxtests/psxinttypes01/Makefile.am b/testsuites/psxtests/psxinttypes01/Makefile.am
new file mode 100644
index 0000000..517648c
--- /dev/null
+++ b/testsuites/psxtests/psxinttypes01/Makefile.am
@@ -0,0 +1,22 @@
+
+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/psxtests/psxinttypes01/init.c b/testsuites/psxtests/psxinttypes01/init.c
new file mode 100644
index 0000000..770b04d
--- /dev/null
+++ b/testsuites/psxtests/psxinttypes01/init.c
@@ -0,0 +1,107 @@
+/*
+ * 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>
+#include <tmacros.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, *nptr;
+
+ uintmax_t j, k;
+
+ int base = 10;
+ rtems_test_assert (base == EINVAL)
+
+ wchar_t *nptr1, *endptr1;
+
+ intmax_t m, n;
+
+ nptr1 = L"10110134932";
+ nptr = "20690239864abc";
+
+ /* Test for wcstoimax */
+
+ m = wcstoimax(nptr1, &endptr1, base);
+ rtems_test_assert (m == ERANGE)
+ rtems_test_assert (m == EINVAL)
+
+ printf( "wcstoimax = %jd\n", m );
+
+ /* test for strtoumax */
+
+ j = strtoumax (nptr, &endptr, base);
+ rtems_test_assert (j == ERANGE);
+ rtems_test_assert (j == EINVAL)
+
+ printf( "strtoumax = %ju ( base %d )\n", j, base );
+ printf( "Stopped scan at %s\n\n", endptr );
+
+ /*test for wcstoumax */
+
+ k = wcstoumax (nptr1, &endptr1, base);
+ rtems_test_assert (k == ERANGE)
+ rtems_test_assert (k == EINVAL)
+
+ printf( "wcstoumax = %ju\n", k );
+
+ /*Test for imaxdiv */
+
+ imaxdiv_t retrival = imaxdiv ( 27, 4 );
+ printf( "imax div value = %jd\n", retrival.rem );
+
+ /*Test for imaxabs */
+
+ printf( "imaxabs_value = %jd\n", imaxabs (-1234));
+
+ /*Test for strtoimax */
+
+ n = strtoimax ("11111111", &endptr, 2)
+ rtems_test_assert (n == ERANGE)
+ rtems_test_assert (n == EINVAL)
+
+ printf( "strtoimax value = %jd\n", n);
+
+
+ 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/psxtests/psxinttypes01/psxinttypes01.scn b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn
new file mode 100644
index 0000000..1625fa7
--- /dev/null
+++ b/testsuites/psxtests/psxinttypes01/psxinttypes01.scn
@@ -0,0 +1,9 @@
+*** BEGIN OF TEST PSXINTTYPE 01 ***
+wcstoimax = 10110134932
+strtoumax = 20690239864 (base 10)
+Stopped scan at abc
+wcstoumax = 10110134932
+imax div value = 3
+imaxabs_value = 1234
+strtoimax value = 255
+*** END OF TEST PSXINTTYPE 01 ***
diff --git a/testsuites/samples/Makefile.am b/testsuites/samples/Makefile.am
index fd16f57..85e89a5 100644
--- a/testsuites/samples/Makefile.am
+++ b/testsuites/samples/Makefile.am
@@ -8,7 +8,6 @@ _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 3d0ef5b..ffe1bad 100644
--- a/testsuites/samples/configure.ac
+++ b/testsuites/samples/configure.ac
@@ -74,7 +74,6 @@ 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
deleted file mode 100644
index 56a85aa..0000000
--- a/testsuites/samples/psxinttypes01/Makefile.am
+++ /dev/null
@@ -1,22 +0,0 @@
-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
deleted file mode 100644
index bda6879..0000000
--- a/testsuites/samples/psxinttypes01/init.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/*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
deleted file mode 100644
index a8ce42a..0000000
--- a/testsuites/samples/psxinttypes01/psxid01.doc
+++ /dev/null
@@ -1,35 +0,0 @@
-# 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
deleted file mode 100644
index e0ea2a0..0000000
--- a/testsuites/samples/psxinttypes01/psxid01.scn
+++ /dev/null
@@ -1,38 +0,0 @@
-*** 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