Determine the size of a pipe without calling read()

后端 未结 13 915
无人共我
无人共我 2020-12-19 03:56

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 t

13条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 04:36

    Depending on your unix implementation ioctl/FIONREAD might do the trick

    err = ioctl(pipedesc, FIONREAD, &bytesAvailable);
    

    Unless this returns the error code for "invalid argument" (or any other error) bytesAvailable contains the amount of data available for unblocking read operations at that time.

提交回复
热议问题