When reading from a pipe in Linux (C, fread/similar), when EOF is reached, how can it be known how many bytes were read? If I read blocks at a time, fread() only returns the number of full blocks read in, and I can’t read one byte at a time because that is too slow. Of course, ftell() returns -1.
Share
You can do this with
fread()by setting thesizeparam to 1 and set thenmembersto whatever size you like. Then the number of “members” is the number of bytes and you can still have a decent sized buffer:instead of