[PATCH] Implementation of inttypes.h and its tests within the samples testsuites named psxinttypes01
Aditya Upadhyay
aadit0402 at gmail.com
Sun Jun 4 06:26:58 UTC 2017
---
cpukit/inttypes/imaxabs.c | 5 +-
cpukit/inttypes/imaxdiv.c | 26 +++----
cpukit/inttypes/strtoimax.c | 170 ++++++++++++++++++++--------------------
cpukit/inttypes/strtoumax.c | 164 ++++++++++++++++++++-------------------
cpukit/inttypes/wcstoimax.c | 183 +++++++++++++++++++++++---------------------
cpukit/inttypes/wcstoumax.c | 168 ++++++++++++++++++++--------------------
foo.c | 5 --
7 files changed, 368 insertions(+), 353 deletions(-)
delete mode 100644 foo.c
diff --git a/cpukit/inttypes/imaxabs.c b/cpukit/inttypes/imaxabs.c
index 525e9c0..c1d25be 100644
--- a/cpukit/inttypes/imaxabs.c
+++ b/cpukit/inttypes/imaxabs.c
@@ -27,14 +27,15 @@
#include "config.h"
#endif
-#include <stdint.h>
+#include <stdint.h> /*intmax_t data type defined here */
#include <stdio.h>
#include <rtems/inttypes.h>
intmax_t
-imaxabs(intmax_t j)
+imaxabs(
+ intmax_t j)
{
return (j < 0 ? -j : j);
}
diff --git a/cpukit/inttypes/imaxdiv.c b/cpukit/inttypes/imaxdiv.c
index 7992caa..97db900 100644
--- a/cpukit/inttypes/imaxdiv.c
+++ b/cpukit/inttypes/imaxdiv.c
@@ -28,23 +28,23 @@
#include "config.h"
#endif
-#include <stdint.h>
+#include <stdint.h> /* intmax_t data type defined here */
#include <rtems/inttypes.h>
/* See comments in div.c for implementation details. */
imaxdiv_t
-imaxdiv(intmax_t numer, intmax_t denom)
+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);
+ 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 9971f73..e7382dd 100644
--- a/cpukit/inttypes/strtoimax.c
+++ b/cpukit/inttypes/strtoimax.c
@@ -31,87 +31,91 @@
#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);
+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
index 3612a23..70d15ee 100644
--- a/cpukit/inttypes/strtoumax.c
+++ b/cpukit/inttypes/strtoumax.c
@@ -31,86 +31,90 @@
#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;
- }
+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
- return minus ? -accum : accum; /* (yes!) */
- }
+ base = 8;
+ }
+ else
+ base = 10;
+ }
-unsigned long long __attribute__ ((alias ("strtoumax")))
-strtoull (const char* __restrict__ nptr, char ** __restrict__ endptr, int base);
+ /* 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
index 24667bd..2ba3547 100644
--- a/cpukit/inttypes/wcstoimax.c
+++ b/cpukit/inttypes/wcstoimax.c
@@ -33,93 +33,98 @@
#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);
+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
index a796a62..36ea56b 100644
--- a/cpukit/inttypes/wcstoumax.c
+++ b/cpukit/inttypes/wcstoumax.c
@@ -33,87 +33,93 @@
#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 */
+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 ( 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);
+ 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/foo.c b/foo.c
deleted file mode 100644
index c9f9b31..0000000
--- a/foo.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#include<stdio.h>
-void main()
-{
- printf("hello");
-}
--
2.7.4
More information about the devel
mailing list