1 // RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t | FileCheck %s
2
3 // REQUIRES: stable-runtime
4 // XFAIL: android && asan
5 // No libutil.
6 // UNSUPPORTED: solaris
7
8 #include <assert.h>
9 #include <stdio.h>
10 #include <string.h>
11 #if __linux__
12 #include <pty.h>
13 #elif defined(__FreeBSD__)
14 #include <libutil.h>
15 #include <pwd.h>
16 #include <sys/ioctl.h>
17 #include <sys/termios.h>
18 #include <sys/types.h>
19 #elif defined(__sun__) && defined(__svr4__)
20 #include <termios.h>
21 #else
22 #include <util.h>
23 #endif
24 #include <unistd.h>
25
26 int
main(int argc,char ** argv)27 main (int argc, char** argv)
28 {
29 int master;
30 int pid = forkpty(&master, NULL, NULL, NULL);
31
32 if(pid == -1) {
33 fprintf(stderr, "forkpty failed\n");
34 return 1;
35 } else if (pid > 0) {
36 char buf[1024];
37 int res = read(master, buf, sizeof(buf));
38 write(1, buf, res);
39 write(master, "password\n", 9);
40 while ((res = read(master, buf, sizeof(buf))) > 0) write(1, buf, res);
41 } else {
42 char *s = getpass("prompt");
43 assert(strcmp(s, "password") == 0);
44 write(1, "done\n", 5);
45 }
46 return 0;
47 }
48
49 // CHECK: prompt
50 // CHECK: done
51