9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Russ Cox" <rsc@swtch.com>
To: "Fans of the OS Plan 9 from Bell Labs" <9fans@cse.psu.edu>
Subject: Re: [9fans] echo -n
Date: Mon, 20 Nov 2006 15:38:37 -0500	[thread overview]
Message-ID: <ee9e417a0611201238w259150c4g154090e7649f9f56@mail.gmail.com> (raw)
In-Reply-To: <5c2bf4a5c8ff68ef5e1bfd2db024e300@plan9.jp>

> 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


  parent reply	other threads:[~2006-11-20 20:38 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-20  8:40 arisawa
2006-11-20  9:45 ` Martin Neubauer
2006-11-20 10:42   ` lucio
2006-11-20 17:35     ` maht
2006-11-20 12:46 ` Russ Cox
2006-11-20 14:41   ` John Stalker
2006-11-20 14:59     ` Dave Lukes
2006-11-20 14:59     ` Axel Belinfante
2006-11-20 15:34       ` ron minnich
2006-11-20 15:43       ` erik quanstrom
2006-11-20 16:37   ` Joel Salomon
2006-11-20 18:49     ` Russ Cox
2006-11-20 19:16       ` Francisco J Ballesteros
2006-11-20 19:57         ` Joel Salomon
2006-11-20 20:18           ` Federico Benavento
2006-11-20 20:38           ` Russ Cox [this message]
2006-11-20 21:00             ` Joel Salomon
2006-11-20 21:05             ` Francisco J Ballesteros
2006-11-20 21:55               ` Russ Cox
2006-11-20 22:11                 ` Francisco J Ballesteros
2006-11-20 22:24                   ` Martin Neubauer
2006-11-20 23:14                   ` Gorka guardiola
2006-11-20 23:22                     ` Francisco J Ballesteros
2006-11-20 23:57                       ` Gorka guardiola
2006-11-21  3:24               ` lucio
2006-11-20 19:32       ` Joel Salomon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee9e417a0611201238w259150c4g154090e7649f9f56@mail.gmail.com \
    --to=rsc@swtch.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).