• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2    libconfig - A library for processing structured configuration files
3    Copyright (C) 2005-2018  Mark A Lindner
4 
5    This file is part of libconfig.
6 
7    This library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Lesser General Public License
9    as published by the Free Software Foundation; either version 2.1 of
10    the License, or (at your option) any later version.
11 
12    This library is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    Lesser General Public License for more details.
16 
17    You should have received a copy of the GNU Library General Public
18    License along with this library; if not, see
19    <http://www.gnu.org/licenses/>.
20    ----------------------------------------------------------------------------
21 */
22 
23 #ifndef __wincompat_h
24 #define __wincompat_h
25 
26 #include <limits.h>
27 
28 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
29   || defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
30 
31 /* Prevent warnings about redefined malloc/free in generated code. */
32 #ifndef _STDLIB_H
33 #define _STDLIB_H
34 #endif
35 
36 #include <malloc.h>
37 
38 #ifdef _MSC_VER
39 #pragma warning (disable: 4996)
40 #endif
41 
42 #define WIN32_LEAN_AND_MEAN
43 #include <windows.h>
44 
45 #define fileno _fileno
46 
47 #if _MSC_VER <= 1800
48 #define snprintf  _snprintf
49 #endif
50 
51 #if !defined(__MINGW32__) && _MSC_VER < 1800
52 #define atoll     _atoi64
53 #define strtoull  _strtoui64
54 #define strtoll   _strtoi64
55 #endif
56 
57 #if !defined(S_ISDIR) && defined(S_IFMT) && defined(S_IFDIR)
58 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
59 #endif
60 
61 #endif
62 
63 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
64   || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) \
65   || defined(__MINGW32__))
66 
67 #define INT64_FMT "%I64d"
68 #define UINT64_FMT "%I64u"
69 
70 #define INT64_HEX_FMT "%I64X"
71 
72 #define FILE_SEPARATOR "\\"
73 
74 #else /* defined(WIN32) || defined(__MINGW32__) */
75 
76 #define INT64_FMT "%lld"
77 #define UINT64_FMT "%llu"
78 
79 #define INT64_HEX_FMT "%llX"
80 
81 #define FILE_SEPARATOR "/"
82 
83 #endif /* defined(WIN32) || defined(__MINGW32__) */
84 
85 #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) \
86   || defined(WIN64) || defined(_WIN64) || defined(__WIN64__)) \
87   && ! defined(__MINGW32__)
88 
89 #define INT64_CONST(I)  (I ## i64)
90 #define UINT64_CONST(I) (I ## Ui64)
91 
92 #ifndef INT_MAX
93 #define INT_MAX (2147483647)
94 #endif
95 
96 #ifndef INT_MIN
97 #define INT_MIN (-2147483647-1)
98 #endif
99 
100 #include <Shlwapi.h>
101 #define IS_RELATIVE_PATH(P) \
102   (PathIsRelativeA(P))
103 
104 extern int fsync(int fd);
105 
106 #else /* defined(WIN32/WIN64) && ! defined(__MINGW32__) */
107 
108 #define INT64_CONST(I)  (I ## LL)
109 #define UINT64_CONST(I) (I ## ULL)
110 
111 #define IS_RELATIVE_PATH(P) \
112   ((P)[0] != '/')
113 
114 #include <unistd.h> /* for fsync() */
115 
116 #endif /* defined(WIN32/WIN64) && ! defined(__MINGW32__) */
117 
118 #endif /* __wincompat_h */
119