1 /* Test strncmp 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 "wcsncmp"
21 #else
22 # define TEST_NAME "strncmp"
23 #endif
24 
25 #include "test-size_t.h"
26 
27 #ifdef WIDE
28 # include <wchar.h>
29 
30 # define STRNCMP wcsncmp
31 # define STRNCPY wcsncpy
32 # define CHAR wchar_t
33 #else
34 # define STRNCMP strncmp
35 # define STRNCPY strncpy
36 # define CHAR char
37 #endif
38 
39 IMPL (STRNCMP, 1)
40 
41 typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
42 
43 
44 static int
45 __attribute__ ((noinline, noclone))
do_strncmp(parameter_t a,parameter_t b)46 do_strncmp (parameter_t a, parameter_t b)
47 {
48   return CALL (&b, a.p, b.p, a.len);
49 }
50 
51 static int
test_main(void)52 test_main (void)
53 {
54   test_init ();
55 
56   size_t size = page_size / sizeof (CHAR);
57   parameter_t dest = { { size }, buf1 };
58   parameter_t src = { { 0 }, buf2 };
59 
60   STRNCPY ((CHAR *) buf1, (const CHAR *) buf2, size);
61 
62   int ret = 0;
63   FOR_EACH_IMPL (impl, 0)
64     {
65       src.fn = impl->fn;
66       int res = do_strncmp (dest, src);
67       if (res)
68 	{
69 	  error (0, 0, "Wrong result in function %s: %i != 0",
70 		 impl->name, res);
71 	  ret = 1;
72 	}
73     }
74 
75   return ret ? EXIT_FAILURE : EXIT_SUCCESS;
76 }
77 
78 #include <support/test-driver.c>
79