From owner-freebsd-bugbusters@FreeBSD.ORG Wed Mar 5 01:48:53 2014 Return-Path: Delivered-To: bugbusters@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7CC4B2F3 for ; Wed, 5 Mar 2014 01:48:53 +0000 (UTC) Received: from nm10-vm0.bullet.mail.bf1.yahoo.com (nm10-vm0.bullet.mail.bf1.yahoo.com [98.139.213.147]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 1ECDFB20 for ; Wed, 5 Mar 2014 01:48:52 +0000 (UTC) Received: from [66.196.81.171] by nm10.bullet.mail.bf1.yahoo.com with NNFMP; 05 Mar 2014 01:48:46 -0000 Received: from [98.139.212.217] by tm17.bullet.mail.bf1.yahoo.com with NNFMP; 05 Mar 2014 01:48:45 -0000 Received: from [127.0.0.1] by omp1026.mail.bf1.yahoo.com with NNFMP; 05 Mar 2014 01:48:45 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 892633.25072.bm@omp1026.mail.bf1.yahoo.com Received: (qmail 96538 invoked by uid 60001); 5 Mar 2014 01:48:45 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1393984125; bh=drydqr3Wt46jrjipeN5O3IKY7or1pV9VdYUzY/aUCmw=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=mPQwsivBQVYZ1Aa7WMZ1UdsIoSUUhx8zVnowVs/eBLE2Ha4B+09xRTqTRXbo4nMC+NutlQ07mnX8J+0AP17R1Nu8RH1bNYZOSO4/TcxXcrcV8cREHxtSZ6niaITo/GsWqzNiMXydndbInrXH2b/EXS8Uc8a8q1EbVT4oHL4EQXI= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:Message-ID:Date:From:Subject:To:MIME-Version:Content-Type; b=6Ct6Lv668/+dIuK8dC08L7tv7AXL4g9IjMUABqKeLOVgtW9QZ4X2O///G8R0wpsrUfAV7ntB4aKnQriZ2nFzwxqGEPUJ21YcbfHvSyqxnw3aFczLd6NQJV7waFGg2uCqXOqGEfS5dIhyMtYJOe2I8ZwJfCnlcjBpEurRLNDVk3U=; X-YMail-OSG: 1iiduIEVM1nLGwzesBj7k98p6eEjEqbt9P.D2juStabObru yz9HUzSSqAXcd37zn2Urq8oMaWfcj.412.1CRKg.IK5NYGOS8IRT8Sft7ZGv jJxuMhMIPxN5L4uKUmqeUZewtVhYR.USvRSI.DMVHCb.l0wkVrAkfSRaA_va CP.dklkKwOxTcDkzbYppso9tlQij.1EOqr8OGbdfg_DwY4VlgOqdw3TRNriY P3DAHbz2zejEBEAhZJEtGElzKElq3S1rUHlM2pA.FEAAuV2gdAuU5w9odCr4 5u6iG36HohG7GLgYwO5MJALlzlm5W3QbE1.W.f2POc4hw3Pjun5ohSwr.6rX wYeEy8_PjQ6BiCNLS7N.JK.Cj3wmwliUB0junapATw_S6RfNjvAQnRdwMKFv yZ7t9pKhNSCzWOv6bE6mtY1fq.h1oXg6av55PcbkCTeW7tui8y39IvCBPC54 QcLjS7D.f5r1FB0B.2REmFleE9LiFOpiWCf4u4AP7FaCJB89O0DgH.RydhVX aXCU7U4OcilRahVfCWwEFc2mE__v2iNgp0LlJlyePX6mxm290feOCulE3non P7JRZhCy6M5EVGA-- Received: from [209.112.188.15] by web161001.mail.bf1.yahoo.com via HTTP; Tue, 04 Mar 2014 17:48:45 PST X-Rocket-MIMEInfo: 002.001, RnJlZUJTRCA5LjIgLi4uIEZvciBjb21wYXJpc29ucywgbWF3ayA9IDEuMy40LCBnYXdrID0gNC4xLjANCg0KUHJvYmxlbSAxOg0KDQokIGdhd2sgJ0JFR0lOIHsgcz1zcHJpbnRmKCIlYyIsIDApOyBwcmludGYoIiVzIiwgcykgfSd8bW9yZQ0KXkAgKGFzIGV4cGVjdGVkLCBBU0NJSSAwKQ0KDQokIG1hd2sgJ0JFR0lOIHsgcz1zcHJpbnRmKCIlYyIsIDApOyBwcmludGYoIiVzIiwgcykgfSd8bW9yZQ0KXkAgKGFzIGV4cGVjdGVkLCBBU0NJSSAwKQ0KDQokIGF3ayAnQkVHSU4geyBzPXNwcmludGYoIiVjIiwgMCkBMAEBAQE- X-Mailer: YahooMailClassic/432 YahooMailWebService/0.8.177.636 Message-ID: <1393984125.18671.YahooMailBasic@web161001.mail.bf1.yahoo.com> Date: Tue, 4 Mar 2014 17:48:45 -0800 (PST) From: "\"Chad Kline\"" Subject: Awk stdin/printf Bugs To: bugbusters@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-BeenThere: freebsd-bugbusters@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Coordination of the Problem Report handling effort." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Mar 2014 01:48:53 -0000 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.