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