delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2015/06/02/12:50:33

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:cc:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=tE8MvG+eklE+tV9ocT0u5ygig+FbDmeE94u9PhoxEFHQbbPazwy7f
yviV45dW49xCeqhb/wAgIvu28NOom69xhbH31NHPbcHupmtyjwxb9ACBp/s3BNxv
Hlm/7N5gJ/vBimtQKXDbX1eGr/nFVNAbH0JsjIBGaH5k3Vvm7SfSns=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:cc:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=+ix7hfmknijWzjUhirw4TDKQLao=; b=g6753w9L3ZtVXe4nzu/muEFVgE/W
2jd4Zdxb0wXH15oMsWiT6C0/0V+Ijp2scOAiy29HZ6tezG1bsLPmdGYT0J4j8jmY
TVrrARzdRpUG/eMqx+c78dHroJA4XIZ17R51i5DCNGTEYu8LVC5n1vu2vC4CRlFm
mDLKXYBubvKaUgs=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL,BAYES_40,KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2
X-HELO: calimero.vinschen.de
Date: Tue, 2 Jun 2015 18:50:13 +0200
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Cc: Rich Eizenhoefer <riche AT microsoft DOT com>
Subject: Re: From Microsoft: Windows 10 Console and Cygwin
Message-ID: <20150602165013.GE741@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com, Rich Eizenhoefer <riche AT microsoft DOT com>
References: <BN3PR03MB14300D5567A2F7D86BB69A28B4D70 AT BN3PR03MB1430 DOT namprd03 DOT prod DOT outlook DOT com> <20150430082231 DOT GB19795 AT calimero DOT vinschen DOT de> <BN3PR03MB1430B88AED4339821C7D95BEB4D50 AT BN3PR03MB1430 DOT namprd03 DOT prod DOT outlook DOT com> <20150502133833 DOT GB12723 AT calimero DOT vinschen DOT de> <BN3PR03MB1430C0816A9D41BB051687A4B4D20 AT BN3PR03MB1430 DOT namprd03 DOT prod DOT outlook DOT com> <1433098286892-118602 DOT post AT n5 DOT nabble DOT com> <20150601082456 DOT GG4308 AT calimero DOT vinschen DOT de> <BN3PR03MB14303BAD46376DED807CFA2CB4B60 AT BN3PR03MB1430 DOT namprd03 DOT prod DOT outlook DOT com> <CAJ1KOAiG-VV2heqYSNSjwCb=s_pjxoxKaGY3SnDiy4E20yvOWw AT mail DOT gmail DOT com> <BN3PR03MB1430F49F8839B66558779F3AB4B50 AT BN3PR03MB1430 DOT namprd03 DOT prod DOT outlook DOT com>
MIME-Version: 1.0
In-Reply-To: <BN3PR03MB1430F49F8839B66558779F3AB4B50@BN3PR03MB1430.namprd03.prod.outlook.com>
User-Agent: Mutt/1.5.23 (2014-03-12)

--TD8GDToEDw0WLGOL
Content-Type: multipart/mixed; boundary="k4f25fnPtRuIRUb3"
Content-Disposition: inline


--k4f25fnPtRuIRUb3
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi Rich,

On Jun  2 16:37, Rich Eizenhoefer wrote:
> Can you provide more detail on changing isatty function to support
> Cygwin PTY's? I need to be able to support the request in our backlog.

As I outlined in https://cygwin.com/ml/cygwin/2015-05/msg00029.html,
I'm wondering if the MSVCRT guys would really like to support this,
but if they are willing to consider that, I have a POC implementation
of a MSVCRT isatty replacement implementation I once created for a
customer.  I attached it to this mail.  It's entirely self-written,
free for any usage, no strings attached.  Feel free to use it as you
see fit.


Thanks,
Corinna

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--k4f25fnPtRuIRUb3
Content-Type: text/plain; charset=utf-8
Content-Disposition: attachment; filename="isatty-for-native-apps.c"
Content-Transfer-Encoding: quoted-printable

#include <stdio.h>
#include <io.h>

#include <errno.h>
#include <wchar.h>
#include <windows.h>
#include <winternl.h>

#ifndef __MINGW64_VERSION_MAJOR
/* MS winternl.h defines FILE_INFORMATION_CLASS, but with only a
   different single member. */
enum FILE_INFORMATION_CLASSX
{
  FileNameInformation =3D 9
};

typedef struct _FILE_NAME_INFORMATION
{
  ULONG FileNameLength;
  WCHAR FileName[1];
} FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;

NTSTATUS (NTAPI *pNtQueryInformationFile) (HANDLE, PIO_STATUS_BLOCK, PVOID,
					  ULONG, FILE_INFORMATION_CLASSX);
#else
NTSTATUS (NTAPI *pNtQueryInformationFile) (HANDLE, PIO_STATUS_BLOCK, PVOID,
					  ULONG, FILE_INFORMATION_CLASS);
#endif

int
isatty (int fd)
{
  HANDLE fh;
  NTSTATUS status;
  IO_STATUS_BLOCK io;
  long buf[66];	/* NAME_MAX + 1 + sizeof ULONG */
  PFILE_NAME_INFORMATION pfni =3D (PFILE_NAME_INFORMATION) buf;
  PWCHAR cp;

  /* First check using _isatty.
=20=20
     Note that this returns the wrong result for NUL, for instance!=20
     Workaround is not to use _isatty at all, but rather GetFileType
     plus object name checking. */
  if (_isatty (fd))
    return 1;

  /* Now fetch the underlying HANDLE. */
  fh =3D (HANDLE) _get_osfhandle (fd);
  if (!fh || fh =3D=3D INVALID_HANDLE_VALUE)
    {
      errno =3D EBADF;
      return 0;
    }

  /* Must be a pipe. */
  if (GetFileType (fh) !=3D FILE_TYPE_PIPE)
    goto no_tty;

  /* Calling the native NT function NtQueryInformationFile is required to
     support pre-Vista systems.  If that's of no concern, Vista introduced
     the GetFileInformationByHandleEx call with the FileNameInfo info class,
     which can be used instead. */
  if (!pNtQueryInformationFile)
    {
      pNtQueryInformationFile =3D (NTSTATUS (NTAPI *)(HANDLE, PIO_STATUS_BL=
OCK,
      				PVOID, ULONG, FILE_INFORMATION_CLASS))
			       GetProcAddress (GetModuleHandle ("ntdll.dll"),
					       "NtQueryInformationFile");
      if (!pNtQueryInformationFile)
      	goto no_tty;
    }
  if (!NT_SUCCESS (pNtQueryInformationFile (fh, &io, pfni, sizeof buf,
					   FileNameInformation)))
    goto no_tty;

  /* The filename is not guaranteed to be NUL-terminated. */
  pfni->FileName[pfni->FileNameLength / sizeof (WCHAR)] =3D L'\0';

  /* Now check the name pattern.  The filename of a Cygwin pseudo tty pipe
     looks like this:

       \cygwin-%16llx-pty%d-{to,from}-master
=20=20=20=20=20
     %16llx is the hash of the Cygwin installation, (to support multiple
     parallel installations), %d is the pseudo tty number, "to" or "from"
     differs the pipe direction. "from" is a stdin, "to" a stdout-like
     pipe. */
  cp =3D pfni->FileName;
  if (!wcsncmp (cp, L"\\cygwin-", 8)
      && !wcsncmp (cp + 24, L"-pty", 4))
    {
      cp =3D wcschr (cp + 28, '-');
      if (!cp)
      	goto no_tty;
      if (!wcscmp (cp, L"-from-master") || !wcscmp (cp, L"-to-master"))
      	return 1;
    }
no_tty:
  errno =3D EINVAL;
  return 0;
}

int
main ()
{
  if (isatty(0))
    printf("tty\n");
  else
    printf("not a tty\n");
  return 0;
}

--k4f25fnPtRuIRUb3--

--TD8GDToEDw0WLGOL
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJVbd7FAAoJEPU2Bp2uRE+g+ewP/2kPYpNGzyG9CsZtR4BHIYcc
H00LiQt9XT7MRVtkadxAIB1pdDKxDUNXBaIpeCTPkevEiUGx0e5iidtG4hsgo7Wt
CS/ENYsY1TuJuSXlRZ6rr9U6D18z4OzZ85T3Py3nt+DAYaIg0qFzXsuAmouYGswd
+xDxPP0DiiYWj+P+qIZ5KdQYgLsOlkg8BmOjxP3YVCPt7RwLVGIgV+aDXP91/pFU
i3NDVl62nXxLCaqBdfqvsEMx3gQ85FDHeQ95By53k0bO/hC9EaPAreucxgIQdJDW
Vl2GpvtRnjeJqkQZ7OZRuQlXGc4wBdQTn5bZyCXU+zEmEB6uQTCozKX7oi3r/VTw
qzfl0Q6s1XCKXkltUDO8XhyyNCjgx7Z/1DqTK/0P08kZ5QnfECC+Jcytj+Pg23XO
SWRrlNxFWNa2BVRY289wj3uC+h5ft78Nxt5sVsS9QfNF2w2Ru+gCzrj7RucqrgVx
uC0s6wvefPeocPPCg6LOaIbAwog+KlcTpvX+88WeTU72BE4YauoViDeVeB5GMNnm
o9veqhXAD0Y50ha5QP0708iEeMcfkSDMDjgoVGce17vHTc3NqlrnUWG4XyqCYjIO
oiRLO0rt97ZHr9E5UXEB1E5JpaC6oOZHBK8w28DH3OMWSUck9fR8xoverTSVV9Fz
25t5PkIfQYEe6Cm2VntR
=ib+4
-----END PGP SIGNATURE-----

--TD8GDToEDw0WLGOL--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019