[subdir=io] (sysdep_routines): Add fallocate and fallocate64.
[glibc/history.git] / inet / htontest.c
blob9658c5b676cb4c52444f759b792f058e0c30fbef
1 /* Test hton/ntoh functions.
2 Copyright (C) 1997, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #include <endian.h>
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <netinet/in.h>
26 #if BYTE_ORDER == BIG_ENDIAN
27 # define TEST(orig, swapped, fct) \
28 if ((fct (orig)) != (orig)) { \
29 printf ("Failed for %s -> %#x\n", #fct "(" #orig ")", fct (orig)); \
30 result = 1; \
32 #elif BYTE_ORDER == LITTLE_ENDIAN
33 # define TEST(orig, swapped, fct) \
34 if ((fct (orig)) != (swapped)) { \
35 printf ("Failed for %s -> %#x\n", #fct "(" #orig ")", fct (orig)); \
36 result = 1; \
38 #else
39 # error "Bah, what kind of system do you use?"
40 #endif
42 u_int32_t lo = 0x67452301;
43 u_int16_t foo = 0x1234;
45 int
46 main (void)
48 int result = 0;
50 TEST (0x67452301, 0x01234567, htonl);
51 TEST (0x67452301, 0x01234567, (htonl));
52 TEST (0x67452301, 0x01234567, ntohl);
53 TEST (0x67452301, 0x01234567, (ntohl));
55 TEST (lo, 0x01234567, htonl);
56 TEST (lo, 0x01234567, (htonl));
57 TEST (lo, 0x01234567, ntohl);
58 TEST (lo, 0x01234567, (ntohl));
60 TEST (0x1234, 0x3412, htons);
61 TEST (0x1234, 0x3412, (htons));
62 TEST (0x1234, 0x3412, ntohs);
63 TEST (0x1234, 0x3412, (ntohs));
65 TEST (foo, 0x3412, htons);
66 TEST (foo, 0x3412, (htons));
67 TEST (foo, 0x3412, ntohs);
68 TEST (foo, 0x3412, (ntohs));
70 return result;