Determine the size of a pipe without calling read()

Tags: unix linux c c++

I need a function called SizeOfPipe() which should return the size of a pipe- I only want to know how much data is in the pipe and not actually read data off the pipe itself.

I thought the following code would work

fseek (pPipe, 0 , SEEK_END);
*pBytes = ftell (pPipe);
rewind (pPipe);

but fseek dosent work on file descriptors. Another option would be to read the pipe then write the data back but would like to avoid this if possibe, any suggestions ?


On Windows you can always use PeekNamedPipe, but I doubt that's what you want to do anyway.

By : MSN

You can wrap it in object with buffering that can be rewinded. This would be feasible only for small amounts of data.

One way to do this in C is to define stuct and wrap all functions operating on pipes for your struct.

By : devdimi

There is no portable way to tell the amount of data coming from a pipe. The only thing you could do is to read and process data as it comes.

For that you could use something like a circular buffer

By : INS

This video can help you solving your question :)
By: admin