Determining if a readable file descriptor is a read end of pipe

I would like to use splicefor zero copying data from STDIN_FILENOto a file descriptor (which can be a regular file, char or block device, FIFO, or anything that can be opened with open). To use spliceeither a file descriptor or a file descriptor must be the corresponding end of the channel, so a channel is usually created for use as an intermediate buffer when the programmer wants to zero-copy data from non-pipe to non-pipe. However, if the STDIN_FILENOend of the pipe is already read, I could skip this step and try to merge directly from STDIN_FILENOto another file descriptor. Therefore, I would like to be able to determine if the STDIN_FILENOread end of the pipe.

Is there a Linux system call that can determine if the STDIN_FILENOread end of a pipe is?

+5
source share
2 answers

To get information about open fd, you can use fstat (). I assume that the st_mode of the result should be S_IFIFO for the channel. Alternatively, / proc / self / fd / and / proc / self / fdinfo / also provide some information about the file descriptor. Keep in mind that / proc is Linux specific.

However, I think it would be easier to just try using splice () first, and if it doesn't work (with EINVAL?), Go back to your magic.

+5
source

lseek() ESPIPE, "fd , FIFO". no-op lseek(fd, 0, SEEK_CUR) , .

, .

+1

All Articles