9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Dan Cross <cross@math.psu.edu>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] weird print(2) problems...
Date: Wed,  5 Sep 2001 14:23:14 -0400	[thread overview]
Message-ID: <200109051823.OAA03645@augusta.math.psu.edu> (raw)
In-Reply-To: <20010905150808.1FC2619A32@mail.cse.psu.edu>

In article <20010905150808.1FC2619A32@mail.cse.psu.edu> you write:
>>>that if write(2) sees a zero length argument, it should consider that a
>>>nop and return.  But then it seems that that would break some weird
>>>semantic somewhere (``Any write will update a timestamp; except for
>>>zero length writes, which are ignored.'' ``Dude, that's broken.'')
>
>it isn't only the possible effect on time stamps; i think it
>should do a write 0 because it's what you said to do.

Yes, that's what I mean by ``breaking some weird semantic''  (although
the semantic isn't that weird).  The timestamp thing was just a contrived
example.

>to be fair, it's disguised by print, but even so,
>if i wanted nop() i'd use
>	;
>or
>	void nop(void){}
>but i wouldn't call write() or even print.  i'd call write() when i wanted
>to write, and i prefer systems that do what i tell it, so that if i say
>`write 0 bytes' i expect it to do that, rather than adding yet
>more special cases to remember.

I don't disagree, but the behavior I've observed is demonstrably broken.

I'm looking for a fix to the system so that the guy writing a program
doesn't have to worry if he's accidentally printing out a blank string;
that's the special case I want to avoid.

After all, if I write zero bytes, I don't expect the program on the
other end of my pipe to stop reading all of a sudden.

>  the effect of writing 0 bytes
>is determined by the device, but that's true of writing 1 byte or many,
>so there's no difference there.

Yes there is.  When the program I'm piping to reads zero bytes, it stops
reading.  If it reads n > 0 bytes, it does not.

>on the other hand, i'd probably write
>	if(*str)
>		print("%s", str);
>if that's what i wanted.

Sure, that's how I fixed the program at hand (which generates morse
code, btw).

But isn't this also a special case I now need to remember?  Worse I
have to remember it when writing user level programs; the complexity
of it (granted, not much) isn't hidden from me.  It's a bummer;
surely there's an elegant solution to this problem.

	- Dan C.



  reply	other threads:[~2001-09-05 18:23 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-05 15:11 forsyth
2001-09-05 18:23 ` Dan Cross [this message]
2001-09-05 19:10   ` Boyd Roberts
  -- strict thread matches above, loose matches on Subject: below --
2001-09-11 11:16 rob pike
     [not found] <rsc@plan9.bell-labs.com>
2001-09-05 21:11 ` Russ Cox
2001-09-05 21:24   ` Scott Schwartz
2001-09-05 19:46 Russ Cox
2001-09-05 19:19 Russ Cox
2001-09-05 19:40 ` Boyd Roberts
2001-09-06  8:19 ` Matthew Hannigan
2001-09-06 16:18 ` Douglas A. Gwyn
2001-09-06 20:45   ` Boyd Roberts
2001-09-05 18:40 Russ Cox
2001-09-05 19:58 ` Dan Cross
     [not found] <cross@math.psu.edu>
2001-09-04 19:02 ` Dan Cross
2001-09-04 19:08   ` Scott Schwartz
2001-09-05 14:22     ` Dan Cross
2001-09-05 19:01       ` Boyd Roberts

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=200109051823.OAA03645@augusta.math.psu.edu \
    --to=cross@math.psu.edu \
    --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).