]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/sanitizer_common/TestCases/Linux/getpass.cc
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / compiler-rt / test / sanitizer_common / TestCases / Linux / getpass.cc
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 #include <pty.h>
8
9 int
10 main (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