Function glib::unix_open_pipe

source ·
pub fn unix_open_pipe(flags: i32) -> Result<(RawFd, RawFd), Error>
Expand description

Similar to the UNIX pipe() call, but on modern systems like Linux uses the pipe2() system call, which atomically creates a pipe with the configured flags.

As of GLib 2.78, the supported flags are O_CLOEXEC/FD_CLOEXEC (see below) and O_NONBLOCK. Prior to GLib 2.78, only FD_CLOEXEC was supported — if you wanted to configure O_NONBLOCK then that had to be done separately with fcntl().

Since GLib 2.80, the constants G_UNIX_PIPE_END_READ and G_UNIX_PIPE_END_WRITE can be used as mnemonic indexes in @fds.

It is a programmer error to call this function with unsupported flags, and a critical warning will be raised.

As of GLib 2.78, it is preferred to pass O_CLOEXEC in, rather than FD_CLOEXEC, as that matches the underlying pipe() API more closely. Prior to 2.78, only FD_CLOEXEC was supported. Support for FD_CLOEXEC may be deprecated and removed in future.

§fds

Array of two integers

§flags

Bitfield of file descriptor flags, as for fcntl()

§Returns

true on success, false if not (and errno will be set).