1335640Shselasky/*
2335640Shselasky * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
3335640Shselasky * Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California)
4335640Shselasky * All rights reserved.
5335640Shselasky *
6335640Shselasky * Redistribution and use in source and binary forms, with or without
7335640Shselasky * modification, are permitted provided that the following conditions
8335640Shselasky * are met:
9335640Shselasky *
10335640Shselasky * 1. Redistributions of source code must retain the above copyright
11335640Shselasky * notice, this list of conditions and the following disclaimer.
12335640Shselasky * 2. Redistributions in binary form must reproduce the above copyright
13335640Shselasky * notice, this list of conditions and the following disclaimer in the
14335640Shselasky * documentation and/or other materials provided with the distribution.
15335640Shselasky * 3. Neither the name of the Politecnico di Torino nor the names of its
16335640Shselasky * contributors may be used to endorse or promote products derived from
17335640Shselasky * this software without specific prior written permission.
18335640Shselasky *
19335640Shselasky * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20335640Shselasky * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21335640Shselasky * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22335640Shselasky * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23335640Shselasky * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24335640Shselasky * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25335640Shselasky * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26335640Shselasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27335640Shselasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28335640Shselasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29335640Shselasky * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30335640Shselasky */
31335640Shselasky#ifndef pcap_pcap_inttypes_h
32335640Shselasky#define pcap_pcap_inttypes_h
33335640Shselasky
34335640Shselasky/*
35335640Shselasky * Get the integer types and PRi[doux]64 values from C99 <inttypes.h>
36335640Shselasky * defined, by hook or by crook.
37335640Shselasky */
38335640Shselasky#if defined(_MSC_VER)
39335640Shselasky  /*
40335640Shselasky   * Compiler is MSVC.
41335640Shselasky   */
42335640Shselasky  #if _MSC_VER >= 1800
43335640Shselasky    /*
44335640Shselasky     * VS 2013 or newer; we have <inttypes.h>.
45335640Shselasky     */
46335640Shselasky    #include <inttypes.h>
47335640Shselasky  #else
48335640Shselasky    /*
49335640Shselasky     * Earlier VS; we have to define this stuff ourselves.
50335640Shselasky     */
51335640Shselasky    typedef unsigned char uint8_t;
52335640Shselasky    typedef signed char int8_t;
53335640Shselasky    typedef unsigned short uint16_t;
54335640Shselasky    typedef signed short int16_t;
55335640Shselasky    typedef unsigned int uint32_t;
56335640Shselasky    typedef signed int int32_t;
57335640Shselasky    #ifdef _MSC_EXTENSIONS
58335640Shselasky      typedef unsigned _int64 uint64_t;
59335640Shselasky      typedef _int64 int64_t;
60335640Shselasky    #else /* _MSC_EXTENSIONS */
61335640Shselasky      typedef unsigned long long uint64_t;
62335640Shselasky      typedef long long int64_t;
63335640Shselasky    #endif
64335640Shselasky  #endif
65335640Shselasky
66335640Shselasky  /*
67335640Shselasky   * These may be defined by <inttypes.h>.
68335640Shselasky   *
69335640Shselasky   * XXX - for MSVC, we always want the _MSC_EXTENSIONS versions.
70335640Shselasky   * What about other compilers?  If, as the MinGW Web site says MinGW
71335640Shselasky   * does, the other compilers just use Microsoft's run-time library,
72335640Shselasky   * then they should probably use the _MSC_EXTENSIONS even if the
73335640Shselasky   * compiler doesn't define _MSC_EXTENSIONS.
74335640Shselasky   *
75335640Shselasky   * XXX - we currently aren't using any of these, but this allows
76335640Shselasky   * their use in the future.
77335640Shselasky   */
78335640Shselasky  #ifndef PRId64
79335640Shselasky    #ifdef _MSC_EXTENSIONS
80335640Shselasky      #define PRId64	"I64d"
81335640Shselasky    #else
82335640Shselasky      #define PRId64	"lld"
83335640Shselasky    #endif
84335640Shselasky  #endif /* PRId64 */
85335640Shselasky
86335640Shselasky  #ifndef PRIo64
87335640Shselasky    #ifdef _MSC_EXTENSIONS
88335640Shselasky      #define PRIo64	"I64o"
89335640Shselasky    #else
90335640Shselasky      #define PRIo64	"llo"
91335640Shselasky    #endif
92335640Shselasky  #endif /* PRIo64 */
93335640Shselasky
94335640Shselasky  #ifndef PRIx64
95335640Shselasky    #ifdef _MSC_EXTENSIONS
96335640Shselasky      #define PRIx64	"I64x"
97335640Shselasky    #else
98335640Shselasky      #define PRIx64	"llx"
99335640Shselasky    #endif
100335640Shselasky  #endif
101335640Shselasky
102335640Shselasky  #ifndef PRIu64
103335640Shselasky    #ifdef _MSC_EXTENSIONS
104335640Shselasky      #define PRIu64	"I64u"
105335640Shselasky    #else
106335640Shselasky      #define PRIu64	"llu"
107335640Shselasky    #endif
108335640Shselasky  #endif
109356341Scy
110356341Scy  /*
111356341Scy   * MSVC's support library doesn't support %zu to print a size_t until
112356341Scy   * Visual Studio 2017, but supports %Iu earlier, so use that.
113356341Scy   */
114356341Scy  #define PRIsize	"Iu"
115335640Shselasky#elif defined(__MINGW32__) || !defined(_WIN32)
116335640Shselasky  /*
117335640Shselasky   * Compiler is MinGW or target is UN*X or MS-DOS.  Just use
118335640Shselasky   * <inttypes.h>.
119335640Shselasky   */
120335640Shselasky  #include <inttypes.h>
121356341Scy
122356341Scy  /*
123356341Scy   * Assume the support library supports %zu; it's required by C99.
124356341Scy   */
125356341Scy  #define PRIsize	"zu"
126335640Shselasky#endif
127335640Shselasky
128335640Shselasky#endif /* pcap/pcap-inttypes.h */
129