STREAMS-UX Programmer's Guide (February 2007)
STREAMS Mechanism and System Calls
Attaching and Detaching a Stream to a File - Named Streams
Chapter 2
41
Arguments
path Path name of an existing object in the file system.
The fdetach () function detaches a file descriptor from its filename in the file system. The path argument
refers to the path that was previously attached using fattach (). The caller must own path or have write
permission or appropriate privileges (PRIV_MOUNT) to detach a file descriptor. As a result of the fdetach ()
operation, the node's status and permissions are restored to the state prior to the file attaching to the node.
Subsequent operations on the path will affect only the file system node and not the attached file.
If one end of a pipe is named, the last close of the other end causes the named end to be automatically
detached. If the named stream is a device and not a pipe, the last close does not cause the stream to be
detached. In this scenario, fdetach (3)/fdetach (1M) has to be explicitly issued to detach the named STREAMS
device.
Return Values
Upon successful completion, the fdetach(3C) function returns a value of 0. Otherwise, it returns a value of -1,
and errno is set to indicate the error.
The isastream(3C) System Call
isastream() tests if a file descriptor refers to a STREAMS device or a STREAMS-based pipe.
Synopsis
#include <stropts.h>
int isastream(int fd);
Arguments
fd An open file descriptor.
The isastream(3C) determines whether an open file descriptor fd corresponds
to a STREAMS device or STREAMS-based pipe.
Return Values
Upon successful completion, the isastream() function returns a value of 0 when the file descriptor of the
open file specified by fd is a STREAMS device or STREAMS-based pipe, and if it is not a stream, but is a
valid open file descriptor. Otherwise, a value of -1 is returned, and errno is set to indicate the error.
File Descriptor Passing
Named streams are useful for passing file descriptors between unrelated processes. A user process can send a
file descriptor to another process by invoking the ioctl(2) I_SENDFD on one end of a named stream. This
sends a message containing a file descriptor to the stream head at the other end of the pipe. Another process
can retrieve that message containing the file descriptor by invoking the ioctl(2) I_RECVFD on the other end
of the pipe.
See Appendix - A for more information on I_SENDFD and I_RECVFD ioctl commands.