diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/.gitattributes | 1 | ||||
-rw-r--r-- | compat/mingw.c | 8 | ||||
-rw-r--r-- | compat/unsetenv.c | 4 | ||||
-rw-r--r-- | compat/win32/lazyload.h | 6 | ||||
-rw-r--r-- | compat/win32/trace2_win32_process_info.c | 4 | ||||
-rw-r--r-- | compat/winansi.c | 5 | ||||
-rw-r--r-- | compat/zlib-uncompress2.c | 95 |
7 files changed, 113 insertions, 10 deletions
diff --git a/compat/.gitattributes b/compat/.gitattributes new file mode 100644 index 0000000000..40dbfb170d --- /dev/null +++ b/compat/.gitattributes @@ -0,0 +1 @@ +/zlib-uncompress2.c whitespace=-indent-with-non-tab,-trailing-space diff --git a/compat/mingw.c b/compat/mingw.c index 9e0cd1e097..640dcb11de 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -8,6 +8,8 @@ #include "win32/lazyload.h" #include "../config.h" #include "dir.h" +#define SECURITY_WIN32 +#include <sspi.h> #define HCAST(type, handle) ((type)(intptr_t)handle) @@ -1008,7 +1010,7 @@ size_t mingw_strftime(char *s, size_t max, /* a pointer to the original strftime in case we can't find the UCRT version */ static size_t (*fallback)(char *, size_t, const char *, const struct tm *) = strftime; size_t ret; - DECLARE_PROC_ADDR(ucrtbase.dll, size_t, strftime, char *, size_t, + DECLARE_PROC_ADDR(ucrtbase.dll, size_t, __cdecl, strftime, char *, size_t, const char *, const struct tm *); if (INIT_PROC_ADDR(strftime)) @@ -1083,6 +1085,7 @@ int pipe(int filedes[2]) return 0; } +#ifndef __MINGW64__ struct tm *gmtime_r(const time_t *timep, struct tm *result) { if (gmtime_s(result, timep) == 0) @@ -1096,6 +1099,7 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) return result; return NULL; } +#endif char *mingw_getcwd(char *pointer, int len) { @@ -2183,7 +2187,7 @@ enum EXTENDED_NAME_FORMAT { static char *get_extended_user_info(enum EXTENDED_NAME_FORMAT type) { - DECLARE_PROC_ADDR(secur32.dll, BOOL, GetUserNameExW, + DECLARE_PROC_ADDR(secur32.dll, BOOL, SEC_ENTRY, GetUserNameExW, enum EXTENDED_NAME_FORMAT, LPCWSTR, PULONG); static wchar_t wbuffer[1024]; DWORD len; diff --git a/compat/unsetenv.c b/compat/unsetenv.c index bf5fd7063b..b9d34af613 100644 --- a/compat/unsetenv.c +++ b/compat/unsetenv.c @@ -1,6 +1,6 @@ #include "../git-compat-util.h" -void gitunsetenv (const char *name) +int gitunsetenv(const char *name) { #if !defined(__MINGW32__) extern char **environ; @@ -24,4 +24,6 @@ void gitunsetenv (const char *name) ++dst; } environ[dst] = NULL; + + return 0; } diff --git a/compat/win32/lazyload.h b/compat/win32/lazyload.h index 2b3637135f..f2bb96c89c 100644 --- a/compat/win32/lazyload.h +++ b/compat/win32/lazyload.h @@ -4,7 +4,7 @@ /* * A pair of macros to simplify loading of DLL functions. Example: * - * DECLARE_PROC_ADDR(kernel32.dll, BOOL, CreateHardLinkW, + * DECLARE_PROC_ADDR(kernel32.dll, BOOL, WINAPI, CreateHardLinkW, * LPCWSTR, LPCWSTR, LPSECURITY_ATTRIBUTES); * * if (!INIT_PROC_ADDR(CreateHardLinkW)) @@ -25,10 +25,10 @@ struct proc_addr { }; /* Declares a function to be loaded dynamically from a DLL. */ -#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \ +#define DECLARE_PROC_ADDR(dll, rettype, convention, function, ...) \ static struct proc_addr proc_addr_##function = \ { #dll, #function, NULL, 0 }; \ - typedef rettype (WINAPI *proc_type_##function)(__VA_ARGS__); \ + typedef rettype (convention *proc_type_##function)(__VA_ARGS__); \ static proc_type_##function function /* diff --git a/compat/win32/trace2_win32_process_info.c b/compat/win32/trace2_win32_process_info.c index 8ccbd1c2c6..a53fd92434 100644 --- a/compat/win32/trace2_win32_process_info.c +++ b/compat/win32/trace2_win32_process_info.c @@ -143,8 +143,8 @@ static void get_is_being_debugged(void) */ static void get_peak_memory_info(void) { - DECLARE_PROC_ADDR(psapi.dll, BOOL, GetProcessMemoryInfo, HANDLE, - PPROCESS_MEMORY_COUNTERS, DWORD); + DECLARE_PROC_ADDR(psapi.dll, BOOL, WINAPI, GetProcessMemoryInfo, + HANDLE, PPROCESS_MEMORY_COUNTERS, DWORD); if (INIT_PROC_ADDR(GetProcessMemoryInfo)) { PROCESS_MEMORY_COUNTERS pmc; diff --git a/compat/winansi.c b/compat/winansi.c index c27b20a79d..4fceecf14c 100644 --- a/compat/winansi.c +++ b/compat/winansi.c @@ -45,8 +45,9 @@ typedef struct _CONSOLE_FONT_INFOEX { static void warn_if_raster_font(void) { DWORD fontFamily = 0; - DECLARE_PROC_ADDR(kernel32.dll, BOOL, GetCurrentConsoleFontEx, - HANDLE, BOOL, PCONSOLE_FONT_INFOEX); + DECLARE_PROC_ADDR(kernel32.dll, BOOL, WINAPI, + GetCurrentConsoleFontEx, HANDLE, BOOL, + PCONSOLE_FONT_INFOEX); /* don't bother if output was ascii only */ if (!non_ascii_used) diff --git a/compat/zlib-uncompress2.c b/compat/zlib-uncompress2.c new file mode 100644 index 0000000000..722610b971 --- /dev/null +++ b/compat/zlib-uncompress2.c @@ -0,0 +1,95 @@ +/* taken from zlib's uncompr.c + + commit cacf7f1d4e3d44d871b605da3b647f07d718623f + Author: Mark Adler <madler@alumni.caltech.edu> + Date: Sun Jan 15 09:18:46 2017 -0800 + + zlib 1.2.11 + +*/ + +#include "../reftable/system.h" +#define z_const + +/* + * Copyright (C) 1995-2003, 2010, 2014, 2016 Jean-loup Gailly, Mark Adler + * For conditions of distribution and use, see copyright notice in zlib.h + */ + +#include <zlib.h> + +/* clang-format off */ + +/* =========================================================================== + Decompresses the source buffer into the destination buffer. *sourceLen is + the byte length of the source buffer. Upon entry, *destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, + *destLen is the size of the decompressed data and *sourceLen is the number + of source bytes consumed. Upon return, source + *sourceLen points to the + first unused input byte. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, or + Z_DATA_ERROR if the input data was corrupted, including if the input data is + an incomplete zlib stream. +*/ +int ZEXPORT uncompress2 ( + Bytef *dest, + uLongf *destLen, + const Bytef *source, + uLong *sourceLen) { + z_stream stream; + int err; + const uInt max = (uInt)-1; + uLong len, left; + Byte buf[1]; /* for detection of incomplete stream when *destLen == 0 */ + + len = *sourceLen; + if (*destLen) { + left = *destLen; + *destLen = 0; + } + else { + left = 1; + dest = buf; + } + + stream.next_in = (z_const Bytef *)source; + stream.avail_in = 0; + stream.zalloc = (alloc_func)0; + stream.zfree = (free_func)0; + stream.opaque = (voidpf)0; + + err = inflateInit(&stream); + if (err != Z_OK) return err; + + stream.next_out = dest; + stream.avail_out = 0; + + do { + if (stream.avail_out == 0) { + stream.avail_out = left > (uLong)max ? max : (uInt)left; + left -= stream.avail_out; + } + if (stream.avail_in == 0) { + stream.avail_in = len > (uLong)max ? max : (uInt)len; + len -= stream.avail_in; + } + err = inflate(&stream, Z_NO_FLUSH); + } while (err == Z_OK); + + *sourceLen -= len + stream.avail_in; + if (dest != buf) + *destLen = stream.total_out; + else if (stream.total_out && err == Z_BUF_ERROR) + left = 1; + + inflateEnd(&stream); + return err == Z_STREAM_END ? Z_OK : + err == Z_NEED_DICT ? Z_DATA_ERROR : + err == Z_BUF_ERROR && left + stream.avail_out ? Z_DATA_ERROR : + err; +} |