From owner-freebsd-bugs Fri Jan 7 11:32: 0 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from bubba.whistle.com (bubba.whistle.com [207.76.205.7]) by hub.freebsd.org (Postfix) with ESMTP id DC3B71575B for ; Fri, 7 Jan 2000 11:31:55 -0800 (PST) (envelope-from archie@whistle.com) Received: (from archie@localhost) by bubba.whistle.com (8.9.2/8.9.2) id LAA57370; Fri, 7 Jan 2000 11:30:57 -0800 (PST) From: Archie Cobbs Message-Id: <200001071930.LAA57370@bubba.whistle.com> Subject: Re: bin/15929: printf(1) truncates if it sees 000 In-Reply-To: from Bruce Evans at "Jan 7, 2000 07:00:59 pm" To: bde@zeta.org.au (Bruce Evans) Date: Fri, 7 Jan 2000 11:30:57 -0800 (PST) Cc: sheldonh@uunet.co.za, freebsd-bugs@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL54 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Bruce Evans writes: > > > > $ printf 'a\000truncated\n' > > > > > > > > This outputs "a" instead of "atruncated" > > > > > > What would you expect to happen, given that printf(3) exhibits the same > > > behaviour? > > > > No, I'm not at all surprised. > > > > But that's not the point, of course. Either the bug should be fixed > > or else at least declared 'normal' and so documented in the man page. > > printf(1) does seem to be incompatible with printf(3) here. From a POSIX > draft: > > (3) In addition to the escape sequences shown in Table 2-15 (see > 2.12), \ddd, where ddd is a one-, two-, or three-digit octal > number, shall be written as a byte with the numeric value > specified by the octal number. > converted string shall be written. > > There seems to be no special case for the escape sequence \000. I think > this is a bug in the POSIX draft. In C, printf(3) would never see the > escape sequence \000; it would see a hard \0. You would have to use %c > format to print a hard \0. In fact, there seems to be no way to print a NUL character using printf(1), which is why I got stuck in the first place. If you try ``printf "%c" 0'' then you get '0' instead of NUL. If you try ``printf "\000"'' then you get the empty string. -Archie ___________________________________________________________________________ Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message