From: Pavel A. on

"sds" <sam.steingold(a)gmail.com> wrote in message
news:85e704c4-cece-46d6-bac2-bb4db1484cee(a)b15g2000yqd.googlegroups.com...
> Is there a way to "inspect" a handle?
> E.g., how do I figure out if the handle is open for output or input?
> POSIX offers fcntl(fd,F_GETFL,0) which returns a flag which contains
> the access mode.
> Note that I do not want to write to the handle or read from it
> (because I do not want to pollute the terminal with test i/o).

Maybe NtQueryInformationFile with FileAccessInformation, FileNameInformation
is what you need.

--pa


From: sds on
On Oct 10, 4:08 pm, "Pavel A." <pave...(a)12fastmail34.fm> wrote:
> "sds" <sam.steing...(a)gmail.com> wrote in message
>
> news:85e704c4-cece-46d6-bac2-bb4db1484cee(a)b15g2000yqd.googlegroups.com...
>
> > Is there a way to "inspect" a handle?
> > E.g., how do I figure out if the handle is open for output or input?
> > POSIX offers fcntl(fd,F_GETFL,0) which returns a flag which contains
> > the access mode.
> > Note that I do not want to write to the handle or read from it
> > (because I do not want to pollute the terminal with test i/o).
>
> Maybe NtQueryInformationFile with FileAccessInformation, FileNameInformation
> is what you need.

Indeed, this looks like what I need.
(http://msdn.microsoft.com/en-us/library/ms804359.aspx)
Alas, it does not quite work.
Specifically,
NtQueryInformationFile(1736,&iosb,(void*)&fai,sizeof
(fai),FileAccessInformation)
returns STATUS_SUCCESS(0), but
fai.AccessFlags(0x120196) & STANDARD_RIGHTS_READ(0x020000) is 1
so the system claims that I can read from the handle(1736, which is my
stdin).
However, when I actually try to read from it, I get error 5
(ERROR_ACCESS_DENIED).
I.e., NtQueryInformationFile fails to detect that the handle is not
valid for input.
From: m on
Remember that this info is volatile too. I doubt that this information is
actually useful to you in any case, but if you try to explain what you are
trying to do, we may be able to help better.

"sds" <sam.steingold(a)gmail.com> wrote in message
news:07f91cce-7575-4324-8bce-bb7f97668262(a)l9g2000yqi.googlegroups.com...
> On Oct 10, 4:08 pm, "Pavel A." <pave...(a)12fastmail34.fm> wrote:
>> "sds" <sam.steing...(a)gmail.com> wrote in message
>>
>> news:85e704c4-cece-46d6-bac2-bb4db1484cee(a)b15g2000yqd.googlegroups.com...
>>
>> > Is there a way to "inspect" a handle?
>> > E.g., how do I figure out if the handle is open for output or input?
>> > POSIX offers fcntl(fd,F_GETFL,0) which returns a flag which contains
>> > the access mode.
>> > Note that I do not want to write to the handle or read from it
>> > (because I do not want to pollute the terminal with test i/o).
>>
>> Maybe NtQueryInformationFile with FileAccessInformation,
>> FileNameInformation
>> is what you need.
>
> Indeed, this looks like what I need.
> (http://msdn.microsoft.com/en-us/library/ms804359.aspx)
> Alas, it does not quite work.
> Specifically,
> NtQueryInformationFile(1736,&iosb,(void*)&fai,sizeof
> (fai),FileAccessInformation)
> returns STATUS_SUCCESS(0), but
> fai.AccessFlags(0x120196) & STANDARD_RIGHTS_READ(0x020000) is 1
> so the system claims that I can read from the handle(1736, which is my
> stdin).
> However, when I actually try to read from it, I get error 5
> (ERROR_ACCESS_DENIED).
> I.e., NtQueryInformationFile fails to detect that the handle is not
> valid for input.