[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: and _PC_PIPE_BUF..

From: Niels Möller
Subject: Re: and _PC_PIPE_BUF..
Date: 27 Apr 2003 11:03:19 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

Robert Millan <> writes:

> I'd say that pk is initialised without allocation, but I'm not sure, the
> pk declaration is a bit confusing.

The pk argument to the function is a pointer to some type called PK.
That means that it must in some way be allocated by the caller, so you
have to look at the function(s) calling hpijs_get_pk. I haven't done
that, I just guessed[1] that the calling code looks something like

  PK packet;
  hpijs_get_pk(&packet, some_fd);

In this case, the allocated size is sizeof(PK), i.e. the size it takes
to store one object of the type PK. The C compiler takes care of the
allocation details.

> > or, if it really depends on PIPE_BUF semantics,
> > 
> >   long int pipe_buf;
> > #if PIPE_BUF
> >   pipe_buf = PIPE_BUF;
> > #else
> >   pipe_buf = fpathconf(fd, _PC_PIPE_BUF);
> > #endif
> >   if (pipe_buf < sizeof(*pk))
> >     /* pipe_buf too small (or not existing), so we fail */
> >     return -1;
> >   else
> >     return read(fd, pk, sizeof(*pk))
> i guess you mean read(fd, pk, pipe_buf) here.

No, I really meant sizeof(*pk) (which is the same as sizeof(PK)). The
point is to give read the allocated size of *pk, so that it can't
overwrite the buffer. That is based on my guess above on how the
caller allocates the space for pk.

[1] It could be something more obscure or more sophisticated, like an
    array or some variable size struct, or char array of some explicit
    size PIPE_BUF casted to a PK *.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]