@@ -875,15 +875,14 @@ getVersionInfo(int verbose)
875875 * 1 if stdio is redirected to a console pipe, else 0 (and in this case, a file should be created)
876876 * Inspired of: https://fossies.org/linux/misc/vim-8.0.tar.bz2/vim80/src/iscygpty.c?m=t
877877 */
878- sqInt isFileDescriptorATTY (int fdNum ) {
878+ sqInt isFileDescriptorATTY (HANDLE fdHandle ) {
879879 //In case of Windows Shell case
880- int res = _isatty (fdNum );
880+ int res = _isatty (_fileno ( fdHandle ) );
881881 if (res != 0 )
882882 return res < 0 ;
883883 if (errno == EBADF )
884884 return 0 ;
885885 //In case of Unix emulator, we parse the name of the pipe
886- HANDLE h ;
887886 int size = sizeof (FILE_NAME_INFO ) + sizeof (WCHAR ) * MAX_PATH ;
888887 FILE_NAME_INFO * nameinfo ;
889888 WCHAR * p = NULL ;
@@ -901,20 +900,19 @@ sqInt isFileDescriptorATTY(int fdNum) {
901900 if (!pGetFileInformationByHandleEx )
902901 return 0 ;
903902 }
904- h = (HANDLE )_get_osfhandle (fdNum );
905- if (h == INVALID_HANDLE_VALUE ) {
903+ if (fdHandle == INVALID_HANDLE_VALUE ) {
906904 return 0 ;
907905 }
908906 /* Cygwin/msys's pty is a pipe. */
909- if (GetFileType (h ) != FILE_TYPE_PIPE ) {
907+ if (GetFileType (fdHandle ) != FILE_TYPE_PIPE ) {
910908 return 0 ;
911909 }
912910 nameinfo = malloc (size );
913911 if (nameinfo == NULL ) {
914912 return 0 ;
915913 }
916914 /* Check the name of the pipe: '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master' */
917- if (pGetFileInformationByHandleEx (h , FileNameInfo , nameinfo , size )) {
915+ if (pGetFileInformationByHandleEx (fdHandle , FileNameInfo , nameinfo , size )) {
918916 nameinfo -> FileName [nameinfo -> FileNameLength / sizeof (WCHAR )] = L'\0' ;
919917 p = nameinfo -> FileName ;
920918 //Check that the pipe name contains msys or cygwin
@@ -934,11 +932,7 @@ sqInt isFileDescriptorATTY(int fdNum) {
934932* 1 if one of the stdio is redirected to a console pipe, else 0 (and in this case, a file should be created)
935933*/
936934sqInt isOneStdioDescriptorATTY () {
937- int ret = 0 ;
938- for (int fd = 0 ; fd < 3 ; fd ++ ) {
939- ret |= isFileDescriptorATTY (fd );
940- }
941- return ret ;
935+ return isFileDescriptorATTY (STD_INPUT_HANDLE ) || isFileDescriptorATTY (STD_OUTPUT_HANDLE ) || isFileDescriptorATTY (STD_ERROR_HANDLE )
942936}
943937
944938static void
0 commit comments