[Partial patch] Use posix_openpt() where available
Ed Schouten <[email protected]> Sun, 27 Jan 2008 14:25:57 +0100
| Newsgroups | gmane.comp.gnu.screen |
|---|---|
| Message-ID | <20080127132557.GP67081__24117.0038738803$1238088988$gmane$org@hoeg.nl> |
Hello, I just looked through screen's source code and I saw that it tries almost any way to open up a PTY, except for the only way described in POSIX, namely posix_openpt(): http://www.opengroup.org/onlinepubs/000095399/functions/posix_openpt.html We can just call posix_openpt() and ptsname() to obtain a PTY and figure out its name. I've attached a really simple patch to fix screen to use posix_openpt(), but I didn't add the autoconf parts, because for some reason, it gave a lot of strange errors on my box. We can only use this code if posix_openpt() and ptsname() are available. If someone else is willing to add those bits for me, that would be great. Yours, -- Ed Schouten <[email protected]> WWW: http://g-rave.nl/
screen-posix_openpt.diff
(text/x-diff, 700 B)
--- pty.c 2003-09-08 16:26:18.000000000 +0200
+++ pty.c 2008-01-27 14:14:58.000000000 +0100
@@ -145,6 +145,35 @@
/***************************************************************/
+#if 1 && !defined(PTY_DONE)
+#define PTY_DONE
+int
+OpenPTY(ttyn)
+char **ttyn;
+{
+ int f;
+ char *n;
+
+ f = posix_openpt(O_RDWR|O_NOCTTY);
+ if (f < 0)
+ return -1;
+
+ n = ptsname(f);
+ if (n == NULL) {
+ close(f);
+ return -1;
+ }
+
+ initmaster(f);
+ pty_preopen = 1;
+ strncpy(TtyName, n, sizeof(TtyName));
+ *ttyn = TtyName;
+ return f;
+}
+#endif
+
+/***************************************************************/
+
#if defined(OSX) && !defined(PTY_DONE)
#define PTY_DONE
int
signature.asc
(application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.8 (FreeBSD) iEYEARECAAYFAkechmUACgkQ52SDGA2eCwXiEACfZ3WMvpuVk7Y31VD2z+8OHDFP XzkAn0Hmx4zAWgoB9SYsILjKOZuO8yY+ =Imh0 -----END PGP SIGNATURE-----