9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] writing to ctl using fprint and write
@ 2010-07-29 12:02 EBo
  2010-07-29 12:06 ` erik quanstrom
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: EBo @ 2010-07-29 12:02 UTC (permalink / raw)
  To: 9Fans-list

I'm working on some regression testing for my GSoC project and am trying
to understand why

  ctl = open(path("ctl"),ORDWR|OAPPEND);
  ts = "chatty9p 1"; // or some other message

  n = fprint(ctl, ts);

succeeds, while

  n = write(ctl,ts,sizeof(ts));

fails.

Can someone explain?

  EBo --




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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 12:02 [9fans] writing to ctl using fprint and write EBo
@ 2010-07-29 12:06 ` erik quanstrom
  2010-07-29 13:21   ` EBo
  2010-07-29 12:07 ` Skip Tavakkolian
  2010-07-29 12:12 ` Sape Mullender
  2 siblings, 1 reply; 10+ messages in thread
From: erik quanstrom @ 2010-07-29 12:06 UTC (permalink / raw)
  To: 9fans

>   n = fprint(ctl, ts);
>
> succeeds, while
>
>   n = write(ctl,ts,sizeof(ts));
>
> fails.

sizeof(ts) == 4 or 8, depending on the arch.
you wish strlen(ts).

- erik



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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 12:02 [9fans] writing to ctl using fprint and write EBo
  2010-07-29 12:06 ` erik quanstrom
@ 2010-07-29 12:07 ` Skip Tavakkolian
  2010-07-29 12:12 ` Sape Mullender
  2 siblings, 0 replies; 10+ messages in thread
From: Skip Tavakkolian @ 2010-07-29 12:07 UTC (permalink / raw)
  To: 9fans

how is ts declared?

> I'm working on some regression testing for my GSoC project and am trying
> to understand why
>
>   ctl = open(path("ctl"),ORDWR|OAPPEND);
>   ts = "chatty9p 1"; // or some other message
>
>   n = fprint(ctl, ts);
>
> succeeds, while
>
>   n = write(ctl,ts,sizeof(ts));
>
> fails.
>
> Can someone explain?
>
>   EBo --




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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 12:02 [9fans] writing to ctl using fprint and write EBo
  2010-07-29 12:06 ` erik quanstrom
  2010-07-29 12:07 ` Skip Tavakkolian
@ 2010-07-29 12:12 ` Sape Mullender
  2 siblings, 0 replies; 10+ messages in thread
From: Sape Mullender @ 2010-07-29 12:12 UTC (permalink / raw)
  To: 9fans; +Cc: 9fans

> I'm working on some regression testing for my GSoC project and am trying
> to understand why
>
>  ctl = open(path("ctl"),ORDWR|OAPPEND);
>  ts = "chatty9p 1"; // or some other message
>
>  n = fprint(ctl, ts);
>
> succeeds, while
>
>  n = write(ctl,ts,sizeof(ts));
>
> fails.
>
> Can someone explain?

Obviously, ts is a char* and, therefore, its size is 4.
You want strlen(ts) instead of sizeof(ts).

	Sape



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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 12:06 ` erik quanstrom
@ 2010-07-29 13:21   ` EBo
  2010-07-29 15:04     ` erik quanstrom
  0 siblings, 1 reply; 10+ messages in thread
From: EBo @ 2010-07-29 13:21 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs


>>   n = fprint(ctl, ts);
>>
>> succeeds, while
>>
>>   n = write(ctl,ts,sizeof(ts));
>>
>> fails.
>
> sizeof(ts) == 4 or 8, depending on the arch.
> you wish strlen(ts).

Thanks Erik, Sape, and Skip.  That was such a STUPID error, and I thank
you all for the extra eyes.  I think it is time for a break and a bowl of
tea...

As a side note, I now have over 40 regression tests written, and as soon
as I soon as I clean up one of the servers to my liking I should have a
bunch more.

Thanks everyone.

  EBo --




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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 13:21   ` EBo
@ 2010-07-29 15:04     ` erik quanstrom
  2010-07-29 15:11       ` David Leimbach
                         ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: erik quanstrom @ 2010-07-29 15:04 UTC (permalink / raw)
  To: 9fans

> Thanks Erik, Sape, and Skip.  That was such a STUPID error, and I thank
> you all for the extra eyes.  I think it is time for a break and a bowl of
> tea...

relax.  not stupid, subtle.  it takes vigilance to keep
sizeof, nelem, strlen, and the number of characters
straight.

- erik



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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 15:04     ` erik quanstrom
@ 2010-07-29 15:11       ` David Leimbach
  2010-07-29 23:42         ` Federico G. Benavento
  2010-07-29 15:18       ` Brian L. Stuart
  2010-07-29 15:27       ` EBo
  2 siblings, 1 reply; 10+ messages in thread
From: David Leimbach @ 2010-07-29 15:11 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 742 bytes --]

On Thu, Jul 29, 2010 at 8:04 AM, erik quanstrom <quanstro@quanstro.net>wrote:

> > Thanks Erik, Sape, and Skip.  That was such a STUPID error, and I thank
> > you all for the extra eyes.  I think it is time for a break and a bowl of
> > tea...
>
> relax.  not stupid, subtle.  it takes vigilance to keep
> sizeof, nelem, strlen, and the number of characters
> straight.
>
> - erik
>
>
And you *can* use sizeof on arrays :-).

Well at least in ANSI/ISO C.  Haven't tried this on plan 9.  :-)

On my mac I get 6 and 8.

#include <stdio.h>

char blah [] = "Hello";
char * blah2 = "There";

int main  () {

        printf("sizeof blah: %ld\n", sizeof(blah));
        printf("sizeof blah2: %ld\n", sizeof(blah2));

}

[-- Attachment #2: Type: text/html, Size: 1344 bytes --]

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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 15:04     ` erik quanstrom
  2010-07-29 15:11       ` David Leimbach
@ 2010-07-29 15:18       ` Brian L. Stuart
  2010-07-29 15:27       ` EBo
  2 siblings, 0 replies; 10+ messages in thread
From: Brian L. Stuart @ 2010-07-29 15:18 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> > Thanks Erik, Sape, and
> Skip.  That was such a STUPID error, and I thank
> > you all for the extra eyes.  I think it is time
> for a break and a bowl of
> > tea...
> 
> relax.  not stupid, subtle.  it takes vigilance
> to keep
> sizeof, nelem, strlen, and the number of characters
> straight.

This is part of why I often recommend (and generally
do myself) that sizeof only be used on types, not
variables:

Foo bar;

use sizeof(Foo) rather than sizeof(bar).  It does
require slightly more work for arrays:

Foo bar[NFOO];

requires NFOO * sizeof(Foo) rather than sizeof(bar),
but I personally think it's worth it to keep the
distinction between sizeof and strlen straight.

BLS




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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 15:04     ` erik quanstrom
  2010-07-29 15:11       ` David Leimbach
  2010-07-29 15:18       ` Brian L. Stuart
@ 2010-07-29 15:27       ` EBo
  2 siblings, 0 replies; 10+ messages in thread
From: EBo @ 2010-07-29 15:27 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs


> relax.  not stupid, subtle.  it takes vigilance to keep
> sizeof, nelem, strlen, and the number of characters
> straight.

I was not offended or anything.  I spent WAY to much time missing on that
one before asking for another set of eyes.  I just felt a bit foolish for
missing something that simple, and yes it is a subtle error.  That's all.
The funny thing is that I had it reading correctly using sizeof(some
struct), and then blew it when I was writing a string.  Anyway, it all
works now.

I really do appreciate the catch.

  EBo --




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

* Re: [9fans] writing to ctl using fprint and write
  2010-07-29 15:11       ` David Leimbach
@ 2010-07-29 23:42         ` Federico G. Benavento
  0 siblings, 0 replies; 10+ messages in thread
From: Federico G. Benavento @ 2010-07-29 23:42 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

sorry, but I didn't get the point

On Thu, Jul 29, 2010 at 12:11 PM, David Leimbach <leimy2k@gmail.com> wrote:
>
>
> On Thu, Jul 29, 2010 at 8:04 AM, erik quanstrom <quanstro@quanstro.net>
> wrote:
>>
>> > Thanks Erik, Sape, and Skip.  That was such a STUPID error, and I thank
>> > you all for the extra eyes.  I think it is time for a break and a bowl
>> > of
>> > tea...
>>
>> relax.  not stupid, subtle.  it takes vigilance to keep
>> sizeof, nelem, strlen, and the number of characters
>> straight.
>>
>> - erik
>>
>
> And you *can* use sizeof on arrays :-).
> Well at least in ANSI/ISO C.  Haven't tried this on plan 9.  :-)
> On my mac I get 6 and 8.
> #include <stdio.h>
> char blah [] = "Hello";
> char * blah2 = "There";
> int main  () {
>         printf("sizeof blah: %ld\n", sizeof(blah));
>         printf("sizeof blah2: %ld\n", sizeof(blah2));
> }
>
>



-- 
Federico G. Benavento



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

end of thread, other threads:[~2010-07-29 23:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-29 12:02 [9fans] writing to ctl using fprint and write EBo
2010-07-29 12:06 ` erik quanstrom
2010-07-29 13:21   ` EBo
2010-07-29 15:04     ` erik quanstrom
2010-07-29 15:11       ` David Leimbach
2010-07-29 23:42         ` Federico G. Benavento
2010-07-29 15:18       ` Brian L. Stuart
2010-07-29 15:27       ` EBo
2010-07-29 12:07 ` Skip Tavakkolian
2010-07-29 12:12 ` Sape Mullender

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