diff --git a/Makefile b/Makefile index 165eeed..2d409ff 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,7 @@ LIBUTILOBJ =\ libutil/concat.o\ libutil/cp.o\ libutil/crypt.o\ + libutil/confirm.o\ libutil/ealloc.o\ libutil/enmasse.o\ libutil/eprintf.o\ diff --git a/libutil/confirm.c b/libutil/confirm.c new file mode 100644 index 0000000..44396af --- /dev/null +++ b/libutil/confirm.c @@ -0,0 +1,22 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include + +#include "../util.h" + +int +confirm(const char *fmt, ...) +{ + int c, ans; + va_list ap; + + va_start(ap, fmt); + xvprintf(fmt, ap); + va_end(ap); + + c = getchar(); + ans = (c == 'y' || c == 'Y'); + while (c != '\n' && c != EOF) + c = getchar(); + return ans; +} diff --git a/libutil/eprintf.c b/libutil/eprintf.c index 673523e..7197fbb 100644 --- a/libutil/eprintf.c +++ b/libutil/eprintf.c @@ -8,8 +8,6 @@ char *argv0; -static void xvprintf(const char *, va_list); - void eprintf(const char *fmt, ...) { diff --git a/util.h b/util.h index 346f6ca..6b6a084 100644 --- a/util.h +++ b/util.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "arg.h" #include "compat.h" @@ -43,6 +44,9 @@ int fshut(FILE *, const char *); void enprintf(int, const char *, ...); void eprintf(const char *, ...); void weprintf(const char *, ...); +void xvprintf(const char *, va_list); + +int confirm(const char*, ...); double estrtod(const char *);