Add support for yorn(), safe yes-or-no prompt

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2019-05-29 15:57:11 +02:00
1 parent 7f053f7624
commit b2c2d032e8
7 files changed
+136 -2

No files matched your search

+1
View File
@@ -17,3 +17,4 @@ tempfile
touch
tree
which
yorn
+1
View File
@@ -18,6 +18,7 @@ TESTS += strmatch
TESTS += touch
TESTS += tempfile
TESTS += which
TESTS += yorn
check_PROGRAMS = $(TESTS)
+32
View File
@@ -0,0 +1,32 @@
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include "check.h"
int main(int argc, char *argv[])
{
int chan[2];
int status;
pipe(chan);
if (fork() > 0) {
dup2(chan[0], STDIN_FILENO);
if (yorn("Do you really wanna do this (y/N)? ")) {
printf("Affirmative!\n");
_exit(0);
}
printf("OK, aborting!\n");
_exit(1);
}
sleep(1);
if (write(chan[1], "Y", 1) != 1)
return 1;
wait(&status);
return WEXITSTATUS(status);
}