aboutsummaryrefslogtreecommitdiff
path: root/lib/confirm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/confirm.c')
-rw-r--r--lib/confirm.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/confirm.c b/lib/confirm.c
index bd283a1..18eb409 100644
--- a/lib/confirm.c
+++ b/lib/confirm.c
@@ -17,22 +17,32 @@
#include "libeclat.h"
#include <sysexits.h>
-int eclat_confirm_mode = -1;
-
int
-eclat_confirm(const char *prompt, ...)
+eclat_confirm(enum eclat_confirm_mode mode, const char *prompt, ...)
{
int rc;
va_list ap;
-
- if (!isatty(0) || eclat_confirm_mode >= 0) {
- if (eclat_confirm_mode == -1)
- die(EX_USAGE, "stdin not a terminal and no default response provided; use -Y or -N option to override");
- return eclat_confirm_mode;
+
+ switch (mode) {
+ case eclat_confirm_unspecified:
+ case eclat_confirm_positive:
+ return 1;
+ case eclat_confirm_negative:
+ return 0;
+ case eclat_confirm_tty:
+ if (!isatty(0))
+ return 1;
+ break;
+ case eclat_confirm_always:
+ if (!isatty(0))
+ die(EX_USAGE,
+ "confirmation required, "
+ "but stdin is not a terminal");
+ break;
}
va_start(ap, prompt);
- rc = eclat_vgetyn(!!eclat_confirm_mode, prompt, ap);
+ rc = eclat_vgetyn(-1, prompt, ap);
va_end(ap);
return rc;

Return to:

Send suggestions and report system problems to the System administrator.