9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: EBo <ebo@sandien.com>
To: plan9port <plan9port-dev@googlegroups.com>, 9Fans-list <9fans@9fans.net>
Subject: read(2) problem on p9p?
Date: Fri, 13 Aug 2010 10:54:52 -0600	[thread overview]
Message-ID: <669f246aba1d324e377a93d730962f41@swcp.com> (raw)



This might be a stupid question, but I have a regression test that is
returning an unintuitive result from a read(2).  The relevant part of the
regression test follows:

    char *tst_str = "this is a test... this is only a test.";

    ret = fprint(dtf, tst_str);
    test(strlen(tst_str)==ret,2,
     "write  %s to variable\n",tst_str);

    // zero out so I know I have clean data
    memset(buf,0,sizeof buf);

    // FIXME: read returns 0, but reads the buff as
    //   expected.  The docs, read(2), sais that a return of
    //   0 suggests eof, but suggests that read should
    //   otherwise return the number of bytes read.
    ret = read(dtf, buf, 1024);
    test(strlen(tst_str)==ret,4, "read back from var\n");
    close(dtf);

    test(!strcmp(tst_str,buf)==ret,4, "check value\n");

Basically the above writes a string to a file reads it back and checks the
value.  All that works except for the value returned by read.  The docs
state that read should return the number of bytes read, and a 0 implies
eof.  I the above case I asked it to read a huge block which read all the
data in the file correctly, but also read to the end of file.  Shouldn't
read return nbytes (strlen(tst_str) in this case), and return 0 if I try to
read past EOF again?  If this is not the plan9 way, how do I check for how
many bytes was read in?

Just to be clear, the last test succeeded -- I read in the entire string
back in and succeeded.

  EBo --



             reply	other threads:[~2010-08-13 16:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-13 16:54 EBo [this message]
2010-08-13 17:16 ` [9fans] " erik quanstrom
2010-08-13 17:46   ` EBo
2010-08-13 17:51 ` Skip Tavakkolian
2010-08-13 18:14   ` Russ Cox
2010-08-13 18:35     ` EBo
2010-08-13 18:46       ` Russ Cox
2010-08-13 19:03         ` EBo
2010-08-13 18:16   ` EBo
2010-08-13 18:58     ` erik quanstrom

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=669f246aba1d324e377a93d730962f41@swcp.com \
    --to=ebo@sandien.com \
    --cc=9fans@9fans.net \
    --cc=plan9port-dev@googlegroups.com \
    /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).