bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] close/stdin bug


From: arnold
Subject: Re: [bug-gawk] close/stdin bug
Date: Thu, 06 Mar 2014 00:02:03 -0700
User-agent: Heirloom mailx 12.4 7/29/08

Hello.

> I am using FreeBSD 9.2, gawk-4.1.0, mawk-1.3.4, and awk from the base
> installation.

What is the result of mawk -Wversion?  There have been several versions
of mawk 1.3.4.

> I do not get the same results as you, even with your coding. I
> think you are cheating a little, because you are using "a" for both inputs,

No, you did not look hard enough:

>  $ cat x.in
>  a
>  b

For BWK awk and gawk I get the same result as you, as well as for the
latest version of mawk released by Thomas Dickey.  That you get something
different on FreeBSD is, I think, related more to FreeBSD than to
awk implemenation differences.  I don't have access to a FreeBSD system,
and until I know exactly what version of mawk you're using, I can't do
any more effective testing.

I also think it would be worthwhile for you to compiile and test the
current version of mawk (http://invisible-island.net/mawk).

You should understand that /dev/stdin is trested specially, at least
by gawk and BWK awk, and maps directly to the original file descriptor zero.
Once it is closed, that's it, it is gone. What you are trying to do
correspods roughtly to C code like this:

        int main()
        {
                int fd;
                close(0);
                fd = open("/dev/stdin", 0);     /* will fail */
                ...
        }

The situation in awk is similar to that in C - a function that is
passed an open file descriptor shouldn't arbitrarily close it.
C code has to watch out for file descriptors 0, 1, and 2; if your
awk code cares, then it has to watch out for both "/dev/stdin" and "-".

HTH,

Arnold



reply via email to

[Prev in Thread] Current Thread [Next in Thread]