[Patch/RFC] Fix libstdc++/9533

Nathan Myers ncm-nospam@cantrip.org
Thu Mar 20 01:44:00 GMT 2003


On Wed, Mar 19, 2003 at 11:10:44AM +0100, Paolo Carlini wrote:
> Nathan Myers wrote:
> >On Thu, Mar 13, 2003 at 01:54:48PM +0100, Paolo Carlini wrote:
> >
> >>the below fixes the problem by implementing a non-trivial showmanyc(),
> >>as discussed thoroughly on the list during the last weeks.
> 
> >First, the above code can only reveal information about sockets, and 
> >not, unfortunately, pipes.  (On a pipe it reports failure.)  So, the 
> >comment is not right.  Still, sockets are important enough to merit 
> >the special treatment.

I have been doing some more exploring, and have discovered (drum roll) 
ioctl()!  (This is meant ironically.  Everybody hates ioctl, but nobody 
knows how to do it any better.)

We can use 

  #include <sys/ioctl.h>

  int i = 0;
  ::ioctl(fd, FIONREAD, &i)

on any file descriptor (pipe, socket, file, character device) to see 
how much is available to read.  

Note that ioctl is not part of POSIX, and that it is often found at 
<ioctl.h> instead.  Also, for files bigger than 2G it reports silly
results. 

Nathan Myers
ncm-nospam@cantrip.org



More information about the Libstdc++ mailing list