This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch/RFC] Fix libstdc++/9533


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 at cantrip dot org


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]