9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* read(2) problem on p9p?
@ 2010-08-13 16:54 EBo
  2010-08-13 17:16 ` [9fans] " erik quanstrom
  2010-08-13 17:51 ` Skip Tavakkolian
  0 siblings, 2 replies; 10+ messages in thread
From: EBo @ 2010-08-13 16:54 UTC (permalink / raw)
  To: plan9port, 9Fans-list



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 --



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-08-13 19:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-13 16:54 read(2) problem on p9p? EBo
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

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).