Writting a new implementation for Monkey, I was looking for some way to know "how many bytes are ready to be readen from a Pipe"?, obviously I want to get that information before to read them. As I coudn't find any information I wrote to Linus Torvalds requiring him a new syscall to do it... Today I got his response:
int bytes, err;
err = ioctl(fd, FIONREAD, &bytes);is the traditional UNIX way to query how many bytes are readable right now
in a pipe (or a socket or tty, for that matter).NOTE! There is _not_ a way to query how much you could write to a pipe,
though. Although normally I think you should be able to rely on being able
to write PIPE_BUF characters if a poll() or select() says "writable". But
you may be able to write more.
Hope this tip help someone... thanks Linus!