1// RUN: %clangxx -O0 -g %s -lutil -o %t && %run %t | FileCheck %s
2// REQUIRES: stable-runtime
3#include <assert.h>
4#include <stdio.h>
5#include <unistd.h>
6#include <string.h>
7#if __linux__
8#include <pty.h>
9#else
10#include <util.h>
11#endif
12
13int
14main (int argc, char** argv)
15{
16    int master;
17    int pid = forkpty(&master, NULL, NULL, NULL);
18
19    if(pid == -1) {
20      fprintf(stderr, "forkpty failed\n");
21      return 1;
22    } else if (pid > 0) {
23      char buf[1024];
24      int res = read(master, buf, sizeof(buf));
25      write(1, buf, res);
26      write(master, "password\n", 9);
27      while ((res = read(master, buf, sizeof(buf))) > 0) write(1, buf, res);
28    } else {
29      char *s = getpass("prompt");
30      assert(strcmp(s, "password") == 0);
31      write(1, "done\n", 5);
32    }
33    return 0;
34}
35
36// CHECK: prompt
37// CHECK: done
38