This source file includes following definitions.
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <config.h>
21
22 #include <pty.h>
23
24 #include "signature.h"
25 SIGNATURE_CHECK (openpty, int, (int *, int *, char *, struct termios const *,
26 struct winsize const *));
27
28 #include <stdio.h>
29 #include <string.h>
30 #include <termios.h>
31 #include <unistd.h>
32
33 int
34 main ()
35 {
36 {
37 #ifndef _WIN32
38 int master;
39 int slave;
40
41
42 {
43 int res = openpty (&master, &slave, NULL, NULL, NULL);
44 if (res != 0)
45 {
46 fprintf (stderr, "openpty returned %d\n", res);
47 return 1;
48 }
49 }
50
51
52
53
54
55 {
56 int tcfd = slave;
57 struct termios attributes;
58
59 if (tcgetattr (tcfd, &attributes) < 0)
60 {
61 fprintf (stderr, "tcgetattr failed\n");
62 return 1;
63 }
64
65 attributes.c_lflag |= ECHO | ICANON | ECHOE;
66 attributes.c_cc[VERASE] = '\177';
67 if (tcsetattr (tcfd, TCSANOW, &attributes) < 0)
68 {
69 fprintf (stderr, "tcsetattr failed\n");
70 return 1;
71 }
72 }
73
74
75 {
76 static const char input[] = "Hello worst\177\177ld!\n";
77
78 if (write (master, input, strlen (input)) < (int) strlen (input))
79 {
80 fprintf (stderr, "write failed\n");
81 return 1;
82 }
83 }
84
85
86 {
87 char buf[100];
88 int res = read (slave, buf, sizeof (buf));
89 static const char expected[] = "Hello world!\n";
90
91 if (res < 0)
92 {
93 fprintf (stderr, "read failed\n");
94 return 1;
95 }
96 if (!(res == strlen (expected)
97 && memcmp (buf, expected, strlen (expected)) == 0))
98 {
99 fprintf (stderr, "read result unexpected\n");
100 return 1;
101 }
102 }
103
104
105
106 close (master);
107 #endif
108 }
109
110 return 0;
111 }