[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: and _PC_PIPE_BUF..
From: |
James A. Morrison |
Subject: |
Re: and _PC_PIPE_BUF.. |
Date: |
24 Apr 2003 10:35:32 -0400 |
On Wed, 2003-04-23 at 19:25, Robert Millan wrote:
> On Wed, Apr 23, 2003 at 10:24:28PM +0200, Robert Millan wrote:
> >
> >
> > one more thing, it appears to me that fpathconf(fd, _PC_PIPE_BUF) is
> > always -1 for files, and has a positive value for pipes, fifos and
> > sockets. is that it? (for GNU and for any system)
>
> i'd better show an example, this is fixed code from gs. does it seem
> correct to you? (considering the file descriptor is expected to be
> a socket, if pipe_buf is -1 then something weird happened)
>
> /* Get packet from the server. */
> private int hpijs_get_pk(PK * pk, int fd)
> {
> #ifdef PIPE_BUF
> return read(fd, pk, PIPE_BUF - 1);
> #else
> long int pipe_buf = fpathconf(fd, _PC_PIPE_BUF);
> if (pipe_buf == -1)
> /* no pipe_buf, so we fail */
> return -1;
> else
> return read(fd, pk, pipe_buf - 1);
> #endif
> }
>
> --
> Robert Millan
Why not use fpathconf if it is available?
i.e.
#ifdef HAVE_FPATHCONF
long int pipe_buf = fpathconf(fd, _PC_PIPE_BUF);
if (pipe_buf == -1)
/* fpathconf failed, fd probably isn't a pipe. */
return -1;
else
return read(fd, pk, pipe_buf - 1);
#else
return read(fd, pk, PIPE_BUF - 1);
#endif
Jim