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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of compiler-rt/test/sanitizer_common/TestCases/Posix/getpass.cpp