1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup bli
22  *
23  * A platform-independent definition of [u]intXX_t
24  * Plus the accompanying header include for htonl/ntohl
25  *
26  * This file includes <sys/types.h> to define [u]intXX_t types, where
27  * XX can be 8, 16, 32 or 64. Unfortunately, not all systems have this
28  * file.
29  * - Windows uses __intXX compiler-builtin types. These are signed,
30  *   so we have to flip the signs.
31  * For these rogue platforms, we make the typedefs ourselves.
32  */
33 
34 #pragma once
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #if defined(__linux__) || defined(__GNU__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
41     defined(__FreeBSD_kernel__) || defined(__HAIKU__)
42 
43 /* Linux-i386, Linux-Alpha, Linux-ppc */
44 #  include <stdint.h>
45 
46 /* XXX */
47 #  ifndef UINT64_MAX
48 #    define UINT64_MAX 18446744073709551615
49 typedef uint8_t u_int8_t;
50 typedef uint16_t u_int16_t;
51 typedef uint32_t u_int32_t;
52 typedef uint64_t u_int64_t;
53 #  endif
54 
55 #elif defined(__APPLE__)
56 
57 #  include <inttypes.h>
58 
59 /* MSVC >= 2010 */
60 #elif defined(_MSC_VER)
61 #  include <stdint.h>
62 
63 #else
64 
65 /* FreeBSD, Solaris */
66 #  include <stdint.h>
67 #  include <sys/types.h>
68 
69 #endif /* ifdef platform for types */
70 
71 #include <stdbool.h>
72 #include <stddef.h> /* size_t define */
73 
74 #ifndef __cplusplus
75 #  if defined(__APPLE__) || defined(__NetBSD__)
76 /* The <uchar.h> standard header is missing on macOS. */
77 typedef unsigned int char32_t;
78 #  else
79 #    include <uchar.h>
80 #  endif
81 #endif
82 
83 typedef unsigned int uint;
84 typedef unsigned short ushort;
85 typedef unsigned long ulong;
86 typedef unsigned char uchar;
87 
88 #ifdef __cplusplus
89 }
90 #endif
91