logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

posix_openpt.3p (4744B)


  1. '\" et
  2. .TH POSIX_OPENPT "3P" 2017 "IEEE/The Open Group" "POSIX Programmer's Manual"
  3. .\"
  4. .SH PROLOG
  5. This manual page is part of the POSIX Programmer's Manual.
  6. The Linux implementation of this interface may differ (consult
  7. the corresponding Linux manual page for details of Linux behavior),
  8. or the interface may not be implemented on Linux.
  9. .\"
  10. .SH NAME
  11. posix_openpt
  12. \(em open a pseudo-terminal device
  13. .SH SYNOPSIS
  14. .LP
  15. .nf
  16. #include <stdlib.h>
  17. #include <fcntl.h>
  18. .P
  19. int posix_openpt(int \fIoflag\fP);
  20. .fi
  21. .SH DESCRIPTION
  22. The
  23. \fIposix_openpt\fR()
  24. function shall establish a connection between a master device for a
  25. pseudo-terminal and a file descriptor. The file descriptor shall be
  26. allocated as described in
  27. .IR "Section 2.14" ", " "File Descriptor Allocation"
  28. and can be used by other I/O functions that refer to that pseudo-terminal.
  29. .P
  30. The file status flags and file access modes of the open file
  31. description shall be set according to the value of
  32. .IR oflag .
  33. .P
  34. Values for
  35. .IR oflag
  36. are constructed by a bitwise-inclusive OR of flags from the following
  37. list, defined in
  38. .IR <fcntl.h> :
  39. .IP O_RDWR 12
  40. Open for reading and writing.
  41. .IP O_NOCTTY 12
  42. If set
  43. \fIposix_openpt\fR()
  44. shall not cause the terminal device to become the controlling terminal
  45. for the process.
  46. .P
  47. The behavior of other values for the
  48. .IR oflag
  49. argument is unspecified.
  50. .SH "RETURN VALUE"
  51. Upon successful completion, the
  52. \fIposix_openpt\fR()
  53. function shall open a file descriptor for a master pseudo-terminal
  54. device and return a non-negative integer representing the file
  55. descriptor. Otherwise, \-1 shall be returned and
  56. .IR errno
  57. set to indicate the error.
  58. .SH ERRORS
  59. The
  60. \fIposix_openpt\fR()
  61. function shall fail if:
  62. .TP
  63. .BR EMFILE
  64. All file descriptors available to the process are currently open.
  65. .TP
  66. .BR ENFILE
  67. The maximum allowable number of files is currently open in the system.
  68. .P
  69. The
  70. \fIposix_openpt\fR()
  71. function may fail if:
  72. .TP
  73. .BR EINVAL
  74. The value of
  75. .IR oflag
  76. is not valid.
  77. .TP
  78. .BR EAGAIN
  79. Out of pseudo-terminal resources.
  80. .TP
  81. .BR ENOSR
  82. Out of STREAMS resources.
  83. .LP
  84. .IR "The following sections are informative."
  85. .SH EXAMPLES
  86. .SS "Opening a Pseudo-Terminal and Returning the Name of the Slave Device and a File Descriptor"
  87. .sp
  88. .RS 4
  89. .nf
  90. #include <fcntl.h>
  91. #include <stdio.h>
  92. .P
  93. int masterfd, slavefd;
  94. char *slavedevice;
  95. .P
  96. masterfd = posix_openpt(O_RDWR|O_NOCTTY);
  97. .P
  98. if (masterfd == -1
  99. || grantpt (masterfd) == -1
  100. || unlockpt (masterfd) == -1
  101. || (slavedevice = ptsname (masterfd)) == NULL)
  102. return -1;
  103. .P
  104. printf("slave device is: %s\en", slavedevice);
  105. .P
  106. slavefd = open(slavedevice, O_RDWR|O_NOCTTY);
  107. if (slavefd < 0)
  108. return -1;
  109. .fi
  110. .P
  111. .RE
  112. .SH "APPLICATION USAGE"
  113. This function is a method for portably obtaining a file descriptor of a
  114. master terminal device for a pseudo-terminal. The
  115. \fIgrantpt\fR()
  116. and
  117. \fIptsname\fR()
  118. functions can be used to manipulate mode and ownership permissions, and
  119. to obtain the name of the slave device, respectively.
  120. .SH RATIONALE
  121. The standard developers considered the matter of adding a special
  122. device for cloning master pseudo-terminals: the
  123. .BR /dev/ptmx
  124. device. However, consensus could not be reached, and it was felt that
  125. adding a new function would permit other implementations. The
  126. \fIposix_openpt\fR()
  127. function is designed to complement the
  128. \fIgrantpt\fR(),
  129. \fIptsname\fR(),
  130. and
  131. \fIunlockpt\fR()
  132. functions.
  133. .P
  134. On implementations supporting the
  135. .BR /dev/ptmx
  136. clone device, opening the master device of a pseudo-terminal is simply:
  137. .sp
  138. .RS 4
  139. .nf
  140. mfdp = open("/dev/ptmx", oflag );
  141. if (mfdp < 0)
  142. return -1;
  143. .fi
  144. .P
  145. .RE
  146. .SH "FUTURE DIRECTIONS"
  147. None.
  148. .SH "SEE ALSO"
  149. .IR "Section 2.14" ", " "File Descriptor Allocation",
  150. .IR "\fIgrantpt\fR\^(\|)",
  151. .IR "\fIopen\fR\^(\|)",
  152. .IR "\fIptsname\fR\^(\|)",
  153. .IR "\fIunlockpt\fR\^(\|)"
  154. .P
  155. The Base Definitions volume of POSIX.1\(hy2017,
  156. .IR "\fB<fcntl.h>\fP",
  157. .IR "\fB<stdlib.h>\fP"
  158. .\"
  159. .SH COPYRIGHT
  160. Portions of this text are reprinted and reproduced in electronic form
  161. from IEEE Std 1003.1-2017, Standard for Information Technology
  162. -- Portable Operating System Interface (POSIX), The Open Group Base
  163. Specifications Issue 7, 2018 Edition,
  164. Copyright (C) 2018 by the Institute of
  165. Electrical and Electronics Engineers, Inc and The Open Group.
  166. In the event of any discrepancy between this version and the original IEEE and
  167. The Open Group Standard, the original IEEE and The Open Group Standard
  168. is the referee document. The original Standard can be obtained online at
  169. http://www.opengroup.org/unix/online.html .
  170. .PP
  171. Any typographical or formatting errors that appear
  172. in this page are most likely
  173. to have been introduced during the conversion of the source files to
  174. man page format. To report such errors, see
  175. https://www.kernel.org/doc/man-pages/reporting_bugs.html .