1 /* Test strnlen with size_t in the lower 32 bits of 64-bit register.
2    Copyright (C) 2019-2022 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    <https://www.gnu.org/licenses/>.  */
18 
19 #ifdef WIDE
20 # define TEST_NAME "wcsnlen"
21 #else
22 # define TEST_NAME "strnlen"
23 #endif /* WIDE */
24 
25 #include "test-size_t.h"
26 
27 #ifdef WIDE
28 # include <wchar.h>
29 # define STRNLEN wcsnlen
30 # define CHAR wchar_t
31 #else
32 # define STRNLEN strnlen
33 # define CHAR char
34 #endif /* WIDE */
35 
36 IMPL (STRNLEN, 1)
37 
38 typedef size_t (*proto_t) (const CHAR *, size_t);
39 
40 static size_t
41 __attribute__ ((noinline, noclone))
do_strnlen(parameter_t a,parameter_t b)42 do_strnlen (parameter_t a, parameter_t b)
43 {
44   return CALL (&a, a.p, b.len);
45 }
46 
47 static int
test_main(void)48 test_main (void)
49 {
50   test_init ();
51 
52   size_t size = page_size / sizeof (CHAR);
53   parameter_t src = { { 0 }, buf2 };
54   parameter_t c = { { size }, (void *) (uintptr_t) 'a' };
55 
56   int ret = 0;
57   FOR_EACH_IMPL (impl, 0)
58     {
59       src.fn = impl->fn;
60       size_t res = do_strnlen (src, c);
61       if (res != size)
62 	{
63 	  error (0, 0, "Wrong result in function %s: 0x%x != 0x%x",
64 		 impl->name, res, size);
65 	  ret = 1;
66 	}
67     }
68 
69   return ret ? EXIT_FAILURE : EXIT_SUCCESS;
70 }
71 
72 #include <support/test-driver.c>
73