Given FILE* or a file descriptor, is there a standard way to know how many bytes are ready to be read?
I cannot use s=ftell(f),fseek(f,0,SEEK_END),e=ftell(f),fseek(f,s,SEEK_SET),es , since FILE* just wraps the file descriptor I received from pipe(2) and I get ESPIPE when I try this.
I thought to use select(2) with a zero timeout to say that I have at least one byte ready to read, and then read the byte at a time, until select(2) told me to stop. This seems to be rather awkward and slow.
Is there a better way to do this?
c pipe file-descriptor
rampion
source share