<string.h>: Make strchrnul, strcasestr, memmem available by default
[platform/upstream/glibc.git] / string / tst-bswap.c
1 /* Copyright (C) 2000-2023 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, see
16    <https://www.gnu.org/licenses/>.  */
17
18 #include <byteswap.h>
19 #include <stdio.h>
20
21 extern unsigned long long int wash (unsigned long long int a);
22
23 int
24 do_test (void)
25 {
26   int result = 0;
27
28   /* Test the functions with constant arguments.  */
29   if (bswap_16 (0x1234) != 0x3412)
30     {
31       puts ("bswap_16 (constant) flunked");
32       result = 1;
33     }
34   if (bswap_32 (0x12345678) != 0x78563412)
35     {
36       puts ("bswap_32 (constant) flunked");
37       result = 1;
38     }
39   if (bswap_64 (0x1234567890abcdefULL) != 0xefcdab9078563412ULL)
40     {
41       puts ("bswap_64 (constant) flunked");
42       result = 1;
43     }
44
45   /* Test the functions with non-constant arguments.  */
46   if (bswap_16 (wash (0x1234)) != 0x3412)
47     {
48       puts ("bswap_16 (non-constant) flunked");
49       result = 1;
50     }
51   if (bswap_32 (wash (0x12345678)) != 0x78563412)
52     {
53       puts ("bswap_32 (non-constant) flunked");
54       result = 1;
55     }
56   if (bswap_64 (wash (0x1234567890abcdefULL)) != 0xefcdab9078563412ULL)
57     {
58       puts ("bswap_64 (non-constant) flunked");
59       result = 1;
60     }
61
62   return result;
63 }
64
65
66 unsigned long long int
67 wash (unsigned long long int a)
68 {
69   /* Do nothing.  This function simply exists to avoid that the compiler
70      regards the argument to the bswap_*() functions as constant.  */
71   return a + 0;
72 }
73
74 #include <support/test-driver.c>