From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: Date: Mon, 20 Nov 2006 15:38:37 -0500 From: "Russ Cox" To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu> Subject: Re: [9fans] echo -n In-Reply-To: <5c2bf4a5c8ff68ef5e1bfd2db024e300@plan9.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <8ccc8ba40611201116r89eba04m32cf9d487a02ceb5@mail.gmail.com> <5c2bf4a5c8ff68ef5e1bfd2db024e300@plan9.jp> Topicbox-Message-UUID: e2d7edc8-ead1-11e9-9d60-3106f5b1d025 > That seems to be the definition under the Unix. From the Single UNIX > Specification, version 2 man page for write(): > If nbyte is 0, write() will return 0 and have no other results > if the file is a regular file; otherwise, the results are > unspecified. > SUS3 is more verbose, but seems to have the same intent. You missed the part where it says "if the file is a regular file; otherwise the results are unspecified." Pipes are not regular files. And even if the spec did say what you said it said, Plan 9 is not Unix. Where Plan 9 and Unix differ, the solution is typically not to make Plan 9 more like Unix. This discussion is confusing lots of separate questions. Q. Should 9P permit a zero-length response to read? A. Yes. Q. Should 9P permit a non-zero-length response to read after a zero-length response? A. Yes. How else could a file server implement /dev/cons? (Think about what happens when the user types ^D at the console.) Q. Should 9P permit a zero-length write? A. Yes. I haven't seen a good argument not to. Certainly we don't want to make write(1, "", 0) an error. Q. Should pipes preserve message boundaries? A. Yes. It is a useful convention, one that Plan 9 used to rely on heavily. (One 9P message per write, one 9P message per read, no need for inserting length headers in the messages.) Perhaps some other application will come along that will need it. Q. Should pipes preserve zero-length messages? A. Yes. If you're preserving message boundaries, then it follows that zero-length writes on one end should result in zero-length reads on the other. Q. Should echo -n generate a zero length write? (the original question) A. There are valid arguments for both answers, and once you're in the preserving-message-boundaries mindset, probably yes edges out no. But even if not, the code is written and just as many people would be upset if it were the other way, so it's not worth changing. Q. Does echo -n generate a zero length write? A. Yes. Get over it. Russ