STREAMS-UX Programmer's Guide (February 2007)
STREAMS Mechanism and System Calls
Creating a Stream
Chapter 2
19
Creating a Stream
open(2) Opening a STREAMS Device
A user application creates a stream by opening a STREAMS device with the open (2) call. This call is part of
the standard UNIX I/O. It opens a UNIX file for reading, writing, or both.
Synopsis
#include <fcntl.h>
int open(const char *path, int oflag, ... /* [mode_t mode] */ );
Arguments
path A pointer to a path name of the STREAMS device file being opened.
oflag The bitwise inclusive OR of O_NDELAY or O_NONBLOCK inclusive OR-ed with one of the
read-write flags. Other flag values are not applicable to STREAMS devices and have no
effect on them.
mode An optional mode argument.
Read-write flags specify the mode in which the STREAMS device is to be opened. The mode can be read-only,
write-only, or read-write. Determine the value for this flag by considering the type of driver and the nature of
the STREAMS application accessing the driver.
Only one of the following values must be used to specify the value of oflag:
O_RDONLY Open for read only
O_WRONLY Open for write only
O_RDWR Open for read-write
If none or more than one value is used, the behavior is undefined.
O_NDELAY and O_NONBLOCK are the only general flags relevant to STREAMS devices. The values of O_NDELAY
and O_NONBLOCK affect the operation of STREAMS drivers and certain system calls. Refer to read (2), getmsg
(2), putmsg (2), and write (2) for more information on these flags.
For drivers, the implementation of O_NDELAY and O_NONBLOCK is device specific. Each STREAMS device
driver may treat these options differently. For example, while opening a STREAMS device file associated with
a communication line, if either O_NDELAY or O_NONBLOCK is set, the open() returns without waiting for
carrier. Otherwise, it does not return until the carrier is present.
Return Values
open (2) returns an integer file descriptor upon successful completion, and a -1 in case of failure. The
corresponding errno is set appropriately, as with the standard UNIX File System I/O.
Creating a STREAMS-Based pipe with pipe(2)
A STREAMS-based pipe is a special case of a stream. Two streams are created and connected together when
a thread executes a pipe (2) system call. The data flow is bi-directional in a STREAMS-based pipe. Both
stream heads can be used for read and write operations. Figure 2-1, “A STREAMS-Based Pipe,” illustrates the
bi-directional data flow in a STREAMS-based pipe.