// RUN: %clangxx -O0 -g %s -lutil -o %t // Ignore leaks as this is not the point of test, but HWASAN repors one here. // RUN: %env_tool_opts=detect_leaks=0 %run %t | FileCheck %s // REQUIRES: stable-runtime // XFAIL: android && asan // No libutil. // UNSUPPORTED: target={{.*solaris.*}} #include #include #include #if __linux__ # include #elif defined(__FreeBSD__) # include # include # include # include # include #elif defined(__sun__) && defined(__svr4__) # include #else # include #endif #include int main(int argc, char **argv) { int m; int pid = forkpty(&m, NULL, NULL, NULL); if (pid == -1) { fprintf(stderr, "forkpty failed\n"); return 1; } else if (pid > 0) { char buf[1024]; int res = read(m, buf, sizeof(buf)); write(1, buf, res); write(m, "password\n", 9); while ((res = read(m, buf, sizeof(buf))) > 0) write(1, buf, res); } else { char *s = getpass("prompt"); assert(strcmp(s, "password") == 0); write(1, "done\n", 5); } return 0; } // CHECK: prompt // CHECK: done