28#define _RWSTD_TEST_SRC
50 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
52 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
54 "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
56 "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f"
58 "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
60 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"
62 "\x60\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
64 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x7b\x7c\x7d\x7e\x7f"
67 "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
68 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
69 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf"
70 "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
71 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
72 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
73 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
74 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
82 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
84 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
86 "\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f"
88 "\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f"
90 "\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
92 "\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f"
94 "\x60\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f"
96 "\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f"
98 "\x80\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\x8a\x8b\x8c\x8d\x8e\x8f"
100 "\x90\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\x9a\x9b\x9c\x9d\x9e\x9f"
102 "\xa0\xa1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xaa\xab\xac\xad\xae\xaf"
104 "\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf"
106 "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf"
108 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf"
110 "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef"
112 "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"
115# error unknown character set (neither ASCII nor EBCDIC)
123_rw_iszero (
const void *
buf,
size_t size)
125 for (
size_t i = 0;
i !=
size; ++
i)
135_rw_cmpx (
const void *buf1,
152 const int zero1 = _rw_iszero (
p1,
size);
153 const int zero2 = _rw_iszero (
p2,
size);
155 if (zero1 || zero2) {
164 "%s:%d: case insensitive comparison not implemented\n",
173 "%s:%d: returning offset not implemented\n",
178 return ret < 0 ? -1 : ret ? +1 : 0;
184_rw_cmp1 (
const void *buf1,
191 typedef _RWSTD_UINT8_T UI8T;
194 const int ret = memcmp (buf1, buf2, nelems);
195 return ret < 0 ? -1 : ret ? +1 : 0;
203 return ret < 0 ? -1 : ret ? +1 : 0;
212 for (;
inx < nelems; ++pi1, ++pi2, ++
inx) {
214 const UI8T ui1 = *pi1;
215 const UI8T ui2 = *pi2;
232 if (_rw_upper [ui1] != _rw_upper [ui2]) {
233 ret = _rw_upper [ui1] < _rw_upper [ui2] ? -1 : +1;
238 ret = ui1 < ui2 ? -1 : +1;
245 ret = ret ? int (
inx) : -1;
251# error _RWSTD_UINT8_T not #defined (configuration problem?)
259_rw_cmp2 (
const void *buf1,
264#ifdef _RWSTD_UINT16_T
266 typedef _RWSTD_UINT16_T UI16T;
274 for (;
inx < nelems; ++pi1, ++pi2, ++
inx) {
276 const UI16T ui1 = *pi1;
277 const UI16T ui2 = *pi2;
294 if (_RWSTD_UCHAR_MAX < ui1 || _RWSTD_UCHAR_MAX < ui2) {
295 ret = ui1 < ui2 ? -1 : +1;
298 else if (_rw_upper [ui1] != _rw_upper [ui2]) {
299 ret = _rw_upper [ui1] < _rw_upper [ui2] ? -1 : +1;
304 ret = ui1 < ui2 ? -1 : +1;
311 ret = ret ? int (
inx) : -1;
318 return _rw_cmpx (buf1, buf2, nelems, 2,
flags);
326_rw_cmp4 (
const void *buf1,
331#ifdef _RWSTD_UINT32_T
333 typedef _RWSTD_UINT32_T UI32T;
341 for (;
inx < nelems; ++pi1, ++pi2, ++
inx) {
343 const UI32T ui1 = *pi1;
344 const UI32T ui2 = *pi2;
361 if (_RWSTD_UCHAR_MAX < ui1 || _RWSTD_UCHAR_MAX < ui2) {
362 ret = ui1 < ui2 ? -1 : +1;
365 else if (_rw_upper [ui1] != _rw_upper [ui2]) {
366 ret = _rw_upper [ui1] < _rw_upper [ui2] ? -1 : +1;
371 ret = ui1 < ui2 ? -1 : +1;
378 ret = ret ? int (
inx) : -1;
385 return _rw_cmpx (buf1, buf2, nelems, 4,
flags);
393_rw_cmp8 (
const void *buf1,
398#ifdef _RWSTD_UINT64_T
400 typedef _RWSTD_UINT64_T UI64T;
408 for (; nelems; ++pi1, ++pi2, ++
inx) {
410 const UI64T ui1 = *pi1;
411 const UI64T ui2 = *pi2;
428 if (_RWSTD_UCHAR_MAX < ui1 || _RWSTD_UCHAR_MAX < ui2) {
429 ret = ui1 < ui2 ? -1 : +1;
432 else if (_rw_upper [ui1] != _rw_upper [ui2]) {
433 ret = _rw_upper [ui1] < _rw_upper [ui2] ? -1 : +1;
438 ret = ui1 < ui2 ? -1 : +1;
445 ret = ret ? int (
inx) : -1;
452 return _rw_cmpx (buf1, buf2, nelems, 8,
flags);
460_rw_cmpxx (
const void* buf1,
470 for (;
inx < nelems; ++
inx) {
472#ifdef _RWSTD_UINT64_T
489 const _RWSTD_UINT8_T*
ptr =
498#ifdef _RWSTD_UINT16_T
501 const _RWSTD_UINT16_T*
ptr =
510#ifdef _RWSTD_UINT32_T
513 const _RWSTD_UINT32_T*
ptr =
522#ifdef _RWSTD_UINT64_T
525 const _RWSTD_UINT64_T*
ptr =
536 "%s:%d: comparison of objects %u and %u bytes in size "
537 "not implemented\n", __FILE__, __LINE__,
538 unsigned (size1),
unsigned (size2));
547 const _RWSTD_UINT8_T*
ptr =
556#ifdef _RWSTD_UINT16_T
559 const _RWSTD_UINT16_T*
ptr =
568#ifdef _RWSTD_UINT32_T
571 const _RWSTD_UINT32_T*
ptr =
580#ifdef _RWSTD_UINT64_T
583 const _RWSTD_UINT64_T*
ptr =
594 "%s:%d: comparison of objects %u and %u bytes in size "
595 "not implemented\n", __FILE__, __LINE__,
596 unsigned (size1),
unsigned (size2));
615 if (_RWSTD_UCHAR_MAX < ui1 || _RWSTD_UCHAR_MAX < ui2) {
616 ret = ui1 < ui2 ? -1 : +1;
619 else if (_rw_upper [ui1] != _rw_upper [ui2]) {
620 ret = _rw_upper [ui1] < _rw_upper [ui2] ? -1 : +1;
625 ret = ui1 < ui2 ? -1 : +1;
632 ret = ret ? int (
inx) : -1;
647 if (size1 == size2) {
650 case 1:
return _rw_cmp1 (buf1, buf2, nelems,
flags);
651 case 2:
return _rw_cmp2 (buf1, buf2, nelems,
flags);
652 case 4:
return _rw_cmp4 (buf1, buf2, nelems,
flags);
653 case 8:
return _rw_cmp8 (buf1, buf2, nelems,
flags);
656 return _rw_cmpx (buf1, buf2, nelems, size1,
flags);
659 return _rw_cmpxx (buf1, buf2, nelems, size1, size2,
flags);
673#ifndef _RWSTD_NO_WCHAR_T
681 return rw_valcmp (str1, str2, nelems, 1,
sizeof (
wchar_t),
flags);
691 return rw_valcmp (str1, str2, nelems,
sizeof (
wchar_t), 1,
flags);
702 sizeof (
wchar_t),
sizeof (
wchar_t),
flags);
714#if _RWSTD_FLT_SIZE == _RWSTD_SHRT_SIZE
716 const IntT imin = _RWSTD_SHRT_MIN;
717#elif _RWSTD_FLT_SIZE == _RWSTD_INT_SIZE
719 const IntT imin = _RWSTD_INT_MIN;
720#elif _RWSTD_FLT_SIZE == _RWSTD_LONG_SIZE
722 const IntT imin = _RWSTD_LONG_MIN;
723#elif _RWSTD_FLT_SIZE == _RWSTD_LLONG_SIZE
725 const IntT imin = _RWSTD_LLONG_MIN;
728# error no integral type of the same size as float exists
735 IntT x_int = *(IntT*)&
x;
737 x_int = imin - x_int;
739 IntT y_int = *(IntT*)&
y;
741 y_int = imin - y_int;
743 const IntT int_diff = x_int - y_int;
749#define Abs(x) ((x) < 0 ? -(x) : (x))
755#if _RWSTD_DBL_SIZE == _RWSTD_INT_SIZE
757 const IntT imin = _RWSTD_INT_MIN;
758#elif _RWSTD_DBL_SIZE == _RWSTD_LONG_SIZE
760 const IntT imin = _RWSTD_LONG_MIN;
761#elif _RWSTD_DBL_SIZE == _RWSTD_LLONG_SIZE
763 const IntT imin = _RWSTD_LLONG_MIN;
766#if _RWSTD_LLONG_SIZE < _RWSTD_DBL_SIZE
773 const double diff =
x -
y;
776 if (
Abs (diff) < _RWSTD_DBL_EPSILON)
780 const double relerr =
783 if (relerr <= 0.0000001)
786 return x <
y ? -1 : +1;
793 IntT x_int = *(IntT*)&
x;
795 x_int = imin - x_int;
797 IntT y_int = *(IntT*)&
y;
799 y_int = imin - y_int;
801 const IntT int_diff = x_int - y_int;
806 return int (int_diff);
813#ifndef _RWSTD_NO_LONG_DOUBLE
818 if (
sizeof (
long double) ==
sizeof (
double))
826 const long double diff =
x -
y;
829 if (
Abs (diff) < _RWSTD_LDBL_EPSILON)
833 const long double relerr =
836 if (relerr <= 0.0000001L)
839 return x <
y ? -1 : +1;
#define _RWSTD_STATIC_CAST(T, x)
_TEST_EXPORT int rw_valcmp(const void *buf1, const void *buf2, size_t nelems, size_t size1, size_t size2, int flags)
_TEST_EXPORT int rw_strncmp(const char *str1, const char *str2, size_t nelems, int flags)
_TEST_EXPORT int rw_fltcmp(float x, float y)
_TEST_EXPORT int rw_ldblcmp(long double x, long double y)
_TEST_EXPORT int rw_dblcmp(double x, double y)