[Top][All Lists]

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

bug#8103: NUL terminated lines

From: Alan Curry
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 <address@hidden> 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

Alan Curry

reply via email to

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