Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Single UNIX Specification, Version 3 |
both | z/OS® V1.9 |
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include <fcntl.h>
int posix_openpt(int oflag);
The posix_openpt() function establishes a connection between a master device for a pseudo-terminal and a file descriptor. The file descriptor is used by other I/O functions that refer to that pseudo-terminal.
The file status flags and file access modes of the open file description are set according to the value of oflag.
Values for oflag are constructed by a bitwise-inclusive OR of flags from the following list, defined in <fcntl.h>:
The behavior of other values for the oflag argument is unspecified.
⁄* CELEBP71
This example demonstrates how to use posix_openpt() to open a
master psuedo-terminal device.
Expected output:
The master psuedo-terminal id is [first available descriptor]
*⁄
#define _XOPEN_SOURCE 600
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
void main() {
int fd;
fd = posix_openpt(O_RDWR | O_NOCTTY);
if (fd == -1)
perror("Error opening a terminal.\n");
else
printf("The master psuedo-terminal id is %d\n",fd);
}