aboutsummaryrefslogtreecommitdiff
blob: caa451232ef4b77aab90bba7d77c497172e6bd39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
https://bugs.gentoo.org/show_bug.cgi?id=212709

Author: OKUMURA N. Shin-ya <oku.ns@dream.com>

--- a/pty.C
+++ b/pty.C
@@ -257,6 +257,23 @@
         }
     }
 
+#if defined(_POSIX_C_SOURCE)
+    // BSD pty �������ʤ��Τǡ�POSIX ����ˡ��
+    if ((master = posix_openpt(O_RDWR)) >= 0) {
+        if (grantpt(master) == 0 && unlockpt(master) == 0) {
+            // �ޥ����ǥХ���̾�ϸ���
+            strcpy(line, "/dev/ptmx");
+            tcgetattr(0, &tt);
+            tt.c_iflag &= ~ISTRIP;
+            ioctl(0, TIOCGWINSZ, (char*) &win);
+            return;
+        }
+        close(master);
+    } else {
+        perror("/dev/ptmx");
+    }
+#endif  // _POSIX_C_SOURCE
+
     printf("Out of pty's\n");
     fail();
 }
@@ -265,12 +282,36 @@
 void
 Pty::getslave()
 {
+#if defined(_POSIX_C_SOURCE)
+    // �ޥ����ǥХ����� POSIX �����ξ��
+    if (strcmp(line, "/dev/ptmx") == 0) {
+        char *slave_devname = ptsname(master);
+        if (slave_devname == NULL) {
+            perror("ptsname");
+            fail();
+        }
+        slave = open(slave_devname, O_RDWR);
+        if (slave < 0) {
+            perror(slave_devname);
+            fail();
+        }
+        strcpy(line, slave_devname);
+    } else {
+        line[strlen("/dev/")] = 't';
+        slave = open(line, O_RDWR);
+        if (slave < 0) {
+            perror(line);
+            fail();
+        }
+    }
+#else   // ! _POSIX_C_SOURCE
     line[strlen("/dev/")] = 't';
     slave = open(line, O_RDWR);
     if (slave < 0) {
         perror(line);
         fail();
     }
+#endif  // _POSIX_C_SOURCE
     tcsetattr(slave, TCSAFLUSH, &tt);
     if (!hs)
         win.ws_row--;