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