This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Toward a satisfactory showmanyc
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: Nathan Myers <ncm at cantrip dot org>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 20 Mar 2003 20:52:30 +0100
- Subject: Toward a satisfactory showmanyc
Hi Nathan, hi everyone,
and sorry for late following up to your interesting messages.
> #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.
and then:
On many targets it doesn't work on regular files at all. On some
targets (apparently including FreeBSD and Solarix 9) FIONREAD is
defined in <sys/filio.h>. See also
Therefore, what about this updated strategy for showmanyc (easily
extensible to large file support, it seems to me):
1- fstat on files.
2- If fstat fails, ioctl for everything else.
Of course this implies autoconf machinery for <sys/ioctl.h>
vs <ioctl.h> and also for FIONREAD in <sys/filio.h>
(I had hoped for fewer different possibilites :(
If we agree by and large on this sketch, I can work on it during the
next few days.
Thanks,
Paolo.