22 * iscygpty.c -- part of ptycheck
33 * https://github.com/k-takata/ptycheck
44 *
5- * Copyright (c) 2015-2017 K.Takata
5+ * Copyright (c) 2015-2023 K.Takata
66 *
77 * You can redistribute it and/or modify it under the terms of either
88 * the MIT license (as described below) or the Vim license.
3535#include <windows.h>
3636
3737#ifdef USE_FILEEXTD
38- /* VC 7.1 or earlier doesn't support SAL. */
38+ // VC 7.1 or earlier doesn't support SAL.
3939# if !defined(_MSC_VER ) || (_MSC_VER < 1400 )
4040# define __out
4141# define __in
4242# define __in_opt
4343# endif
44- /* Win32 FileID API Library:
45- * http://www.microsoft.com/en-us/download/details.aspx?id=22599
46- * Needed for WinXP. */
44+ // Win32 FileID API Library:
45+ // http://www.microsoft.com/en-us/download/details.aspx?id=22599
46+ // Needed for WinXP.
4747# include <fileextd.h>
48- #else /* USE_FILEEXTD */
49- /* VC 8 or earlier. */
48+ #else // USE_FILEEXTD
49+ // VC 8 or earlier.
5050# if defined(_MSC_VER ) && (_MSC_VER < 1500 )
5151# ifdef ENABLE_STUB_IMPL
5252# define STUB_IMPL
5353# else
5454# error "Win32 FileID API Library is required for VC2005 or earlier."
5555# endif
5656# endif
57- #endif /* USE_FILEEXTD */
57+ #endif // USE_FILEEXTD
5858
59+ #ifdef __MINGW32__
60+ # define UNUSED __attribute__((unused))
61+ #else
62+ # define UNUSED
63+ #endif
5964
6065#include "iscygpty.h"
6166
6267//#define USE_DYNFILEID
6368#ifdef USE_DYNFILEID
6469typedef BOOL (WINAPI * pfnGetFileInformationByHandleEx )(
65- HANDLE hFile ,
66- FILE_INFO_BY_HANDLE_CLASS FileInformationClass ,
67- LPVOID lpFileInformation ,
68- DWORD dwBufferSize
69- );
70+ HANDLE hFile ,
71+ FILE_INFO_BY_HANDLE_CLASS FileInformationClass ,
72+ LPVOID lpFileInformation ,
73+ DWORD dwBufferSize );
7074static pfnGetFileInformationByHandleEx pGetFileInformationByHandleEx = NULL ;
7175
7276# ifndef USE_FILEEXTD
7377static BOOL WINAPI stub_GetFileInformationByHandleEx (
74- HANDLE hFile ,
75- FILE_INFO_BY_HANDLE_CLASS FileInformationClass ,
76- LPVOID lpFileInformation ,
77- DWORD dwBufferSize
78- )
78+ HANDLE hFile UNUSED ,
79+ FILE_INFO_BY_HANDLE_CLASS FileInformationClass UNUSED ,
80+ LPVOID lpFileInformation UNUSED ,
81+ DWORD dwBufferSize UNUSED )
7982{
8083 return FALSE;
8184}
@@ -106,14 +109,14 @@ static void setup_fileid_api(void)
106109#define is_wprefix (s , prefix ) \
107110 (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0)
108111
109- /* Check if the fd is a cygwin/msys's pty. */
112+ // Check if the fd is a cygwin/msys's pty.
110113int is_cygpty (int fd )
111114{
112115#ifdef STUB_IMPL
113116 return 0 ;
114117#else
115118 HANDLE h ;
116- int size = sizeof (FILE_NAME_INFO ) + sizeof (WCHAR ) * (MAX_PATH - 1 );
119+ const int size = sizeof (FILE_NAME_INFO ) + sizeof (WCHAR ) * (MAX_PATH - 1 );
117120 FILE_NAME_INFO * nameinfo ;
118121 WCHAR * p = NULL ;
119122
@@ -123,28 +126,29 @@ int is_cygpty(int fd)
123126 if (h == INVALID_HANDLE_VALUE ) {
124127 return 0 ;
125128 }
126- /* Cygwin/msys's pty is a pipe. */
129+ // Cygwin/msys's pty is a pipe.
127130 if (GetFileType (h ) != FILE_TYPE_PIPE ) {
128131 return 0 ;
129132 }
130133 nameinfo = malloc (size + sizeof (WCHAR ));
131134 if (nameinfo == NULL ) {
132135 return 0 ;
133136 }
134- /* Check the name of the pipe:
135- * '\ {cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' */
137+ // Check the name of the pipe:
138+ // "\\ {cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master"
136139 if (pGetFileInformationByHandleEx (h , FileNameInfo , nameinfo , size )) {
137140 nameinfo -> FileName [nameinfo -> FileNameLength / sizeof (WCHAR )] = L'\0' ;
138141 p = nameinfo -> FileName ;
139- if (is_wprefix (p , L"\\cygwin-" )) { /* Cygwin */
142+ if (is_wprefix (p , L"\\cygwin-" )) { // Cygwin
140143 p += 8 ;
141- } else if (is_wprefix (p , L"\\msys-" )) { /* MSYS and MSYS2 */
144+ } else if (is_wprefix (p , L"\\msys-" )) { // MSYS and MSYS2
142145 p += 6 ;
143146 } else {
144147 p = NULL ;
145148 }
146149 if (p != NULL ) {
147- while (* p && isxdigit (* p )) /* Skip 16-digit hexadecimal. */
150+ // Skip 16-digit hexadecimal.
151+ while (* p && iswascii (* p ) && isxdigit (* p ))
148152 ++ p ;
149153 if (is_wprefix (p , L"-pty" )) {
150154 p += 4 ;
@@ -153,7 +157,8 @@ int is_cygpty(int fd)
153157 }
154158 }
155159 if (p != NULL ) {
156- while (* p && isdigit (* p )) /* Skip pty number. */
160+ // Skip pty number.
161+ while (* p && iswascii (* p ) && isdigit (* p ))
157162 ++ p ;
158163 if (is_wprefix (p , L"-from-master" )) {
159164 //p += 12;
@@ -166,10 +171,10 @@ int is_cygpty(int fd)
166171 }
167172 free (nameinfo );
168173 return (p != NULL );
169- #endif /* STUB_IMPL */
174+ #endif // STUB_IMPL
170175}
171176
172- /* Check if at least one cygwin/msys pty is used. */
177+ // Check if at least one cygwin/msys pty is used.
173178int is_cygpty_used (void )
174179{
175180 int fd , ret = 0 ;
@@ -180,6 +185,6 @@ int is_cygpty_used(void)
180185 return ret ;
181186}
182187
183- #endif /* _WIN32 */
188+ #endif // _WIN32
184189
185- /* vim: set ts=4 sw=4: */
190+ // vim: set ts=4 sw=4:
0 commit comments