GNU bug report logs - #8103
tac RFE: accept -z, --zero-terminated option

Previous Next

Package: coreutils;

Reported by: Bjartur Thorlacius <svartman95 <at> gmail.com>

Date: Wed, 23 Feb 2011 23:26:02 UTC

Severity: wishlist

Tags: easy, notabug

Full log


View this message in rfc822 format

From: "Alan Curry" <pacman-cu <at> kosh.dhis.org>
To: svartman95 <at> gmail.com (Bjartur Thorlacius)
Cc: 8103 <at> debbugs.gnu.org, Jim Meyering <jim <at> meyering.net>
Subject: bug#8103: NUL terminated lines
Date: Thu, 24 Feb 2011 17:13:19 -0500 (GMT+5)
Bjartur Thorlacius writes:
> 
> On 2/24/11, Jim Meyering <jim <at> meyering.net> wrote:
> > Bjartur Thorlacius wrote:
> >>> Maybe we should modify tac to add the -z option.  Would you care to
> >> write a patch?
> >> It would be redundant, as tac -s $'\0' is equivalent.

Note that a $'\0' argument in a shell command line is exactly equivalent to
an empty string, since it must be passed from the shell to the program using
execve() which takes NUL-terminated strings.

There is no way to run a program with an actual NUL byte contained in one of
its arguments. execve will stop copying at the NUL, and even if it didn't,
the new program receives its arguments in int argc, char **argv form so how
is it supposed to know that there's a NUL in there that's not a terminator?

This limitation can't be avoided. It's not just a C language thing. The
execve interface is based on NUL-terminated strings at the asm level too.

If tac -s $'\0' did something different from tac -s '', it could only have
been a shell builtin. (Assuming the shell supported the $'...' notation at
all)

-- 
Alan Curry




This bug report was last modified 6 years and 252 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.