Number of bytes in terminal input queue w/o blocking and consuming?

Hello, everyone.

Could someone, please, tell me how to get the number of bytes in the terminal input queue without blocking and without consuming these bytes? I guess it could be called the peek functionality.

I've looked at termio tcgetattr() and tcsetattr() functions but could not find exactly what I need. I know I can poll() on stdin. But I don't want to read after poll() returns. I just want to see how many characters, if any, can be read without blocking from stdin - terminal in my case.

Thanks for any hints.
Lucy.

poll() and select() returning guarantees that an attempted read will not block, it does not guarantee what will happen - error condition, EOF, whatever.

This is what POSIX says:

Plus, there is no way to know how many bytes can be read if a read were successful.
Try just reading a single byte then poll() or select().

Thank you for your reply, Jim. This is not going to work. Reading data means it will be removed from the terminal input queue. That is not what I want. I am not interested in data. I am interested in how much data is available. Similar to recv( MSG_PEEK) for sockets.
There is no way to do this with section two read/write. Hence, this post. And, hence, my idea that answer lies in the bowls of termio. Any termio gurus out there?

There is no standard API for returning this information. You need to use the FIONREAD ioctl if it is available on your platform. Typical code would be something like the following.

  #include <sys/ioctl.h>

  int chars_avail;
  int result;

  result = ioctl (tty, FIONREAD, &chars_avail);

You are a genius, fpmurphy.
It works.
On Sun Solaris I had to include <sys/filio.h>
Notes: tested it with
1). nothing typed - character count is zero.
2). something typed, but not followed by Enter key - character count is zero.
3). something typed followed by Enter key - character count includes new line.

It's ok, since default input mode is canonical - line oriented. At this point I can play with setting the terminal to raw mode hoping to get character count regardless of user hitting Enter or not, but that becomes application specific and the problem in general is solved.

fpmurphy, thanks again.
Lucy.