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]))
40 #include <sys/utime.h>
45 /* MSVC defines mkdir here, not in io.h */
51 * with MSVC, if we define _POSIX_ we loose half of useful functions
52 * (e.g. chmod, open, close), otherwise we don't have PATH_MAX
53 * because of #ifdef in <io.h>.
54 * So, when build under MSVC, don't define _POSIX_
59 /* from mingw/include/sys/types.h */
62 typedef long _ssize_t
;
65 typedef _ssize_t ssize_t
;
67 #endif /* Not _SSIZE_T_ */
71 typedef unsigned short _mode_t
;
74 typedef _mode_t mode_t
;
76 #endif /* Not _MODE_T_ */
79 /* from mingw/include/io.h */
80 /* Some defines for _access nAccessMode (MS doesn't define them, but
81 * it doesn't seem to hurt to add them). */
82 #define F_OK 0 /* Check for file existence */
83 /* Well maybe it does hurt. On newer versions of MSVCRT, an access mode
84 of 1 causes invalid parameter error. */
85 #define X_OK 1 /* MS access() doesn't check for execute permission. */
86 #define W_OK 2 /* Check for write permission */
87 #define R_OK 4 /* Check for read permission */
89 /* from mingw/include/string.h */
90 #define strcasecmp(__sz1, __sz2) (_stricmp((__sz1), (__sz2)))
92 /* from mingw/include/stdint.h */
93 typedef unsigned uint32_t;
96 #define NORETURN __attribute__((__noreturn__))
100 #define NORETURN __declspec(noreturn)
103 #endif /* _MSC_VER */
105 #ifndef __attribute__
106 #define __attribute__(x)
111 extern int error(const char * format
, ...);
112 extern NORETURN
void die(const char *err
, ...) __attribute__((format (printf
, 1, 2)));
114 #ifndef HAVE_STRCHRNUL
115 #define strchrnul gitstrchrnul
116 static inline char *gitstrchrnul(const char *s
, int c
)
118 while (*s
&& *s
!= c
)
124 extern time_t tm_to_time_t(const struct tm
*tm
);
126 extern void release_pack_memory(size_t, int);
128 extern char *xstrdup(const char *str
);
129 extern void *xmalloc(size_t size
);
130 extern void *xrealloc(void *ptr
, size_t size
);
131 extern void *xcalloc(size_t nmemb
, size_t size
);
132 extern ssize_t
xread(int fd
, void *buf
, size_t len
);
135 #define strlcpy gitstrlcpy
136 extern size_t gitstrlcpy(char *, const char *, size_t);
139 #define snprintf _snprintf
146 #define MAP_PRIVATE 1
147 #define MAP_FAILED ((void*)-1)
150 #define mmap git_mmap
151 #define munmap git_munmap
152 extern void *git_mmap(void *start
, size_t length
, int prot
, int flags
, int fd
, off_t offset
);
153 extern int git_munmap(void *start
, size_t length
);
155 /* This value must be multiple of (pagesize * 2) */
156 #define DEFAULT_PACKED_GIT_WINDOW_SIZE (1 * 1024 * 1024)
160 #include <sys/mman.h>
162 /* This value must be multiple of (pagesize * 2) */
163 #define DEFAULT_PACKED_GIT_WINDOW_SIZE \
164 (sizeof(void*) >= 8 \
165 ? 1 * 1024 * 1024 * 1024 \
171 #define pread git_pread
172 extern ssize_t
git_pread(int fd
, void *buf
, size_t count
, off_t offset
);
175 * Forward decl that will remind us if its twin in cache.h changes.
176 * This function is used in compat/pread.c. But we can't include
179 extern ssize_t
read_in_full(int fd
, void *buf
, size_t count
);
181 #include "compat/mingw.h"