Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. dlltc.c
  5. Abstract:
  6. Client implementation of Terminal Control functions for POSIX
  7. Author:
  8. Ellen Aycock-Wright 05-Aug-1991
  9. Revision History:
  10. --*/
  11. #include <termios.h>
  12. #include "psxdll.h"
  13. int
  14. __cdecl
  15. tcgetattr (int fildes, struct termios *termios_p)
  16. {
  17. PSX_API_MSG m;
  18. NTSTATUS st;
  19. SCREQUESTMSG Request;
  20. PPSX_TCGETATTR_MSG args;
  21. args = &m.u.TcGetAttr;
  22. PSX_FORMAT_API_MSG(m,PsxTcGetAttrApi,sizeof(*args));
  23. args->FileDes = fildes;
  24. args->Termios = termios_p;
  25. st = NtRequestWaitReplyPort(
  26. PsxPortHandle,
  27. (PPORT_MESSAGE) &m,
  28. (PPORT_MESSAGE) &m
  29. );
  30. if ( m.Error ) {
  31. errno = (int) m.Error;
  32. return (int) -1;
  33. }
  34. //
  35. // fildes is a valid file descriptor; now call to posix.exe to get
  36. // the real terminal settings.
  37. //
  38. Request.Request = TcRequest;
  39. Request.d.Con.Request = TcGetAttr;
  40. st = SendConsoleRequest(&Request);
  41. memcpy(termios_p, &Request.d.Tc.Termios, sizeof(*termios_p));
  42. if (!NT_SUCCESS(st)) {
  43. errno = PdxStatusToErrno(st);
  44. return -1;
  45. }
  46. return 0;
  47. }
  48. int
  49. __cdecl
  50. tcsetattr(int fildes, int optional_actions, const struct termios *termios_p)
  51. {
  52. PSX_API_MSG m;
  53. NTSTATUS st;
  54. SCREQUESTMSG Request;
  55. PPSX_TCSETATTR_MSG args;
  56. args = &m.u.TcSetAttr;
  57. PSX_FORMAT_API_MSG(m,PsxTcSetAttrApi,sizeof(*args));
  58. args->FileDes = fildes;
  59. args->OptionalActions = optional_actions;
  60. args->Termios = (struct termios *)termios_p;
  61. st = NtRequestWaitReplyPort(
  62. PsxPortHandle,
  63. (PPORT_MESSAGE) &m,
  64. (PPORT_MESSAGE) &m
  65. );
  66. if ( m.Error ) {
  67. errno = (int) m.Error;
  68. return (int) -1;
  69. }
  70. //
  71. // The file descriptor is valid; make the request to posix.exe to
  72. // set the attributes.
  73. //
  74. Request.Request = TcRequest;
  75. Request.d.Con.Request = TcSetAttr;
  76. memcpy(&Request.d.Tc.Termios, termios_p, sizeof(*termios_p));
  77. st = SendConsoleRequest(&Request);
  78. if (!NT_SUCCESS(st)) {
  79. errno = PdxStatusToErrno(st);
  80. return -1;
  81. }
  82. return 0;
  83. }
  84. int
  85. __cdecl
  86. tcsendbreak (int fildes, int duration)
  87. {
  88. PSX_API_MSG m;
  89. NTSTATUS st;
  90. PPSX_TCSENDBREAK_MSG args;
  91. args = &m.u.TcSendBreak;
  92. PSX_FORMAT_API_MSG(m,PsxTcSendBreakApi,sizeof(*args));
  93. args->FileDes = fildes;
  94. args->Duration = duration;
  95. st = NtRequestWaitReplyPort(
  96. PsxPortHandle,
  97. (PPORT_MESSAGE) &m,
  98. (PPORT_MESSAGE) &m
  99. );
  100. if ( m.Error ) {
  101. errno = (int) m.Error;
  102. return (int) -1;
  103. } else {
  104. return (int) m.ReturnValue;
  105. }
  106. }
  107. int
  108. __cdecl
  109. tcdrain (int fildes)
  110. {
  111. PSX_API_MSG m;
  112. NTSTATUS st;
  113. PPSX_TCDRAIN_MSG args;
  114. args = &m.u.TcDrain;
  115. PSX_FORMAT_API_MSG(m,PsxTcDrainApi,sizeof(*args));
  116. args->FileDes = fildes;
  117. st = NtRequestWaitReplyPort(
  118. PsxPortHandle,
  119. (PPORT_MESSAGE) &m,
  120. (PPORT_MESSAGE) &m
  121. );
  122. if ( m.Error ) {
  123. errno = (int) m.Error;
  124. return (int) -1;
  125. } else {
  126. return (int) m.ReturnValue;
  127. }
  128. }
  129. int
  130. __cdecl
  131. tcflush (int fildes, int queue_selector)
  132. {
  133. PSX_API_MSG m;
  134. NTSTATUS st;
  135. PPSX_TCFLUSH_MSG args;
  136. args = &m.u.TcFlush;
  137. PSX_FORMAT_API_MSG(m,PsxTcFlushApi,sizeof(*args));
  138. args->FileDes = fildes;
  139. args->QueueSelector = queue_selector;
  140. st = NtRequestWaitReplyPort(
  141. PsxPortHandle,
  142. (PPORT_MESSAGE) &m,
  143. (PPORT_MESSAGE) &m
  144. );
  145. if ( m.Error ) {
  146. errno = (int) m.Error;
  147. return (int) -1;
  148. } else {
  149. return (int) m.ReturnValue;
  150. }
  151. }
  152. int
  153. __cdecl
  154. tcflow (int fildes, int action)
  155. {
  156. PSX_API_MSG m;
  157. NTSTATUS st;
  158. PPSX_TCFLOW_MSG args;
  159. args = &m.u.TcFlow;
  160. PSX_FORMAT_API_MSG(m,PsxTcFlowApi,sizeof(*args));
  161. args->FileDes = fildes;
  162. args->Action = action;
  163. st = NtRequestWaitReplyPort(
  164. PsxPortHandle,
  165. (PPORT_MESSAGE) &m,
  166. (PPORT_MESSAGE) &m
  167. );
  168. if ( m.Error ) {
  169. errno = (int) m.Error;
  170. return (int) -1;
  171. } else {
  172. return (int) m.ReturnValue;
  173. }
  174. }
  175. pid_t
  176. __cdecl
  177. tcgetpgrp (int fildes)
  178. {
  179. PSX_API_MSG m;
  180. NTSTATUS st;
  181. PPSX_TCGETPGRP_MSG args;
  182. args = &m.u.TcGetPGrp;
  183. PSX_FORMAT_API_MSG(m,PsxTcGetPGrpApi,sizeof(*args));
  184. args->FileDes = fildes;
  185. st = NtRequestWaitReplyPort(
  186. PsxPortHandle,
  187. (PPORT_MESSAGE) &m,
  188. (PPORT_MESSAGE) &m
  189. );
  190. if ( m.Error ) {
  191. errno = (int) m.Error;
  192. return (pid_t) -1;
  193. } else {
  194. return (pid_t) m.ReturnValue;
  195. }
  196. }
  197. int
  198. __cdecl
  199. tcsetpgrp(int fildes, pid_t pgrp_id)
  200. {
  201. PSX_API_MSG m;
  202. NTSTATUS st;
  203. PPSX_TCSETPGRP_MSG args;
  204. args = &m.u.TcSetPGrp;
  205. PSX_FORMAT_API_MSG(m,PsxTcSetPGrpApi,sizeof(*args));
  206. args->FileDes = fildes;
  207. args->PGrpId = pgrp_id;
  208. st = NtRequestWaitReplyPort(
  209. PsxPortHandle,
  210. (PPORT_MESSAGE) &m,
  211. (PPORT_MESSAGE) &m
  212. );
  213. if ( m.Error ) {
  214. errno = (int) m.Error;
  215. return (pid_t) -1;
  216. } else {
  217. return (pid_t) m.ReturnValue;
  218. }
  219. }