2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. All rights reserved.
3 * Copyright 2010, Jérôme Duval, korli@users.berlios.de. All rights reserved.
4 * Distributed under the terms of the MIT License.
16 openpty(int* _master
, int* _slave
, char* name
, struct termios
* termAttrs
,
17 struct winsize
* windowSize
)
19 int master
= posix_openpt(O_RDWR
);
25 if (grantpt(master
) != 0 || unlockpt(master
) != 0
26 || (ttyName
= ptsname(master
)) == NULL
27 || (slave
= open(ttyName
, O_RDWR
| O_NOCTTY
)) < 0) {
32 if ((termAttrs
!= NULL
&& tcsetattr(master
, TCSANOW
, termAttrs
) != 0)
33 || (windowSize
!= NULL
34 && ioctl(master
, TIOCSWINSZ
, windowSize
, sizeof(winsize
)) != 0)) {
44 strcpy(name
, ttyName
);
55 if (ioctl(fd
, TIOCSCTTY
, NULL
) != 0)
68 forkpty(int* _master
, char* name
, struct termios
* termAttrs
,
69 struct winsize
* windowSize
)
72 if (openpty(&master
, &slave
, name
, termAttrs
, windowSize
) != 0)
84 return login_tty(slave
);