Skip to content

Commit 07d066e

Browse files
committed
Merge branch 'mingw-getcwd'
Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 0d438c7 + aaaa1c1 commit 07d066e

File tree

5 files changed

+68
-11
lines changed

5 files changed

+68
-11
lines changed

compat/mingw.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,31 @@ static int ask_yes_no_if_possible(const char *format, ...)
202202
}
203203
}
204204

205+
/* Normalizes NT paths as returned by some low-level APIs. */
206+
static wchar_t *normalize_ntpath(wchar_t *wbuf)
207+
{
208+
int i;
209+
/* fix absolute path prefixes */
210+
if (wbuf[0] == '\\') {
211+
/* strip NT namespace prefixes */
212+
if (!wcsncmp(wbuf, L"\\??\\", 4) ||
213+
!wcsncmp(wbuf, L"\\\\?\\", 4))
214+
wbuf += 4;
215+
else if (!wcsnicmp(wbuf, L"\\DosDevices\\", 12))
216+
wbuf += 12;
217+
/* replace remaining '...UNC\' with '\\' */
218+
if (!wcsnicmp(wbuf, L"UNC\\", 4)) {
219+
wbuf += 2;
220+
*wbuf = '\\';
221+
}
222+
}
223+
/* convert backslashes to slashes */
224+
for (i = 0; wbuf[i]; i++)
225+
if (wbuf[i] == '\\')
226+
wbuf[i] = '/';
227+
return wbuf;
228+
}
229+
205230
int mingw_unlink(const char *pathname)
206231
{
207232
int ret, tries = 0;
@@ -887,8 +912,29 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
887912

888913
char *mingw_getcwd(char *pointer, int len)
889914
{
890-
wchar_t wpointer[MAX_PATH];
891-
if (!_wgetcwd(wpointer, ARRAY_SIZE(wpointer)))
915+
wchar_t cwd[MAX_PATH], wpointer[MAX_PATH];
916+
DWORD ret = GetCurrentDirectoryW(ARRAY_SIZE(cwd), cwd);
917+
918+
if (!ret || ret >= ARRAY_SIZE(cwd)) {
919+
errno = ret ? ENAMETOOLONG : err_win_to_posix(GetLastError());
920+
return NULL;
921+
}
922+
ret = GetLongPathNameW(cwd, wpointer, ARRAY_SIZE(wpointer));
923+
if (!ret && GetLastError() == ERROR_ACCESS_DENIED) {
924+
HANDLE hnd = CreateFileW(cwd, 0,
925+
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
926+
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
927+
if (hnd == INVALID_HANDLE_VALUE)
928+
return NULL;
929+
ret = GetFinalPathNameByHandleW(hnd, wpointer, ARRAY_SIZE(wpointer), 0);
930+
CloseHandle(hnd);
931+
if (!ret || ret >= ARRAY_SIZE(wpointer))
932+
return NULL;
933+
if (xwcstoutf(pointer, normalize_ntpath(wpointer), len) < 0)
934+
return NULL;
935+
return pointer;
936+
}
937+
if (!ret || ret >= ARRAY_SIZE(wpointer))
892938
return NULL;
893939
if (xwcstoutf(pointer, wpointer, len) < 0)
894940
return NULL;

compat/poll/poll.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
#include <sys/types.h>
3131

32-
/* Specification. */
33-
#include <poll.h>
34-
3532
#include <errno.h>
3633
#include <limits.h>
3734
#include <assert.h>
@@ -55,6 +52,9 @@
5552
# include <unistd.h>
5653
#endif
5754

55+
/* Specification. */
56+
#include "poll.h"
57+
5858
#ifdef HAVE_SYS_IOCTL_H
5959
# include <sys/ioctl.h>
6060
#endif

compat/poll/poll.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,21 @@
2121
#ifndef _GL_POLL_H
2222
#define _GL_POLL_H
2323

24+
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600
25+
/* Vista has its own, socket-only poll() */
26+
#undef POLLIN
27+
#undef POLLPRI
28+
#undef POLLOUT
29+
#undef POLLERR
30+
#undef POLLHUP
31+
#undef POLLNVAL
32+
#undef POLLRDNORM
33+
#undef POLLRDBAND
34+
#undef POLLWRNORM
35+
#undef POLLWRBAND
36+
#define pollfd compat_pollfd
37+
#endif
38+
2439
/* fake a poll(2) environment */
2540
#define POLLIN 0x0001 /* any readable data available */
2641
#define POLLPRI 0x0002 /* OOB/Urgent readable data */

config.mak.uname

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ ifeq ($(uname_S),Windows)
381381
NO_PYTHON = YesPlease
382382
BLK_SHA1 = YesPlease
383383
ETAGS_TARGET = ETAGS
384-
NO_INET_PTON = YesPlease
385-
NO_INET_NTOP = YesPlease
386384
NO_POSIX_GOODIES = UnfortunatelyYes
387385
NATIVE_CRLF = YesPlease
388386
DEFAULT_HELP_FORMAT = html
@@ -529,8 +527,6 @@ ifneq (,$(findstring MINGW,$(uname_S)))
529527
NO_REGEX = YesPlease
530528
NO_PYTHON = YesPlease
531529
ETAGS_TARGET = ETAGS
532-
NO_INET_PTON = YesPlease
533-
NO_INET_NTOP = YesPlease
534530
NO_POSIX_GOODIES = UnfortunatelyYes
535531
DEFAULT_HELP_FORMAT = html
536532
COMPAT_CFLAGS += -DNOGDI -Icompat -Icompat/win32

git-compat-util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@
146146
#define _SGI_SOURCE 1
147147

148148
#if defined(WIN32) && !defined(__CYGWIN__) /* Both MinGW and MSVC */
149-
# if defined (_MSC_VER) && !defined(_WIN32_WINNT)
150-
# define _WIN32_WINNT 0x0502
149+
# if !defined(_WIN32_WINNT)
150+
# define _WIN32_WINNT 0x0600
151151
# endif
152152
#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */
153153
#include <winsock2.h>

0 commit comments

Comments
 (0)