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