1 #ifndef GIT_COMPAT_UTIL_H
2 #define GIT_COMPAT_UTIL_H
6 * See if our compiler is known to support flexible array members.
8 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
9 # define FLEX_ARRAY /* empty */
10 #elif defined(__GNUC__)
12 # define FLEX_ARRAY /* empty */
14 # define FLEX_ARRAY 0 /* older GNU extension */
16 #elif defined(_MSC_VER)
17 #define FLEX_ARRAY /* empty */
21 * Otherwise, default to safer but a bit wasteful traditional style
28 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
43 #include <sys/utime.h>
51 /* MSVC defines mkdir here, not in io.h */
57 * with MSVC, if we define _POSIX_ we loose half of useful functions
58 * (e.g. chmod, open, close), otherwise we don't have PATH_MAX
59 * because of #ifdef in <io.h>.
60 * So, when build under MSVC, don't define _POSIX_
66 #ifdef _SSIZE_T_DEFINED
70 /* from mingw/include/sys/types.h */
73 typedef long _ssize_t
;
76 typedef _ssize_t ssize_t
;
78 #endif /* Not _SSIZE_T_ */
81 typedef unsigned short _mode_t
;
84 typedef _mode_t mode_t
;
86 #endif /* Not _MODE_T_ */
89 /* from mingw/include/io.h */
90 /* Some defines for _access nAccessMode (MS doesn't define them, but
91 * it doesn't seem to hurt to add them). */
92 #define F_OK 0 /* Check for file existence */
93 /* Well maybe it does hurt. On newer versions of MSVCRT, an access mode
94 of 1 causes invalid parameter error. */
95 #define X_OK 1 /* MS access() doesn't check for execute permission. */
96 #define W_OK 2 /* Check for write permission */
97 #define R_OK 4 /* Check for read permission */
100 /* from mingw/include/string.h */
101 #define strcasecmp(__sz1, __sz2) (_stricmp((__sz1), (__sz2)))
103 /* from mingw/include/stdint.h */
104 typedef unsigned uint32_t;
107 #define NORETURN __attribute__((__noreturn__))
110 #if defined(_MSC_VER)
111 #define NORETURN __declspec(noreturn)
114 #endif /* _MSC_VER */
116 #ifndef __attribute__
117 #define __attribute__(x)
122 extern int error(const char * format
, ...);
123 extern NORETURN
void die(const char *err
, ...) __attribute__((format (printf
, 1, 2)));
125 #ifndef HAVE_STRCHRNUL
126 #define strchrnul gitstrchrnul
127 static inline char *gitstrchrnul(const char *s
, int c
)
129 while (*s
&& *s
!= c
)
135 extern time_t tm_to_time_t(const struct tm
*tm
);
137 extern void release_pack_memory(size_t, int);
139 extern char *xstrdup(const char *str
);
140 extern void *xmalloc(size_t size
);
141 extern void *xrealloc(void *ptr
, size_t size
);
142 extern void *xcalloc(size_t nmemb
, size_t size
);
143 extern ssize_t
xread(int fd
, void *buf
, size_t len
);
146 #define strlcpy gitstrlcpy
147 extern size_t gitstrlcpy(char *, const char *, size_t);
151 #define snprintf _snprintf
159 #define MAP_PRIVATE 1
160 #define MAP_FAILED ((void*)-1)
163 #define mmap git_mmap
164 #define munmap git_munmap
165 extern void *git_mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
);
166 extern int git_munmap(void *start
, size_t length
);
168 /* This value must be multiple of (pagesize * 2) */
169 #define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
173 #include <sys/mman.h>
175 /* This value must be multiple of (pagesize * 2) */
176 #define DEFAULT_PACKED_GIT_WINDOW_SIZE \
177 (sizeof(void*) >= 8 \
178 ? 1 * 1024 * 1024 * 1024 \
184 #define pread git_pread
185 extern ssize_t
git_pread(int fd
, void *buf
, size_t count
, off_t offset
);
188 * Forward decl that will remind us if its twin in cache.h changes.
189 * This function is used in compat/pread.c. But we can't include
192 extern ssize_t
read_in_full(int fd
, void *buf
, size_t count
);
195 #include "../compat/mingw.h"
198 /* some defines not available on osx */
200 #define MAX_PATH PATH_MAX
216 #define UINT unsigned int
220 #define PATH_SEPERATOR '\\'
223 /* default PATH_SEPERATOR is / */
224 #ifndef PATH_SEPERATOR
225 #define PATH_SEPERATOR '/'