annotate src/iscygpty.c @ 12301:93155ae168fb v8.0.1030

patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty() commit https://github.com/vim/vim/commit/9e8dcf9d6fa15523800005a32d40cf0382178ab0 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Aug 31 21:35:45 2017 +0200 patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty() Problem: MS-Windows: wrong size computation in is_cygpty(). Solution: Compute the size properly. (Ken Takata)
author Christian Brabandt <cb@256bit.org>
date Thu, 31 Aug 2017 21:45:04 +0200
parents 4aead6a9b7a9
children 8412df1479a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /*
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 * iscygpty.c -- part of ptycheck
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * https://github.com/k-takata/ptycheck
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
5 * Copyright (c) 2015-2017 K.Takata
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 *
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * You can redistribute it and/or modify it under the terms of either
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 * the MIT license (as described below) or the Vim license.
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 *
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 * Permission is hereby granted, free of charge, to any person obtaining
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * a copy of this software and associated documentation files (the
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 * "Software"), to deal in the Software without restriction, including
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 * without limitation the rights to use, copy, modify, merge, publish,
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 * distribute, sublicense, and/or sell copies of the Software, and to
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 * permit persons to whom the Software is furnished to do so, subject to
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 * the following conditions:
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 *
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 * The above copyright notice and this permission notice shall be
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 * included in all copies or substantial portions of the Software.
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 *
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
30 #ifdef _WIN32
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
31
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 #include <ctype.h>
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 #include <io.h>
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 #include <wchar.h>
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 #include <windows.h>
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 #ifdef USE_FILEEXTD
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 /* VC 7.1 or earlier doesn't support SAL. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 # if !defined(_MSC_VER) || (_MSC_VER < 1400)
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 # define __out
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 # define __in
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 # define __in_opt
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 # endif
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 /* Win32 FileID API Library:
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 * http://www.microsoft.com/en-us/download/details.aspx?id=22599
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 * Needed for WinXP. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 # include <fileextd.h>
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 #else /* USE_FILEEXTD */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 /* VC 8 or earlier. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 # if defined(_MSC_VER) && (_MSC_VER < 1500)
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 # ifdef ENABLE_STUB_IMPL
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 # define STUB_IMPL
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 # else
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 # error "Win32 FileID API Library is required for VC2005 or earlier."
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55 # endif
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
56 # endif
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
57 #endif /* USE_FILEEXTD */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
58
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
59
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
60 #include "iscygpty.h"
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
61
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
62 //#define USE_DYNFILEID
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
63 #ifdef USE_DYNFILEID
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
64 typedef BOOL (WINAPI *pfnGetFileInformationByHandleEx)(
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
65 HANDLE hFile,
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
66 FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
67 LPVOID lpFileInformation,
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
68 DWORD dwBufferSize
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
69 );
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70 static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
71
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
72 # ifndef USE_FILEEXTD
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
73 static BOOL WINAPI stub_GetFileInformationByHandleEx(
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
74 HANDLE hFile,
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
75 FILE_INFO_BY_HANDLE_CLASS FileInformationClass,
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
76 LPVOID lpFileInformation,
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
77 DWORD dwBufferSize
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
78 )
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
79 {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
80 return FALSE;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
81 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
82 # endif
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
83
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
84 static void setup_fileid_api(void)
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
85 {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
86 if (pGetFileInformationByHandleEx != NULL) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
87 return;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
88 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
89 pGetFileInformationByHandleEx = (pfnGetFileInformationByHandleEx)
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
90 GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")),
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
91 "GetFileInformationByHandleEx");
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
92 if (pGetFileInformationByHandleEx == NULL) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
93 # ifdef USE_FILEEXTD
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
94 pGetFileInformationByHandleEx = GetFileInformationByHandleEx;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
95 # else
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
96 pGetFileInformationByHandleEx = stub_GetFileInformationByHandleEx;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
97 # endif
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
98 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
99 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
100 #else
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
101 # define pGetFileInformationByHandleEx GetFileInformationByHandleEx
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
102 # define setup_fileid_api()
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
103 #endif
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
104
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
105
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
106 #define is_wprefix(s, prefix) \
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
107 (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0)
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
108
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
109 /* Check if the fd is a cygwin/msys's pty. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
110 int is_cygpty(int fd)
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
111 {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
112 #ifdef STUB_IMPL
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
113 return 0;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
114 #else
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
115 HANDLE h;
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
116 int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * (MAX_PATH - 1);
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
117 FILE_NAME_INFO *nameinfo;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
118 WCHAR *p = NULL;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
119
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
120 setup_fileid_api();
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
121
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
122 h = (HANDLE) _get_osfhandle(fd);
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
123 if (h == INVALID_HANDLE_VALUE) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
124 return 0;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
125 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
126 /* Cygwin/msys's pty is a pipe. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
127 if (GetFileType(h) != FILE_TYPE_PIPE) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
128 return 0;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
129 }
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
130 nameinfo = malloc(size + sizeof(WCHAR));
9363
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
131 if (nameinfo == NULL) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
132 return 0;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
133 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
134 /* Check the name of the pipe:
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
135 * '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
136 if (pGetFileInformationByHandleEx(h, FileNameInfo, nameinfo, size)) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
137 nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0';
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
138 p = nameinfo->FileName;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 p += 8;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 } else if (is_wprefix(p, L"\\msys-")) { /* MSYS and MSYS2 */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 p += 6;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
143 } else {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 p = NULL;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
145 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 if (p != NULL) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 while (*p && isxdigit(*p)) /* Skip 16-digit hexadecimal. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 ++p;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 if (is_wprefix(p, L"-pty")) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 p += 4;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 } else {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
152 p = NULL;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
153 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 if (p != NULL) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 while (*p && isdigit(*p)) /* Skip pty number. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
157 ++p;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
158 if (is_wprefix(p, L"-from-master")) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
159 //p += 12;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
160 } else if (is_wprefix(p, L"-to-master")) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161 //p += 10;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 } else {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 p = NULL;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 free(nameinfo);
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 return (p != NULL);
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 #endif /* STUB_IMPL */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 /* Check if at least one cygwin/msys pty is used. */
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 int is_cygpty_used(void)
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 int fd, ret = 0;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
176
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
177 for (fd = 0; fd < 3; fd++) {
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
178 ret |= is_cygpty(fd);
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
179 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
180 return ret;
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
181 }
f9dda6450c76 commit https://github.com/vim/vim/commit/97ff9b9cffd97219d888874b9b3811d55e99c78f
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
182
12301
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
183 #endif /* _WIN32 */
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
184
93155ae168fb patch 8.0.1030: MS-Windows: wrong size computation in is_cygpty()
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
185 /* vim: set ts=4 sw=4: */