xref: /plan9/sys/src/cmd/gs/src/stdint_.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2003-2004 artofcode LLC.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: stdint_.h,v 1.5 2004/06/17 21:42:53 giles Exp $ */
18 /* Generic substitute for stdint.h */
19 
20 #ifndef stdint__INCLUDED
21 #  define stdint__INCLUDED
22 
23 /*
24  * ensure our standard defines have been included
25  */
26 #include "std.h"
27 
28 /* Define some stdint.h types. The jbig2dec headers and ttf bytecode
29  * interpreter require these and they're generally useful to have around
30  * now that there's a standard.
31  */
32 
33 /* Some systems are guaranteed to have stdint.h
34  * but don't use the autoconf detection
35  */
36 #ifndef HAVE_STDINT_H
37 # ifdef __MACOS__
38 #   define HAVE_STDINT_H
39 # endif
40 #endif
41 
42 /* try a generic header first */
43 #if defined(HAVE_STDINT_H)
44 # include <stdint.h>
45 # define STDINT_TYPES_DEFINED
46 #elif defined(SYS_TYPES_HAS_STDINT_TYPES)
47   /* std.h will have included sys/types.h */
48 # define STDINT_TYPES_DEFINED
49 #endif
50 
51 /* try platform-specific defines */
52 #ifndef STDINT_TYPES_DEFINED
53 # if defined(__WIN32__) /* MSVC currently doesn't provide C99 headers */
54    typedef signed char             int8_t;
55    typedef short int               int16_t;
56    typedef int                     int32_t;
57    typedef __int64                 int64_t;
58    typedef unsigned char           uint8_t;
59    typedef unsigned short int      uint16_t;
60    typedef unsigned int            uint32_t;
61    typedef unsigned __int64        uint64_t;
62 #  define STDINT_TYPES_DEFINED
63 # elif defined(__VMS) /* OpenVMS provides these types in inttypes.h */
64 #  include <inttypes.h>
65 #  define STDINT_TYPES_DEFINED
66 # elif defined(__CYGWIN__)
67    /* Cygwin defines the signed versions in sys/types.h */
68    /* but uses a u_ prefix for the unsigned versions */
69    typedef u_int8_t                uint8_t;
70    typedef u_int16_t               uint16_t;
71    typedef u_int32_t               uint32_t;
72    typedef u_int64_t               uint64_t;
73 #  define STDINT_TYPES_DEFINED
74 # endif
75    /* other archs may want to add defines here,
76       or use the fallbacks in std.h */
77 #endif
78 
79 /* fall back to tests based on arch.h */
80 #ifndef STDINT_TYPES_DEFINED
81 /* 8 bit types */
82 # if ARCH_SIZEOF_CHAR == 1
83 typedef signed char int8_t;
84 typedef unsigned char uint8_t;
85 # endif
86 /* 16 bit types */
87 # if ARCH_SIZEOF_SHORT == 2
88 typedef signed short int16_t;
89 typedef unsigned short uint16_t;
90 # else
91 #  if ARCH_SIZEOF_INT == 2
92 typedef signed int int16_t;
93 typedef unsigned int uint16_t;
94 #  endif
95 # endif
96 /* 32 bit types */
97 # if ARCH_SIZEOF_INT == 4
98 typedef signed int int32_t;
99 typedef unsigned int uint32_t;
100 # else
101 #  if ARCH_SIZEOF_LONG == 4
102 typedef signed long int32_t;
103 typedef unsigned long uint32_t;
104 #  else
105 #   if ARCH_SIZEOF_SHORT == 4
106 typedef signed short int32_t;
107 typedef unsigned short uint32_t;
108 #   endif
109 #  endif
110 # endif
111 /* 64 bit types */
112 # if ARCH_SIZEOF_INT == 8
113 typedef signed int int64_t;
114 typedef unsigned int uint64_t;
115 # else
116 #  if ARCH_SIZEOF_LONG == 8
117 typedef signed long int64_t;
118 typedef unsigned long uint64_t;
119 #  else
120 #   ifdef ARCH_SIZEOF_LONG_LONG
121 #    if ARCH_SIZEOF_LONG_LONG == 8
122 typedef signed long long int64_t;
123 typedef unsigned long long uint64_t;
124 #    endif
125 #   endif
126 #  endif
127 # endif
128 #  define STDINT_TYPES_DEFINED
129 #endif /* STDINT_TYPES_DEFINED */
130 
131 #endif /* stdint__INCLUDED */
132