From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 03 11:30:12 2014 Received: (at submit) by debbugs.gnu.org; 3 Jan 2014 16:30:12 +0000 Received: from localhost ([127.0.0.1]:60108 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz7dR-0001En-SY for submit@debbugs.gnu.org; Fri, 03 Jan 2014 11:30:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34223) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz71x-00008w-Rm for submit@debbugs.gnu.org; Fri, 03 Jan 2014 10:51:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vz71n-0002cF-TC for submit@debbugs.gnu.org; Fri, 03 Jan 2014 10:51:25 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:38704) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz71n-0002cA-Pt for submit@debbugs.gnu.org; Fri, 03 Jan 2014 10:51:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz71g-0002CV-FY for bug-coreutils@gnu.org; Fri, 03 Jan 2014 10:51:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vz71W-0002aT-QZ for bug-coreutils@gnu.org; Fri, 03 Jan 2014 10:51:08 -0500 Received: from f412.i.mail.ru ([185.5.136.83]:47852) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz71W-0002ZS-EO for bug-coreutils@gnu.org; Fri, 03 Jan 2014 10:50:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=Content-Type:Message-ID:Reply-To:Date:Mime-Version:Subject:To:From; bh=9S0iX2XdF5rQcvCvaeZen0qp+gQG1+0eThSCsRJS4h4=; b=uYiTNGSLesb4p5E975d0Fq5qrU7WbF1V4Q0nRwN7whFY46/VJF2ozM+skK+q7KKtS12VgxicEYqwgen6I7aOL9YE5ihSwFJKLYpOHARa1bvohIg1iBolFZBkht6+PkiHml2UdmZg7T+R6me3sbFl24KOmcuFKgKuKvio1YzOdls=; Received: from mail by f412.i.mail.ru with local (envelope-from ) id 1Vz71U-0000Uy-3Y for bug-coreutils@gnu.org; Fri, 03 Jan 2014 19:50:56 +0400 Received: from [109.172.69.18] by e.mail.ru with HTTP; Fri, 03 Jan 2014 19:50:56 +0400 From: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= To: bug-coreutils@gnu.org Subject: =?UTF-8?B?YGhlYWQgLS1saW5lcz0tMCcgcHJpbnRzIG5vdGhpbmcgaWYgbm8gbmV3bGlu?= =?UTF-8?B?ZSBhdCB0aGUgRU9G?= Mime-Version: 1.0 X-Mailer: Mail.Ru Mailer 1.0 X-Originating-IP: [109.172.69.18] Date: Fri, 03 Jan 2014 19:50:56 +0400 X-Priority: 3 (Normal) Message-ID: <1388764256.577663010@f412.i.mail.ru> Content-Type: multipart/mixed; boundary="----KJhk3qQW-Hg2xURz7Ft3ME4nl:1388764256" X-Mras: Ok X-Spam: undefined X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Fri, 03 Jan 2014 11:30:06 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) ------KJhk3qQW-Hg2xURz7Ft3ME4nl:1388764256 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 SGksCgpJZiBvbmUgcnVucyBgaGVhZCAtLWxpbmVzPS0wIHNvbWVmaWxlJywgaGUnbGwgc29tZXRp bWVzIGdldCBubyBvdXRwdXQgaW5zdGVhZCBvZiBmdWxsIGZpbGUgY29udGVudHMgYXMKZXhwZWN0 ZWQgYWZ0ZXIgcmVhZGluZyB0aGUgbWFudWFsOgoKLW4sIC0tbGluZXM9Wy1dSwogICAgICAgIHBy aW50IHRoZSBmaXJzdCBLIGxpbmVzIGluc3RlYWQgb2YgdGhlIGZpcnN0IDEwOyB3aXRoIHRoZSBs ZWFk4oCQCiAgICAgICAgaW5nIGAtJywgcHJpbnQgYWxsIGJ1dCB0aGUgbGFzdCBLIGxpbmVzIG9m IGVhY2ggZmlsZQoKSXQgZGVwZW5kcyBvbiB3aGV0aGVyIHRoZSBmaWxlIGhhcyBhIHRyYWlsaW5n IG5ld2xpbmUuCgpGb3IgZXhhbXBsZToKCiQgcHJpbnRmICcxXG4yXG4zJyA+IHRlc3QxCiQgcHJp bnRmICc0XG41XG4nID4gdGVzdDIKJCBoZWFkIC1uIC0wIHRlc3QqCj09PiB0ZXN0MSA8PT0KCj09 PiB0ZXN0MiA8PT0KNAo1CiQgdGFpbCAtbiArMCB0ZXN0KiAgICMgSnVzdCBmb3IgY29tcGFyaXNv bgo9PT4gdGVzdDEgPD09CjEKMgozCj09PiB0ZXN0MiA8PT0KNAo1CiQgCgpJJ20gdXNpbmcgRGVi aWFuIEdOVS9MaW51eCA3IHdoZWV6eSBhbmQgY29yZXV0aWxzLTguMTM7IEkndmUgYWxzbyB0ZXN0 ZWQgY29yZXV0aWxzLTguMjIsIGFuZCBpdCBoYXMgdGhlCnNhbWUgaXNzdWUuCgpBIHByb3Bvc2Vk IHBhdGNoIGZpeGluZyB0aGUgYnVnIGlzIGF0dGFjaGVkLiBJdCBtYWtlcyBoZWFkIGJlaGF2ZSBl eGFjdGx5IGxpa2UgYHRhaWwgLW4gKzAnIG9uIHNhbWUgZmlsZXMuCgotLSAK0JDQu9C10LrRgdC1 0Lkg0KjQuNC70LjQvQ== ------KJhk3qQW-Hg2xURz7Ft3ME4nl:1388764256 Content-Type: application/x-patch; name="=?UTF-8?B?aGVhZF9ubGluZXNfZml4LnBhdGNo?=" Content-Disposition: attachment Content-Transfer-Encoding: base64 LS0tIGNvcmV1dGlscy04LjIyLm9yaWcvc3JjL2hlYWQuYwkyMDEzLTEyLTA0IDE0OjQ4OjMwLjAw MDAwMDAwMCArMDAwMAorKysgY29yZXV0aWxzLTguMjIvc3JjL2hlYWQuYwkyMDE0LTAxLTAzIDE0 OjQ5OjQ0LjM0NDI3Mjg5NSArMDAwMApAQCAtNjM2LDggKzYzNiwxMSBAQAogICAgICAgcmV0dXJu IGZhbHNlOwogICAgIH0KIAorICAvKiBuX2xpbmVzID09IDAgY2FzZSBuZWVkcyBzcGVjaWFsIHRy ZWF0bWVudC4gKi8KKyAgY29uc3QgYm9vbCBhbGxfbGluZXMgPSAhbl9saW5lczsKKwogICAvKiBD b3VudCB0aGUgaW5jb21wbGV0ZSBsaW5lIG9uIGZpbGVzIHRoYXQgZG9uJ3QgZW5kIHdpdGggYSBu ZXdsaW5lLiAgKi8KLSAgaWYgKGJ5dGVzX3JlYWQgJiYgYnVmZmVyW2J5dGVzX3JlYWQgLSAxXSAh PSAnXG4nKQorICBpZiAobl9saW5lcyAmJiBieXRlc19yZWFkICYmIGJ1ZmZlcltieXRlc19yZWFk IC0gMV0gIT0gJ1xuJykKICAgICAtLW5fbGluZXM7CiAKICAgd2hpbGUgKDEpCkBAIC02NDcsMTEg KzY1MCwxNiBAQAogICAgICAgc2l6ZV90IG4gPSBieXRlc19yZWFkOwogICAgICAgd2hpbGUgKG4p CiAgICAgICAgIHsKLSAgICAgICAgICBjaGFyIGNvbnN0ICpubDsKLSAgICAgICAgICBubCA9IG1l bXJjaHIgKGJ1ZmZlciwgJ1xuJywgbik7Ci0gICAgICAgICAgaWYgKG5sID09IE5VTEwpCi0gICAg ICAgICAgICBicmVhazsKLSAgICAgICAgICBuID0gbmwgLSBidWZmZXI7CisgICAgICAgICAgaWYg KGFsbF9saW5lcykKKyAgICAgICAgICAgIG4gLT0gbiA/IDEgOiAwOworICAgICAgICAgIGVsc2UK KyAgICAgICAgICAgIHsKKyAgICAgICAgICAgICAgY2hhciBjb25zdCAqbmw7CisgICAgICAgICAg ICAgIG5sID0gbWVtcmNociAoYnVmZmVyLCAnXG4nLCBuKTsKKyAgICAgICAgICAgICAgaWYgKG5s ID09IE5VTEwpCisgICAgICAgICAgICAgICAgYnJlYWs7CisgICAgICAgICAgICAgIG4gPSBubCAt IGJ1ZmZlcjsKKyAgICAgICAgICAgIH0KICAgICAgICAgICBpZiAobl9saW5lcy0tID09IDApCiAg ICAgICAgICAgICB7CiAgICAgICAgICAgICAgIC8qIEZvdW5kIGl0LiAgKi8K ------KJhk3qQW-Hg2xURz7Ft3ME4nl:1388764256-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 03 11:45:13 2014 Received: (at 16329) by debbugs.gnu.org; 3 Jan 2014 16:45:13 +0000 Received: from localhost ([127.0.0.1]:60145 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz7s0-0001f6-Gp for submit@debbugs.gnu.org; Fri, 03 Jan 2014 11:45:12 -0500 Received: from mail3.vodafone.ie ([213.233.128.45]:54935) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz7rx-0001ev-Vf for 16329@debbugs.gnu.org; Fri, 03 Jan 2014 11:45:10 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBAL7oxlJtTev4/2dsb2JhbAANS4cWpHiODYMHgSODGQEBAQQjDwFGEAkCDQsCAgUWCwICCQMCAQIBRQYNAQcBAYgFjViaeXaZYBeBKY0yMweCb4FIAQOfA45V Received: from unknown (HELO [192.168.1.79]) ([109.77.235.248]) by mail3.vodafone.ie with ESMTP; 03 Jan 2014 16:45:07 +0000 Message-ID: <52C6E913.2040300@draigBrady.com> Date: Fri, 03 Jan 2014 16:45:07 +0000 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= Subject: Re: bug#16329: `head --lines=-0' prints nothing if no newline at the EOF References: <1388764256.577663010@f412.i.mail.ru> In-Reply-To: <1388764256.577663010@f412.i.mail.ru> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 16329 Cc: 16329@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 01/03/2014 03:50 PM, Алексей Шилин wrote: > Hi, > > If one runs `head --lines=-0 somefile', he'll sometimes get no output instead of full file contents as > expected after reading the manual: > > -n, --lines=[-]K > print the first K lines instead of the first 10; with the lead‐ > ing `-', print all but the last K lines of each file > > It depends on whether the file has a trailing newline. > > For example: > > $ printf '1\n2\n3' > test1 > $ printf '4\n5\n' > test2 > $ head -n -0 test* > ==> test1 <== > > ==> test2 <== > 4 > 5 > $ tail -n +0 test* # Just for comparison > ==> test1 <== > 1 > 2 > 3 > ==> test2 <== > 4 > 5 > $ > > I'm using Debian GNU/Linux 7 wheezy and coreutils-8.13; I've also tested coreutils-8.22, and it has the > same issue. > > A proposed patch fixing the bug is attached. It makes head behave exactly like `tail -n +0' on same files. > Thanks for the clear reproducer and patch. I'll probably apply this in your name with a test. thanks! Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 03 11:57:32 2014 Received: (at 16329) by debbugs.gnu.org; 3 Jan 2014 16:57:32 +0000 Received: from localhost ([127.0.0.1]:60188 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz83v-00021J-Q5 for submit@debbugs.gnu.org; Fri, 03 Jan 2014 11:57:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29557) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz83s-000218-Ki for 16329@debbugs.gnu.org; Fri, 03 Jan 2014 11:57:30 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s03GvQMs030153 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jan 2014 11:57:27 -0500 Received: from [10.3.113.90] (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s03GvP76021581; Fri, 3 Jan 2014 11:57:26 -0500 Message-ID: <52C6EBF5.9000407@redhat.com> Date: Fri, 03 Jan 2014 09:57:25 -0700 From: Eric Blake Organization: Red Hat, Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= , 16329@debbugs.gnu.org Subject: Re: bug#16329: `head --lines=-0' prints nothing if no newline at the EOF References: <1388764256.577663010@f412.i.mail.ru> In-Reply-To: <1388764256.577663010@f412.i.mail.ru> X-Enigmail-Version: 1.6 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="58RBRn4fgqB6sAdAEFl0veHjWCti1l4lP" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-Spam-Score: -5.6 (-----) X-Debbugs-Envelope-To: 16329 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.6 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --58RBRn4fgqB6sAdAEFl0veHjWCti1l4lP Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/03/2014 08:50 AM, =D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9 =D0=A8= =D0=B8=D0=BB=D0=B8=D0=BD wrote: > Hi, >=20 > If one runs `head --lines=3D-0 somefile', he'll sometimes get no output= instead of full file contents as > expected after reading the manual: >=20 > -n, --lines=3D[-]K > print the first K lines instead of the first 10; with the lead=E2= =80=90 > ing `-', print all but the last K lines of each file >=20 > It depends on whether the file has a trailing newline. Per POSIX, 'head' is only required to operate on "text files" http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html and a "text file" must either be empty or have a trailing newline: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#t= ag_03_397 So this is not necessarily a bug. That said, since POSIX doesn't specify what we should do, we are free to make it behave differently. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --58RBRn4fgqB6sAdAEFl0veHjWCti1l4lP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSxuv1AAoJEKeha0olJ0NqfYQH/3j1s1dlVdU7bNkykP/jLrBY IF5DdVqgMqikQBG60iazi6ungKWg37ZY3gTv8YbSFpZ0mFt1LK7UbmoJzKYjIxKM Yu5jFR9CrbAsjEmGZhyuB+szg89lZvANiyprtyoHQfL53DvMOpHO5c93zlOkttu/ H32t9aTPWbzxyv0F+/Bm+Kf3ECCA53zWv0gwlmx058gUhXzfXFs6JuY/jVEyDyQV IDjPfchCuTckX0DOLKzB6RiXfqk6OnqzK34H3AGlgBKex/TrLfkSP299EAzhGHj+ nx5GsC6E7kPeOJDRhCs9NFrtu/Z/wRN3lUBce1Nof8rX11v3k+ZJ4Pg5QwDGaa0= =RMGE -----END PGP SIGNATURE----- --58RBRn4fgqB6sAdAEFl0veHjWCti1l4lP-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 03 12:02:51 2014 Received: (at 16329) by debbugs.gnu.org; 3 Jan 2014 17:02:51 +0000 Received: from localhost ([127.0.0.1]:60201 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz894-0003Hv-RL for submit@debbugs.gnu.org; Fri, 03 Jan 2014 12:02:51 -0500 Received: from mail6.vodafone.ie ([213.233.128.184]:12925) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz892-0003Hk-Ux for 16329@debbugs.gnu.org; Fri, 03 Jan 2014 12:02:49 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBAF7sxlJtTev4/2dsb2JhbAANS4NDg1O1PU+BI4MZAQEBBCMPAUYQCQINAQoCAgUWCwICCQMCAQIBRQYNAQcBAYgFCI1Bmnl2mWEXgSmNZQeCb4FIAQOZR4U8jlU Received: from unknown (HELO [192.168.1.79]) ([109.77.235.248]) by mail3.vodafone.ie with ESMTP; 03 Jan 2014 17:02:47 +0000 Message-ID: <52C6ED37.5070703@draigBrady.com> Date: Fri, 03 Jan 2014 17:02:47 +0000 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Eric Blake Subject: Re: bug#16329: `head --lines=-0' prints nothing if no newline at the EOF References: <1388764256.577663010@f412.i.mail.ru> <52C6EBF5.9000407@redhat.com> In-Reply-To: <52C6EBF5.9000407@redhat.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 16329 Cc: 16329@debbugs.gnu.org, =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 01/03/2014 04:57 PM, Eric Blake wrote: > On 01/03/2014 08:50 AM, Алексей Шилин wrote: >> Hi, >> >> If one runs `head --lines=-0 somefile', he'll sometimes get no output instead of full file contents as >> expected after reading the manual: >> >> -n, --lines=[-]K >> print the first K lines instead of the first 10; with the lead‐ >> ing `-', print all but the last K lines of each file >> >> It depends on whether the file has a trailing newline. > > Per POSIX, 'head' is only required to operate on "text files" > http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html > and a "text file" must either be empty or have a trailing newline: > http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_397 > > So this is not necessarily a bug. That said, since POSIX doesn't > specify what we should do, we are free to make it behave differently. BTW I still don't think POSIX is specifying that text files without a trailing newline are not text files. It states that text files can have zero or more lines, implying that the trailing new line is optional. thanks, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 03 12:10:16 2014 Received: (at 16329) by debbugs.gnu.org; 3 Jan 2014 17:10:16 +0000 Received: from localhost ([127.0.0.1]:60212 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz8GG-0003To-2z for submit@debbugs.gnu.org; Fri, 03 Jan 2014 12:10:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:3110) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz8GC-0003Td-Fw for 16329@debbugs.gnu.org; Fri, 03 Jan 2014 12:10:14 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s03HAA1s030395 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 3 Jan 2014 12:10:11 -0500 Received: from [10.3.113.90] (ovpn-113-90.phx2.redhat.com [10.3.113.90]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s03HAAPw013795; Fri, 3 Jan 2014 12:10:10 -0500 Message-ID: <52C6EEF1.1060503@redhat.com> Date: Fri, 03 Jan 2014 10:10:09 -0700 From: Eric Blake Organization: Red Hat, Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#16329: `head --lines=-0' prints nothing if no newline at the EOF References: <1388764256.577663010@f412.i.mail.ru> <52C6EBF5.9000407@redhat.com> <52C6ED37.5070703@draigBrady.com> In-Reply-To: <52C6ED37.5070703@draigBrady.com> X-Enigmail-Version: 1.6 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="d916BSR2bLwD1U57EbMtFIHQTNsWjMntU" X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-Spam-Score: -5.6 (-----) X-Debbugs-Envelope-To: 16329 Cc: 16329@debbugs.gnu.org, =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.6 (-----) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --d916BSR2bLwD1U57EbMtFIHQTNsWjMntU Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 01/03/2014 10:02 AM, P=C3=A1draig Brady wrote: >>> It depends on whether the file has a trailing newline. >> >> Per POSIX, 'head' is only required to operate on "text files" >> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html >> and a "text file" must either be empty or have a trailing newline: >> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.htm= l#tag_03_397 >> >> So this is not necessarily a bug. That said, since POSIX doesn't >> specify what we should do, we are free to make it behave differently. >=20 > BTW I still don't think POSIX is specifying that text files without > a trailing newline are not text files. >=20 > It states that text files can have zero or more lines, Where "lines" is also a well-defined POSIX term: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#t= ag_03_206 > implying that the trailing new line is optional. Wrong. The trailing newline character is mandatory in text files. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --d916BSR2bLwD1U57EbMtFIHQTNsWjMntU Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJSxu7xAAoJEKeha0olJ0NqpxMH/jsRu5VPokXGzkaH6iZAzhrM uadEFsc4SEZL+2ooASUiGcWvKeY51oVEAt9Z13Z0Ns0hbEh0ETidk2BU7i45nkup OwX8mViEiZ9zOxbBOxUaBP80vs01APQwrsGU6tBCQv19wo2MWxVNhHDAd50WQntR HcqJjXqd5vBxZMdI9h9minA0CcrMu0nbSEG8JSmPLb69J+zGLQOFSCZ4xVUs5qWm h4gRzm3wFdfA/SrKxYD//iUgSV94CW12Go8pdj2/mgmOCEnHu5nuDzN8QFmaZaPN /wvRCvdFemmYIEtEezBrGtwABviK4D4J4jqPBMCv747N3Cw7JXy34qjp5Nonpuk= =l57A -----END PGP SIGNATURE----- --d916BSR2bLwD1U57EbMtFIHQTNsWjMntU-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 03 12:45:22 2014 Received: (at submit) by debbugs.gnu.org; 3 Jan 2014 17:45:22 +0000 Received: from localhost ([127.0.0.1]:60272 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz8oD-0004Tv-F0 for submit@debbugs.gnu.org; Fri, 03 Jan 2014 12:45:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:57685) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Vz8o9-0004Tk-9l for submit@debbugs.gnu.org; Fri, 03 Jan 2014 12:45:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vz8o2-0003Nz-Ea for submit@debbugs.gnu.org; Fri, 03 Jan 2014 12:45:16 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([208.118.235.17]:39157) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz8o2-00038s-AU for submit@debbugs.gnu.org; Fri, 03 Jan 2014 12:45:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57518) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz8do-0007h2-GP for bug-coreutils@gnu.org; Fri, 03 Jan 2014 12:34:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vz8dj-0000Cv-2u for bug-coreutils@gnu.org; Fri, 03 Jan 2014 12:34:36 -0500 Received: from smtp.cs.ucla.edu ([131.179.128.62]:58857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vz8di-0000CK-TQ for bug-coreutils@gnu.org; Fri, 03 Jan 2014 12:34:31 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 8C737A60008 for ; Fri, 3 Jan 2014 09:34:29 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j+680uBnEwhy for ; Fri, 3 Jan 2014 09:34:28 -0800 (PST) Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id BDA5EA60003 for ; Fri, 3 Jan 2014 09:34:28 -0800 (PST) Message-ID: <52C6F4A4.6080503@cs.ucla.edu> Date: Fri, 03 Jan 2014 09:34:28 -0800 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: bug-coreutils@gnu.org Subject: Re: bug#16329: `head --lines=-0' prints nothing if no newline at the EOF References: <1388764256.577663010@f412.i.mail.ru> <52C6EBF5.9000407@redhat.com> <52C6ED37.5070703@draigBrady.com> In-Reply-To: <52C6ED37.5070703@draigBrady.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 208.118.235.17 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) P=C3=A1draig Brady wrote: > It states that text files can have zero or more lines, > implying that the trailing new line is optional. I think Eric's right here; if the file is nonempty, a trailing newline is required. I'm old enough to remember when text files were not allowed to be empty (!). Totally bizarre, but that's the way POSIX was until 2008. Before that, every text file had to end with a newline byte. See: http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#t= ag_03_392 From debbugs-submit-bounces@debbugs.gnu.org Fri Jan 03 15:40:33 2014 Received: (at 16329) by debbugs.gnu.org; 3 Jan 2014 20:40:33 +0000 Received: from localhost ([127.0.0.1]:60480 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VzBXk-0000rY-5P for submit@debbugs.gnu.org; Fri, 03 Jan 2014 15:40:32 -0500 Received: from f346.i.mail.ru ([217.69.140.242]:47911) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VzBXg-0000rM-T7 for 16329@debbugs.gnu.org; Fri, 03 Jan 2014 15:40:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=References:In-Reply-To:Content-Type:Message-ID:Reply-To:Date:Mime-Version:Subject:To:From; bh=44iyNNa/uUL0KXEu1ihAyz2XxRSrb9zujU2gTSNMJYk=; b=gJyCTE0ZkatyT26eY8GGppQLQl1chKqk0EhIPAcxz3em72mlhN+fl3FgENa7+GC4rZzc6Q8FS+xmnPmPUZhKA6xoLXNIyaz7SnPLayJONLXtJrTUqigY3Kwfk4LTjUuFrozMZnR7h2V3cTGDqgahiwE+XmhYzJhljkHIbPers7k=; Received: from mail by f346.i.mail.ru with local (envelope-from ) id 1VzBXf-0002C5-A4 for 16329@debbugs.gnu.org; Sat, 04 Jan 2014 00:40:27 +0400 Received: from [109.172.69.18] by e.mail.ru with HTTP; Sat, 04 Jan 2014 00:40:27 +0400 From: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= To: 16329@debbugs.gnu.org Subject: =?UTF-8?B?UmU6IGJ1ZyMxNjMyOTogQWNrbm93bGVkZ2VtZW50IChgaGVhZCAtLWxpbmVz?= =?UTF-8?B?PS0wJyBwcmludHMgbm90aGluZyBpZiBubyBuZXdsaW5lIGF0IHRoZSBFT0Yp?= Mime-Version: 1.0 X-Mailer: Mail.Ru Mailer 1.0 X-Originating-IP: [109.172.69.18] Date: Sat, 04 Jan 2014 00:40:27 +0400 X-Priority: 3 (Normal) Message-ID: <1388781627.45947684@f346.i.mail.ru> Content-Type: multipart/mixed; boundary="----0pGvb3Lo-AD616WfjPAuj6Y0S:1388781627" X-Mras: Ok X-Spam: undefined In-Reply-To: References: <1388764256.577663010@f412.i.mail.ru> X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 16329 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) ------0pGvb3Lo-AD616WfjPAuj6Y0S:1388781627 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 TG9va3MgbGlrZSBJIHdhcyBvdmVybHkgY2F1dGlvdXMgYWJvdXQgZGVjcmVtZW50aW5nIGFuIHVu c2lnbmVkLi4uCgpzaXplX3QgbiA9IGJ5dGVzX3JlYWQ7CndoaWxlIChuKQogIHsKICAgIGlmIChh bGxfbGluZXMpCiAgICAgIG4gLT0gbiA/IDEgOiAwOyAgICAgICAgLy8gLi4uaGVyZS4KICAgIGVs c2UKCkFzIGl0IGlzIHVuZGVyIGB3aGlsZSAobiknIHN0YXRlbWVudCwgbiBpcyBhbHdheXMgdHJ1 ZSBoZXJlLCBhbmQgdGh1cyB0aGUgdGVybmFyeSBvcGVyYXRvciwgdGhvdWdoIG1ha2VzIG5vCmhh cm0sIGlzIG5lZWRsZXNzLCBhbmQgdGhlIHdob2xlIGxpbmUgY2FuIGJlIHJlcGxhY2VkIHdpdGgg anVzdCBgbi0tOycuIFNvcnJ5IGZvciB0aGF0LgoKVGhlIGZpeGVkIHZlcnNpb24gb2YgdGhlIG9y aWdpbmFsIHBhdGNoIGlzIGF0dGFjaGVkLgoKLS0gCtCQ0LvQtdC60YHQtdC5INCo0LjQu9C40L0K ------0pGvb3Lo-AD616WfjPAuj6Y0S:1388781627 Content-Type: application/x-patch; name="=?UTF-8?B?aGVhZF9ubGluZXNfZml4Mi5wYXRjaA==?=" Content-Disposition: attachment Content-Transfer-Encoding: base64 LS0tIGNvcmV1dGlscy04LjIyLm9yaWcvc3JjL2hlYWQuYwkyMDEzLTEyLTA0IDE0OjQ4OjMwLjAw MDAwMDAwMCArMDAwMAorKysgY29yZXV0aWxzLTguMjIvc3JjL2hlYWQuYwkyMDE0LTAxLTAzIDIw OjEyOjA3LjU3Mjg2MzY1MiArMDAwMApAQCAtNjM2LDggKzYzNiwxMSBAQAogICAgICAgcmV0dXJu IGZhbHNlOwogICAgIH0KIAorICAvKiBuX2xpbmVzID09IDAgY2FzZSBuZWVkcyBzcGVjaWFsIHRy ZWF0bWVudC4gKi8KKyAgY29uc3QgYm9vbCBhbGxfbGluZXMgPSAhbl9saW5lczsKKwogICAvKiBD b3VudCB0aGUgaW5jb21wbGV0ZSBsaW5lIG9uIGZpbGVzIHRoYXQgZG9uJ3QgZW5kIHdpdGggYSBu ZXdsaW5lLiAgKi8KLSAgaWYgKGJ5dGVzX3JlYWQgJiYgYnVmZmVyW2J5dGVzX3JlYWQgLSAxXSAh PSAnXG4nKQorICBpZiAobl9saW5lcyAmJiBieXRlc19yZWFkICYmIGJ1ZmZlcltieXRlc19yZWFk IC0gMV0gIT0gJ1xuJykKICAgICAtLW5fbGluZXM7CiAKICAgd2hpbGUgKDEpCkBAIC02NDcsMTEg KzY1MCwxNiBAQAogICAgICAgc2l6ZV90IG4gPSBieXRlc19yZWFkOwogICAgICAgd2hpbGUgKG4p CiAgICAgICAgIHsKLSAgICAgICAgICBjaGFyIGNvbnN0ICpubDsKLSAgICAgICAgICBubCA9IG1l bXJjaHIgKGJ1ZmZlciwgJ1xuJywgbik7Ci0gICAgICAgICAgaWYgKG5sID09IE5VTEwpCi0gICAg ICAgICAgICBicmVhazsKLSAgICAgICAgICBuID0gbmwgLSBidWZmZXI7CisgICAgICAgICAgaWYg KGFsbF9saW5lcykKKyAgICAgICAgICAgIG4tLTsKKyAgICAgICAgICBlbHNlCisgICAgICAgICAg ICB7CisgICAgICAgICAgICAgIGNoYXIgY29uc3QgKm5sOworICAgICAgICAgICAgICBubCA9IG1l bXJjaHIgKGJ1ZmZlciwgJ1xuJywgbik7CisgICAgICAgICAgICAgIGlmIChubCA9PSBOVUxMKQor ICAgICAgICAgICAgICAgIGJyZWFrOworICAgICAgICAgICAgICBuID0gbmwgLSBidWZmZXI7Cisg ICAgICAgICAgICB9CiAgICAgICAgICAgaWYgKG5fbGluZXMtLSA9PSAwKQogICAgICAgICAgICAg ewogICAgICAgICAgICAgICAvKiBGb3VuZCBpdC4gICovCg== ------0pGvb3Lo-AD616WfjPAuj6Y0S:1388781627-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 04 12:52:50 2014 Received: (at 16329) by debbugs.gnu.org; 4 Jan 2014 17:52:50 +0000 Received: from localhost ([127.0.0.1]:34139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VzVOz-0007Lg-Jx for submit@debbugs.gnu.org; Sat, 04 Jan 2014 12:52:49 -0500 Received: from f433.i.mail.ru ([185.5.136.104]:45664) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VzVOw-0007LU-Ke for 16329@debbugs.gnu.org; Sat, 04 Jan 2014 12:52:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail2; h=References:In-Reply-To:Content-Transfer-Encoding:Content-Type:Message-ID:Reply-To:Date:Mime-Version:Subject:Cc:To:From; bh=h3Qzzf+acyNaRYjmrK0UP3UZbXnOWlZZzs0NbyRbz3g=; b=TBTveHllpPKgwfujp/FIjt4cf+En5YtPSnvYCjD3ScfxUEHwPHAm2FW12mAv+7GDra7pvB37mSdu3h9ACS6RXy5ZMWmJWAuE9OjIS7HBNIFPLirTl5jddGwhIQV9N9xEOspeZMDBlxenGsWza2SPRjRW+oVvoeB09xfWbLFInOo=; Received: from mail by f433.i.mail.ru with local (envelope-from ) id 1VzVOu-0006Uq-53; Sat, 04 Jan 2014 21:52:44 +0400 Received: from [109.172.69.18] by e.mail.ru with HTTP; Sat, 04 Jan 2014 21:52:44 +0400 From: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= To: =?UTF-8?B?RXJpYyBCbGFrZQ==?= Subject: =?UTF-8?B?UmVbMl06IGJ1ZyMxNjMyOTogYGhlYWQgLS1saW5lcz0tMCcgcHJpbnRzIG5v?= =?UTF-8?B?dGhpbmcgaWYgbm8gbmV3bGluZSBhdCB0aGUgRU9G?= Mime-Version: 1.0 X-Mailer: Mail.Ru Mailer 1.0 X-Originating-IP: [109.172.69.18] Date: Sat, 04 Jan 2014 21:52:44 +0400 X-Priority: 3 (Normal) Message-ID: <1388857964.843477226@f433.i.mail.ru> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 X-Mras: Ok X-Spam: undefined In-Reply-To: <52C6EBF5.9000407@redhat.com> References: <1388764256.577663010@f412.i.mail.ru> <52C6EBF5.9000407@redhat.com> X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 16329 Cc: 16329@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) 0J/Rj9GC0L3QuNGG0LAsICAzINGP0L3QstCw0YDRjyAyMDE0LCA5OjU3IC0wNzowMCDQvtGCIEVy aWMgQmxha2UgPGVibGFrZUByZWRoYXQuY29tPjoKPlBlciBQT1NJWCwgJ2hlYWQnIGlzIG9ubHkg cmVxdWlyZWQgdG8gb3BlcmF0ZSBvbiAidGV4dCBmaWxlcyIKPmh0dHA6Ly9wdWJzLm9wZW5ncm91 cC5vcmcvb25saW5lcHVicy85Njk5OTE5Nzk5L3V0aWxpdGllcy9oZWFkLmh0bWwKPmFuZCBhICJ0 ZXh0IGZpbGUiIG11c3QgZWl0aGVyIGJlIGVtcHR5IG9yIGhhdmUgYSB0cmFpbGluZyBuZXdsaW5l Ogo+aHR0cDovL3B1YnMub3Blbmdyb3VwLm9yZy9vbmxpbmVwdWJzLzk2OTk5MTk3OTkvYmFzZWRl ZnMvVjFfY2hhcDAzLmh0bWwjdGFnXzAzXzM5Nwo+Cj5TbyB0aGlzIGlzIG5vdCBuZWNlc3Nhcmls eSBhIGJ1Zy4KCldoaWxlIEkgZ2VuZXJhbGx5IGFncmVlLCB0aGF0IGN1cnJlbnQgYGhlYWQnIGlt cGxlbWVudGF0aW9uIGRvZXNuJ3QgdmlvbGF0ZSB0aGUgc3RhbmRhcmQsIEkgc3RpbGwgY29uc2lk ZXIKaXQgYSBidWcsIGJlY2F1c2U6CgogKiBgaGVhZCAtbiAtTiBmaWxlbmFtZScgd29ya3MgdGhl IHNhbWUgd2F5IG9uIGZpbGVzIGJvdGggd2l0aCBhbmQgd2l0aG91dCB0cmFpbGluZyBuZXdsaW5l IGZvciBhbGwgTgogICBleGNlcHQgTiA9PSAwLiBGb3IgZXhhbXBsZToKCiAgICQgcHJpbnRmICcx XG4yXG4zJyA+IHRlc3QKICAgJCBoZWFkIC1uIC0xIHRlc3QKICAgMQogICAyCiAgICQgaGVhZCAt biAtMCB0ZXN0CiAgICQgCgogICBJbiBmYWN0LCBgaGVhZCcgd2FzIHdyaXR0ZW4gZXhwbGljaXRs eSB0byBjb25zaWRlciB0aGF0IHRyYWlsaW5nIG5ld2xpbmUgaXMgbm90IGFsd2F5cyBwcmVzZW50 IFsxXS4KCiAgIFRoZSBvbmx5IHJlYXNvbiBOID09IDAgY2FzZSB3b3JrcyBkaWZmZXJlbnRseSBp cyB0aGF0IHRoZSBgbl9saW5lcycgdmFyaWFibGUsIGJlaW5nIHVuc2lnbmVkIGFuZCBlcXVhbAog ICB0byAwLCBpcyBkZWNyZW1lbnRlZCBbMl0sIGFuZCwgYXMgYSByZXN1bHQgb2YgYW4gaW50ZWdl ciB1bmRlcmZsb3csIGdldHMgYSB2ZXJ5IGJpZyAoVUlOVDY0X01BWCkKICAgdmFsdWUsIHdoaWNo IGluIHR1cm4sIGhhdmluZyBpbiBtaW5kIHRoZSAnYWxsIGJ1dCB0aGUgbGFzdCBLIGxpbmVzJyBt ZWFuaW5nLCBsZWFkcyB0byBlbXB0eSBvdXRwdXQuCgogICBJIGd1ZXNzLCBpdCdzIGhpZ2hseSB1 bmxpa2VseSB0byBiZSB0aGUgaW50ZW5kZWQgYmVoYXZpb3IuCgogKiBgdGFpbCAtbiArMCBmaWxl bmFtZScgaGFzIHRoZSB2ZXJ5IHNhbWUgbWVhbmluZyBhY2NvcmRpbmcgdG8gaXRzJyBtYW51YWws IGFuZCBpdCB3b3JrcyBqdXN0IGZpbmU6CgogICAkIHRhaWwgLW4gKzAgdGVzdDsgZWNobwogICAx CiAgIDIKICAgMwogICAkIAoKVG8gc3VtIHVwLCBjdXJyZW50IGBoZWFkJyBiZWhhdmlvciBpcyBs aWtlbHkgdW5pbnRlbmRlZCwgaW5jb25zaXN0ZW50IGFuZCBjb25mdXNpbmcuIFRoYXQncyB3aHkg SSBzdGlsbApjb25zaWRlciBpdCBhIGJ1ZywgbWF5YmUgb2YgYSBsZXNzZXIgcHJpb3JpdHkuCgpb MV0gaHR0cDovL2dpdC5zYXZhbm5haC5nbnUub3JnL2dpdHdlYi8/cD1jb3JldXRpbHMuZ2l0O2E9 YmxvYjtmPXNyYy9oZWFkLmM7aD1kZGFhOTkwNmI0MWVjYzIwZmJiNjdmODdmYWI0MzMwNGM5Y2Ni Njc0O2hiPUhFQUQjbDYzOQpbMl0gaHR0cDovL2dpdC5zYXZhbm5haC5nbnUub3JnL2dpdHdlYi8/ cD1jb3JldXRpbHMuZ2l0O2E9YmxvYjtmPXNyYy9oZWFkLmM7aD1kZGFhOTkwNmI0MWVjYzIwZmJi NjdmODdmYWI0MzMwNGM5Y2NiNjc0O2hiPUhFQUQjbDY0MQoKLS0gCtCQ0LvQtdC60YHQtdC5INCo 0LjQu9C40L0K From debbugs-submit-bounces@debbugs.gnu.org Sun Jan 26 20:24:27 2014 Received: (at control) by debbugs.gnu.org; 27 Jan 2014 01:24:27 +0000 Received: from localhost ([127.0.0.1]:37061 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W7aw7-00036l-6j for submit@debbugs.gnu.org; Sun, 26 Jan 2014 20:24:27 -0500 Received: from mail2.vodafone.ie ([213.233.128.44]:41132) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W7aw4-00036X-7u; Sun, 26 Jan 2014 20:24:25 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApkFAIq05VJtThEL/2dsb2JhbAANTINEUKJPAQGWDYN+gR6DGQEBAQMBMgFGBQsLDQsJFg8JAwIBAgFFBg0BBwEBh3kNA6pSk2uJPBePDQeEOAEDjgGLWIU9hXGIaw Received: from unknown (HELO [192.168.1.79]) ([109.78.17.11]) by mail2.vodafone.ie with ESMTP; 27 Jan 2014 01:24:23 +0000 Message-ID: <52E5B547.2030206@draigBrady.com> Date: Mon, 27 Jan 2014 01:24:23 +0000 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: LGUC Subject: Re: bug#16561: Bug report for 'head' (and 'wc' et. al.) References: <52e524ee.b075340a.4538.01a5@mx.google.com> In-Reply-To: <52e524ee.b075340a.4538.01a5@mx.google.com> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control Cc: 16561@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) forcemerge 16561 16329 stop On 01/26/2014 03:07 PM, LGUC wrote: > THE INCOMPLETE ATTACMENT! (working on sunday makes not my lucky day. > Sorry for the inconveniences!. > Please disregard the previous 2 mails) > __________________________________________________________________ > > Caracas, Sunday 26th, 2014 > Ref: Bug report for 'head' (and 'wc' et. al.) > Dear friends: > Please find attached the text file 'head-tst.txt' > > As you easily can see, the following command fails and do not print > anything, even if the file has: 6 lines, 49 words and 250 chars: > 'head -n -0 head-tst.txt' > The last line on the file does NOT end with a '\n', and this seems > to be the base of the problem. If you add the last '\n', 'head' works > pretty fine. Right that's an issue, coincidentally recently reported: http://bugs.gnu.org/16329 We'll include the fix for that soon. > So this seems to be a problem with the definition of a 'text line': > I guess that a line that has around 68 normal chars and 13 spaces, is > a good candidate to be considered as a line. > I found the same problem in several other core utils, being the > most remarcable 'wc'. If you executes: > 'wc head-tst.txt' > you will get: > 5 49 250 head-tst.txt > what is wrong, as the file has six (6) lines instead of five (5). > The last one line is missing due to the fact that it does not > include a '\n' at the end. > In 1998 I fix 'wc', and I have attached 'wc-fix.c' including only > the most remarkable aspects, in case it could be of any help. So wc is different and is defined by POSIX to only count '\n' chars. So we can't change that really. We might be able to add a --visible-lines option that would handle this and also unicode line separators etc. But that would require more debate since it would be a new option. thanks, Pdraig. From debbugs-submit-bounces@debbugs.gnu.org Wed Jan 29 06:56:23 2014 Received: (at 16329-done) by debbugs.gnu.org; 29 Jan 2014 11:56:23 +0000 Received: from localhost ([127.0.0.1]:39862 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W8Tkk-00036g-Fn for submit@debbugs.gnu.org; Wed, 29 Jan 2014 06:56:22 -0500 Received: from mail3.vodafone.ie ([213.233.128.45]:36018) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W8Tkh-00036X-6i for 16329-done@debbugs.gnu.org; Wed, 29 Jan 2014 06:56:20 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AsABAJjr6FJtTv4m/2dsb2JhbAANTINEUIMEpzySRIEbgxkBAQEEIwRSEAkCDQQDAQIBCRYLAgIJAwIBAgE9CAYNAQUCAQEWh1cDFgOOEZp7dpcvFYgUF44uAQE+EQcJgmaBSQEDkD6BModqhT6FcYctgT6BcQ Received: from unknown (HELO [192.168.1.79]) ([109.78.254.38]) by mail3.vodafone.ie with ESMTP; 29 Jan 2014 11:55:54 +0000 Message-ID: <52E8EC49.1090103@draigBrady.com> Date: Wed, 29 Jan 2014 11:55:53 +0000 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: =?UTF-8?B?0JDQu9C10LrRgdC10Lkg0KjQuNC70LjQvQ==?= Subject: Re: bug#16329: Acknowledgement (`head --lines=-0' prints nothing if no newline at the EOF) References: <1388764256.577663010@f412.i.mail.ru> <1388781627.45947684@f346.i.mail.ru> In-Reply-To: <1388781627.45947684@f346.i.mail.ru> X-Enigmail-Version: 1.6 Content-Type: multipart/mixed; boundary="------------030008040109060905060006" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 16329-done Cc: 16329-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) This is a multi-part message in MIME format. --------------030008040109060905060006 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 01/03/2014 08:40 PM, Алексей Шилин wrote: > Looks like I was overly cautious about decrementing an unsigned... > > size_t n = bytes_read; > while (n) > { > if (all_lines) > n -= n ? 1 : 0; // ...here. > else > > As it is under `while (n)' statement, n is always true here, and thus the ternary operator, though makes no > harm, is needless, and the whole line can be replaced with just `n--;'. Sorry for that. > > The fixed version of the original patch is attached. > I've updated the patch to also handle the pipe case, and I added a test. Will push soon. thanks, Pádraig. --------------030008040109060905060006 Content-Type: text/x-patch; name="head--lines-0.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="head--lines-0.patch" >From b1387eb3e922398ab90cf6aa63cac6dea37971fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=A8=D0=B8=D0?= =?UTF-8?q?=BB=D0=B8=D0=BD?= Date: Wed, 29 Jan 2014 01:23:46 +0000 Subject: [PATCH] head: fix --lines=-0 outputting nothing if no newline at EOF * src/head.c (elide_tail_lines_pipe): Just output all input in this case to avoid the issue and also avoid redundant '\n' processing. (elide_tail_lines_seekable): Likewise. * tests/misc/head-elide-tail.pl: Add tests for no '\n' at EOF. * NEWS: Mention the fix. Fixes http://bugs.gnu.org/16329 --- NEWS | 4 ++++ src/head.c | 27 +++++++++++++++++++++------ tests/misc/head-elide-tail.pl | 7 +++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index e091d18..f86e589 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ GNU coreutils NEWS -*- outline -*- when reading the SELinux context for a file. [bug introduced in coreutils-8.22] + head --lines=-0, when the input does not contain a trailing '\n', + now copies all input to stdout. Previously nothing was output in this case. + [bug introduced with the --lines=-N feature in coreutils-5.0.1] + ln -sf now replaces symbolic links whose targets can't exist. Previously it would display an error, requiring --no-dereference to avoid the issue. [bug introduced in coreutils-5.3.0] diff --git a/src/head.c b/src/head.c index ddaa990..ef368d7 100644 --- a/src/head.c +++ b/src/head.c @@ -501,6 +501,13 @@ elide_tail_lines_pipe (const char *filename, int fd, uintmax_t n_elide) n_read = safe_read (fd, tmp->buffer, BUFSIZ); if (n_read == 0 || n_read == SAFE_READ_ERROR) break; + + if (! n_elide) + { + fwrite (tmp->buffer, 1, n_read, stdout); + continue; + } + tmp->nbytes = n_read; tmp->nlines = 0; tmp->next = NULL; @@ -636,8 +643,11 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, return false; } + /* n_lines == 0 case needs special treatment. */ + const bool all_lines = !n_lines; + /* Count the incomplete line on files that don't end with a newline. */ - if (bytes_read && buffer[bytes_read - 1] != '\n') + if (n_lines && bytes_read && buffer[bytes_read - 1] != '\n') --n_lines; while (1) @@ -647,11 +657,16 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, size_t n = bytes_read; while (n) { - char const *nl; - nl = memrchr (buffer, '\n', n); - if (nl == NULL) - break; - n = nl - buffer; + if (all_lines) + n -= 1; + else + { + char const *nl; + nl = memrchr (buffer, '\n', n); + if (nl == NULL) + break; + n = nl - buffer; + } if (n_lines-- == 0) { /* Found it. */ diff --git a/tests/misc/head-elide-tail.pl b/tests/misc/head-elide-tail.pl index 758e1c9..3c178d6 100755 --- a/tests/misc/head-elide-tail.pl +++ b/tests/misc/head-elide-tail.pl @@ -52,6 +52,8 @@ my @Tests = ['elide-l2', "--lines=-1", {IN=>"a"}, {OUT=>''}], ['elide-l3', "--lines=-1", {IN=>"a\nb"}, {OUT=>"a\n"}], ['elide-l4', "--lines=-1", {IN=>"a\nb\n"}, {OUT=>"a\n"}], + ['elide-l5', "--lines=-0", {IN=>"a\nb\n"}, {OUT=>"a\nb\n"}], + ['elide-l6', "--lines=-0", {IN=>"a\nb"}, {OUT=>"a\nb"}], ); if ($ENV{RUN_EXPENSIVE_TESTS}) @@ -80,9 +82,10 @@ if ($ENV{RUN_EXPENSIVE_TESTS}) } $s =~ s/(.)/$1\n/g; - for my $file_size (0..20) + $s .= 'u'; # test without trailing '\n' + for my $file_size (0..21) { - for my $n_elide (0..20) + for my $n_elide (0..21) { my $input = substr $s, 0, 2 * $file_size; my $out_len = $n_elide < $file_size ? $file_size - $n_elide : 0; -- 1.7.7.6 --------------030008040109060905060006-- From unknown Sun Jun 22 03:56:02 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Wed, 26 Feb 2014 12:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator