mirror of
git://git.suckless.org/sbase
synced 2026-01-26 05:37:54 +00:00
libutil: add confirm() prompt
This commit is contained in:
parent
8e18687849
commit
8d07e5e8f6
1
Makefile
1
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\
|
||||
|
||||
22
libutil/confirm.c
Normal file
22
libutil/confirm.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
@ -8,8 +8,6 @@
|
||||
|
||||
char *argv0;
|
||||
|
||||
static void xvprintf(const char *, va_list);
|
||||
|
||||
void
|
||||
eprintf(const char *fmt, ...)
|
||||
{
|
||||
|
||||
4
util.h
4
util.h
@ -4,6 +4,7 @@
|
||||
#include <regex.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#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 *);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user