]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/x32/tst-size_t-memchr.c
29a3daf1024d6a0c683dd3a411a719320892d289
[thirdparty/glibc.git] / sysdeps / x86_64 / x32 / tst-size_t-memchr.c
1 /* Test memchr with size_t in the lower 32 bits of 64-bit register.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #ifndef WIDE
20 # define TEST_NAME "memchr"
21 #else
22 # define TEST_NAME "wmemchr"
23 #endif /* WIDE */
24 #include "test-size_t.h"
25
26 #ifndef WIDE
27 # define MEMCHR memchr
28 # define CHAR char
29 # define UCHAR unsigned char
30 #else
31 # include <wchar.h>
32 # define MEMCHR wmemchr
33 # define CHAR wchar_t
34 # define UCHAR wchar_t
35 #endif /* WIDE */
36
37 IMPL (MEMCHR, 1)
38
39 typedef CHAR * (*proto_t) (const CHAR*, int, size_t);
40
41 static CHAR *
42 __attribute__ ((noinline, noclone))
43 do_memchr (parameter_t a, parameter_t b)
44 {
45 return CALL (&b, a.p, (uintptr_t) b.p, a.len);
46 }
47
48 static int
49 test_main (void)
50 {
51 test_init ();
52
53 parameter_t src = { { page_size / sizeof (CHAR) }, buf2 };
54 parameter_t c = { { 0 }, (void *) (uintptr_t) 0x12 };
55
56 int ret = 0;
57 FOR_EACH_IMPL (impl, 0)
58 {
59 c.fn = impl->fn;
60 CHAR *res = do_memchr (src, c);
61 if (res)
62 {
63 error (0, 0, "Wrong result in function %s: %p != NULL",
64 impl->name, res);
65 ret = 1;
66 }
67 }
68
69 return ret ? EXIT_FAILURE : EXIT_SUCCESS;
70 }
71
72 #include <support/test-driver.c>