#define TEST_NAME "memccpy"
#include "test-string.h"
-void *simple_memccpy (void *, const void *, int, size_t);
-void *stupid_memccpy (void *, const void *, int, size_t);
-
-IMPL (stupid_memccpy, 0)
-IMPL (simple_memccpy, 0)
IMPL (memccpy, 1)
+/* Naive implementation to verify results. */
void *
simple_memccpy (void *dst, const void *src, int c, size_t n)
{
return NULL;
}
-void *
-stupid_memccpy (void *dst, const void *src, int c, size_t n)
-{
- void *p = memchr (src, c, n);
-
- if (p != NULL)
- return mempcpy (dst, src, p - src + 1);
-
- memcpy (dst, src, n);
- return NULL;
-}
-
typedef void *(*proto_t) (void *, const void *, int c, size_t);
static void
#endif /* WIDE */
typedef CHAR *(*proto_t) (const CHAR *, int, size_t);
-CHAR *SIMPLE_MEMCHR (const CHAR *, int, size_t);
-IMPL (SIMPLE_MEMCHR, 0)
IMPL (MEMCHR, 1)
+/* Naive implementation to verify results. */
CHAR *
SIMPLE_MEMCHR (const CHAR *s, int c, size_t n)
{
typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
-IMPL (SIMPLE_MEMCMP, 0)
IMPL (MEMCMP, 1)
static int
#define TIMEOUT (8 * 60)
#include "test-string.h"
-char *simple_memcpy (char *, const char *, size_t);
-char *builtin_memcpy (char *, const char *, size_t);
-
-IMPL (simple_memcpy, 0)
-IMPL (builtin_memcpy, 0)
IMPL (memcpy, 1)
+
+/* Naive implementation to verify results. */
char *
simple_memcpy (char *dst, const char *src, size_t n)
{
return ret;
}
-char *
-builtin_memcpy (char *dst, const char *src, size_t n)
-{
- return __builtin_memcpy (dst, src, n);
-}
#endif
typedef char *(*proto_t) (char *, const char *, size_t);
typedef uint32_t __attribute__ ((may_alias, aligned (1))) unaligned_uint32_t;
#include "test-string.h"
typedef char *(*proto_t) (const void *, size_t, const void *, size_t);
-void *simple_memmem (const void *, size_t, const void *, size_t);
-IMPL (simple_memmem, 0)
IMPL (memmem, 1)
+/* Naive implementation to verify results. */
void *
simple_memmem (const void *haystack, size_t haystack_len, const void *needle,
size_t needle_len)
#ifdef TEST_BCOPY
typedef void (*proto_t) (const char *, char *, size_t);
-void simple_bcopy (const char *, char *, size_t);
-IMPL (simple_bcopy, 0)
IMPL (bcopy, 1)
+/* Naive implementation to verify results. */
void
simple_bcopy (const char *src, char *dst, size_t n)
{
simple_memmove (dst, src, n);
}
+
#else
typedef char *(*proto_t) (char *, const char *, size_t);
-IMPL (simple_memmove, 0)
IMPL (memmove, 1)
#endif
+/* Naive implementation to verify results. */
char *
inhibit_loop_to_libcall
simple_memmove (char *dst, const char *src, size_t n)
#define TEST_NAME "mempcpy"
#include "test-string.h"
-char *simple_mempcpy (char *, const char *, size_t);
-
-IMPL (simple_mempcpy, 0)
IMPL (mempcpy, 1)
+/* Naive implementation to verify results. */
char *
simple_mempcpy (char *dst, const char *src, size_t n)
{
#include "test-string.h"
typedef char *(*proto_t) (const char *, int, size_t);
-char *simple_memrchr (const char *, int, size_t);
-IMPL (simple_memrchr, 0)
IMPL (memrchr, 1)
+/* Naive implementation to verify results. */
char *
simple_memrchr (const char *s, int c, size_t n)
{
# define BIG_CHAR WCHAR_MAX
#endif /* WIDE */
-CHAR *SIMPLE_MEMSET (CHAR *, int, size_t);
-
#ifdef TEST_BZERO
typedef void (*proto_t) (char *, size_t);
-void simple_bzero (char *, size_t);
-void builtin_bzero (char *, size_t);
-
-IMPL (simple_bzero, 0)
-IMPL (builtin_bzero, 0)
-#ifdef TEST_EXPLICIT_BZERO
+# ifdef TEST_EXPLICIT_BZERO
IMPL (explicit_bzero, 1)
-#else
+# else
IMPL (bzero, 1)
-#endif
-
-void
-simple_bzero (char *s, size_t n)
-{
- SIMPLE_MEMSET (s, 0, n);
-}
-
-void
-builtin_bzero (char *s, size_t n)
-{
- __builtin_bzero (s, n);
-}
+# endif
#else
typedef CHAR *(*proto_t) (CHAR *, int, size_t);
-
-IMPL (SIMPLE_MEMSET, 0)
-# ifndef WIDE
-char *builtin_memset (char *, int, size_t);
-IMPL (builtin_memset, 0)
-# endif /* !WIDE */
IMPL (MEMSET, 1)
-
-# ifndef WIDE
-char *
-builtin_memset (char *s, int c, size_t n)
-{
- return __builtin_memset (s, c, n);
-}
-# endif /* !WIDE */
#endif /* !TEST_BZERO */
+/* Naive implementation to verify results. */
CHAR *
inhibit_loop_to_libcall
SIMPLE_MEMSET (CHAR *s, int c, size_t n)
s[n] = sentinel;
SIMPLE_MEMSET(s, ~c, n);
#ifdef TEST_BZERO
- simple_bzero (buf, n);
+ SIMPLE_MEMSET (buf, 0, n);
CALL (impl, s, n);
if (memcmp (s, buf, n) != 0
|| (space_below && s[-1] != sentinel)
#include "test-string.h"
typedef int (*proto_t) (const char *, const char *);
-static int simple_strcasecmp (const char *, const char *);
-static int stupid_strcasecmp (const char *, const char *);
-IMPL (stupid_strcasecmp, 0)
-IMPL (simple_strcasecmp, 0)
IMPL (strcasecmp, 1)
-static int
+/* Naive implementation to verify results. */
+int
simple_strcasecmp (const char *s1, const char *s2)
{
int ret;
return ret;
}
-static int
-stupid_strcasecmp (const char *s1, const char *s2)
-{
- size_t ns1 = strlen (s1) + 1, ns2 = strlen (s2) + 1;
- size_t n = ns1 < ns2 ? ns1 : ns2;
- int ret = 0;
-
- while (n--)
- {
- if ((ret = ((unsigned char) tolower (*s1)
- - (unsigned char) tolower (*s2))) != 0)
- break;
- ++s1;
- ++s2;
- }
- return ret;
-}
-
static void
do_one_test (impl_t *impl, const char *s1, const char *s2, int exp_result)
{
#include "test-string.h"
-#define STRCASESTR simple_strcasestr
+#define STRCASESTR c_strcasestr
#define NO_ALIAS
#define __strncasecmp strncasecmp
#define __strnlen strnlen
#include "strcasestr.c"
-
+/* Naive implementation to verify results. */
static char *
-stupid_strcasestr (const char *s1, const char *s2)
+simple_strcasestr (const char *s1, const char *s2)
{
ssize_t s1len = strlen (s1);
ssize_t s2len = strlen (s2);
typedef char *(*proto_t) (const char *, const char *);
-IMPL (stupid_strcasestr, 0)
-IMPL (simple_strcasestr, 0)
+IMPL (c_strcasestr, 0)
IMPL (strcasestr, 1)
const char s2[] = "OK";
char *exp_result;
- exp_result = stupid_strcasestr (s1, s2);
+ exp_result = simple_strcasestr (s1, s2);
FOR_EACH_IMPL (impl, 0)
check_result (impl, s1, s2, exp_result);
}
#endif /* WIDE */
typedef CHAR *(*proto_t) (CHAR *, const CHAR *);
-CHAR *SIMPLE_STRCAT (CHAR *, const CHAR *);
-IMPL (SIMPLE_STRCAT, 0)
IMPL (STRCAT, 1)
+/* Naive implementation to verify results. */
CHAR *
SIMPLE_STRCAT (CHAR *dst, const CHAR *src)
{
#ifndef WIDE
# ifdef USE_FOR_STRCHRNUL
# define STRCHR strchrnul
-# define stupid_STRCHR stupid_STRCHRNUL
# define simple_STRCHR simple_STRCHRNUL
# else
# define STRCHR strchr
# include <wchar.h>
# ifdef USE_FOR_STRCHRNUL
# define STRCHR wcschrnul
-# define stupid_STRCHR stupid_WCSCHRNUL
# define simple_STRCHR simple_WCSCHRNUL
# else
# define STRCHR wcschr
typedef CHAR *(*proto_t) (const CHAR *, int);
+/* Naive implementation to verify results. */
CHAR *
simple_STRCHR (const CHAR *s, int c)
-{
- for (; *s != (CHAR) c; ++s)
- if (*s == '\0')
- return NULLRET ((CHAR *) s);
- return (CHAR *) s;
-}
-
-CHAR *
-stupid_STRCHR (const CHAR *s, int c)
{
size_t n = STRLEN (s) + 1;
return NULLRET ((CHAR *) s - 1);
}
-IMPL (stupid_STRCHR, 0)
-IMPL (simple_STRCHR, 0)
IMPL (STRCHR, 1)
static int
{
CHAR s[] __attribute__((aligned(16))) = L ("\xff");
CHAR c = L ('\xfe');
- CHAR *exp_result = stupid_STRCHR (s, c);
+ CHAR *exp_result = simple_STRCHR (s, c);
FOR_EACH_IMPL (impl, 0)
check_result (impl, s, c, exp_result);
typedef int (*proto_t) (const CHAR *, const CHAR *);
-IMPL (SIMPLE_STRCMP, 1)
IMPL (STRCMP, 1)
static int
# define STRCPY wcscpy
# endif
-CHAR *SIMPLE_STRCPY (CHAR *, const CHAR *);
-
-IMPL (SIMPLE_STRCPY, 0)
IMPL (STRCPY, 1)
+/* Naive implementation to verify results. */
CHAR *
SIMPLE_STRCPY (CHAR *dst, const CHAR *src)
{
typedef size_t (*proto_t) (const CHAR *);
+/* Naive implementation to verify results. */
size_t
simple_STRLEN (const CHAR *s)
{
IMPL (builtin_strlen, 0)
#endif
-IMPL (simple_STRLEN, 0)
IMPL (STRLEN, 1)
typedef int (*proto_t) (const char *, const char *, size_t);
static int simple_strncasecmp (const char *, const char *, size_t);
-static int stupid_strncasecmp (const char *, const char *, size_t);
-IMPL (stupid_strncasecmp, 0)
-IMPL (simple_strncasecmp, 0)
IMPL (strncasecmp, 1)
+/* Naive implementation to verify results. */
static int
simple_strncasecmp (const char *s1, const char *s2, size_t n)
{
return ret;
}
-static int
-stupid_strncasecmp (const char *s1, const char *s2, size_t max)
-{
- size_t ns1 = strlen (s1) + 1;
- size_t ns2 = strlen (s2) + 1;
- size_t n = ns1 < ns2 ? ns1 : ns2;
- if (n > max)
- n = max;
- int ret = 0;
-
- while (n--)
- {
- if ((ret = ((unsigned char) tolower (*s1)
- - (unsigned char) tolower (*s2))) != 0)
- break;
- ++s1;
- ++s2;
- }
- return ret;
-}
-
static int
check_result (impl_t *impl, const char *s1, const char *s2, size_t n,
int exp_result)
# define CHAR char
# define UCHAR unsigned char
# define SIMPLE_STRNCAT simple_strncat
-# define STUPID_STRNCAT stupid_strncat
# define STRLEN strlen
# define MEMSET memset
# define MEMCPY memcpy
# define CHAR wchar_t
# define UCHAR wchar_t
# define SIMPLE_STRNCAT simple_wcsncat
-# define STUPID_STRNCAT stupid_wcsncat
# define STRLEN wcslen
# define MEMSET wmemset
# define MEMCPY wmemcpy
#endif /* WIDE */
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
-CHAR *STUPID_STRNCAT (CHAR *, const CHAR *, size_t);
-CHAR *SIMPLE_STRNCAT (CHAR *, const CHAR *, size_t);
-IMPL (STUPID_STRNCAT, 0)
IMPL (STRNCAT, 2)
+/* Naive implementation to verify results. */
CHAR *
-STUPID_STRNCAT (CHAR *dst, const CHAR *src, size_t n)
+SIMPLE_STRNCAT (CHAR *dst, const CHAR *src, size_t n)
{
CHAR *ret = dst;
while (*dst++ != '\0');
typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
-IMPL (SIMPLE_STRNCMP, 0)
IMPL (STRNCMP, 1)
# include "test-string.h"
# ifndef WIDE
# define SIMPLE_STRNCPY simple_strncpy
-# define STUPID_STRNCPY stupid_strncpy
# define STRNCPY strncpy
# else
# define SIMPLE_STRNCPY simple_wcsncpy
-# define STUPID_STRNCPY stupid_wcsncpy
# define STRNCPY wcsncpy
# endif /* WIDE */
-CHAR *SIMPLE_STRNCPY (CHAR *, const CHAR *, size_t);
-CHAR *STUPID_STRNCPY (CHAR *, const CHAR *, size_t);
-IMPL (STUPID_STRNCPY, 0)
-IMPL (SIMPLE_STRNCPY, 0)
IMPL (STRNCPY, 1)
+/* Naive implementation to verify results. */
CHAR *
SIMPLE_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
{
return ret;
}
-CHAR *
-STUPID_STRNCPY (CHAR *dst, const CHAR *src, size_t n)
-{
- size_t nc = STRNLEN (src, n);
- size_t i;
-
- for (i = 0; i < nc; ++i)
- dst[i] = src[i];
- for (; i < n; ++i)
- dst[i] = '\0';
- return dst;
-}
#endif /* !STRNCPY_RESULT */
typedef CHAR *(*proto_t) (CHAR *, const CHAR *, size_t);
#endif /* !WIDE */
typedef size_t (*proto_t) (const CHAR *, size_t);
-size_t SIMPLE_STRNLEN (const CHAR *, size_t);
-IMPL (SIMPLE_STRNLEN, 0)
IMPL (STRNLEN, 1)
+/* Naive implementation to verify results. */
size_t
SIMPLE_STRNLEN (const CHAR *s, size_t maxlen)
{
# ifndef WIDE
# define STRPBRK strpbrk
# define SIMPLE_STRPBRK simple_strpbrk
-# define STUPID_STRPBRK stupid_strpbrk
# else
# include <wchar.h>
# define STRPBRK wcspbrk
# define SIMPLE_STRPBRK simple_wcspbrk
-# define STUPID_STRPBRK stupid_wcspbrk
# endif /* WIDE */
typedef CHAR *(*proto_t) (const CHAR *, const CHAR *);
-CHAR *SIMPLE_STRPBRK (const CHAR *, const CHAR *);
-CHAR *STUPID_STRPBRK (const CHAR *, const CHAR *);
-IMPL (STUPID_STRPBRK, 0)
-IMPL (SIMPLE_STRPBRK, 0)
IMPL (STRPBRK, 1)
+/* Naive implementation to verify results. */
CHAR *
SIMPLE_STRPBRK (const CHAR *s, const CHAR *rej)
{
while ((c = *s++) != '\0')
for (r = rej; *r != '\0'; ++r)
if (*r == c)
- return (CHAR *) s - 1;
+ return (CHAR *) s - 1;
return NULL;
}
-CHAR *
-STUPID_STRPBRK (const CHAR *s, const CHAR *rej)
-{
- size_t ns = STRLEN (s), nrej = STRLEN (rej);
- size_t i, j;
-
- for (i = 0; i < ns; ++i)
- for (j = 0; j < nrej; ++j)
- if (s[i] == rej[j])
- return (CHAR *) s + i;
- return NULL;
-}
#endif /* !STRPBRK_RESULT */
static void
#endif
typedef CHAR *(*proto_t) (const CHAR *, int);
-CHAR *SIMPLE_STRRCHR (const CHAR *, int);
-IMPL (SIMPLE_STRRCHR, 0)
IMPL (STRRCHR, 1)
+/* Naive implementation to verify results. */
CHAR *
SIMPLE_STRRCHR (const CHAR *s, int c)
{
# define CHAR char
# define UCHAR unsigned char
# define SIMPLE_STRSPN simple_strspn
-# define STUPID_STRSPN stupid_strspn
# define STRLEN strlen
# define STRCHR strchr
# define BIG_CHAR CHAR_MAX
# define CHAR wchar_t
# define UCHAR wchar_t
# define SIMPLE_STRSPN simple_wcsspn
-# define STUPID_STRSPN stupid_wcsspn
# define STRLEN wcslen
# define STRCHR wcschr
# define BIG_CHAR WCHAR_MAX
#endif /* WIDE */
typedef size_t (*proto_t) (const CHAR *, const CHAR *);
-size_t SIMPLE_STRSPN (const CHAR *, const CHAR *);
-size_t STUPID_STRSPN (const CHAR *, const CHAR *);
-IMPL (STUPID_STRSPN, 0)
-IMPL (SIMPLE_STRSPN, 0)
IMPL (STRSPN, 1)
+/* Naive implementation to verify results. */
size_t
SIMPLE_STRSPN (const CHAR *s, const CHAR *acc)
{
return s - str - 1;
}
-size_t
-STUPID_STRSPN (const CHAR *s, const CHAR *acc)
-{
- size_t ns = STRLEN (s), nacc = STRLEN (acc);
- size_t i, j;
-
- for (i = 0; i < ns; ++i)
- {
- for (j = 0; j < nacc; ++j)
- if (s[i] == acc[j])
- break;
- if (j == nacc)
- return i;
- }
- return i;
-}
-
static void
do_one_test (impl_t *impl, const CHAR *s, const CHAR *acc, size_t exp_res)
{
#include "test-string.h"
-#define STRSTR simple_strstr
+#define STRSTR c_strstr
#define libc_hidden_builtin_def(arg) /* nothing */
#define __strnlen strnlen
#include "strstr.c"
-
+/* Naive implementation to verify results. */
static char *
-stupid_strstr (const char *s1, const char *s2)
+simple_strstr (const char *s1, const char *s2)
{
ssize_t s1len = strlen (s1);
ssize_t s2len = strlen (s2);
typedef char *(*proto_t) (const char *, const char *);
-IMPL (stupid_strstr, 0)
-IMPL (simple_strstr, 0)
+IMPL (c_strstr, 0)
IMPL (strstr, 1)
const char s2[] = "_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD_EF_BF_BD";
char *exp_result;
- exp_result = stupid_strstr (s1, s2);
+ exp_result = simple_strstr (s1, s2);
FOR_EACH_IMPL (impl, 0)
check_result (impl, s1, s2, exp_result);
}
char *s2_page_cross = (void *) buf2 + page_size_real - 8;
strcpy (s2_page_cross, s2_stack);
- exp_result = stupid_strstr (s1_stack, s2_stack);
+ exp_result = simple_strstr (s1_stack, s2_stack);
FOR_EACH_IMPL (impl, 0)
{
check_result (impl, s1_stack, s2_stack, exp_result);
/* Ensure we don't match at the first 'x'. */
h[0] = 'x';
- char *exp_result = stupid_strstr (h, n);
+ char *exp_result = simple_strstr (h, n);
FOR_EACH_IMPL (impl, 0)
check_result (impl, h, n, exp_result);
}