Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Mar 2014 17:48:45 -0800 (PST)
From:      "\"Chad Kline\"" <i18rabbit@yahoo.com>
To:        bugbusters@FreeBSD.org
Subject:   Awk stdin/printf Bugs
Message-ID:  <1393984125.18671.YahooMailBasic@web161001.mail.bf1.yahoo.com>

next in thread | raw e-mail | index | archive | help
FreeBSD 9.2 ... For comparisons, mawk = 1.3.4, gawk = 4.1.0

Problem 1:

$ gawk 'BEGIN { s=sprintf("%c", 0); printf("%s", s) }'|more
^@ (as expected, ASCII 0)

$ mawk 'BEGIN { s=sprintf("%c", 0); printf("%s", s) }'|more
^@ (as expected, ASCII 0)

$ awk 'BEGIN { s=sprintf("%c", 0); printf("%s", s) }'|more
(nothing, no output - this should be fixed for compatibility/sensibility).

Problem 2:

$ gawk 'BEGIN { getline < "/dev/stdin"; close("/dev/stdin");
                getline < "/dev/stdin"; print }'
xxx
xxx
$ mawk 'BEGIN { getline < "/dev/stdin"; close("/dev/stdin");
                getline < "/dev/stdin"; print }'
xxx
yyy
yyy
$ awk 'BEGIN { getline < "/dev/stdin"; close("/dev/stdin");
               getline < "/dev/stdin"; print }'
xxx
xxx
awk: i/o error occurred on /dev/stdin
 source line number 1

Mawk is the only awk that processes the above code sensibly.
This "bug" has been filed with gawk-bugs@gnu.org for the following
reasons:

1. There is a definite compatibility problem here, and the only solutions are
to either make Mawk work "incorrectly/nonsensical/undefined" as Gawk and
FreeBSD awk, or to make Gawk and FreeBSD awk work in a defined and sensible
way such as Mawk.

2. It could be demanded of programmers to always avoid closing the "evil and
dangerous" stdin, but this requires every "open/read/close" file-type function
to always make special checks for a file named "stdin", when there is no
sensible/logical reason to do so.  There is no reason to force stdin to be
closed for the entirety of a program just because it was closed once.  Stdin
should behave like any other file, sensibly speaking, and it should be
possible to open again if it was closed previously, just like in C or any
other file in awk.

3. It is much more efficient for awk to "do nothing" with a
close("/dev/stdin") call than to implement special tests in awk for the "evil
and dangerous" stdin file within every "open/read/close" file-type function.
It hurts nothing to do so.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1393984125.18671.YahooMailBasic>