Make build on windows
Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
This commit is contained in:

committed by
Love Hornquist Astrand

parent
452c20aed5
commit
c4b95f7330
@@ -37,10 +37,15 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#ifdef HAVE_TERMIOS_H
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#include <roken.h>
|
||||
|
||||
#include <ui.h>
|
||||
#ifdef HAVE_CONIO_H
|
||||
#include <conio.h>
|
||||
#endif
|
||||
|
||||
static sig_atomic_t intr_flag;
|
||||
|
||||
@@ -50,6 +55,8 @@ intr(int sig)
|
||||
intr_flag++;
|
||||
}
|
||||
|
||||
#ifndef HAVE_CONIO_H
|
||||
|
||||
#ifndef NSIG
|
||||
#define NSIG 47
|
||||
#endif
|
||||
@@ -135,6 +142,49 @@ read_string(const char *preprompt, const char *prompt,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* CONIO_H */
|
||||
|
||||
static int
|
||||
read_string(const char *preprompt, const char *prompt,
|
||||
char *buf, size_t len, int echo)
|
||||
{
|
||||
int of = 0;
|
||||
int c;
|
||||
char *p;
|
||||
void (*oldsigintr)(int);
|
||||
|
||||
_cprintf("%s%s", preprompt, prompt);
|
||||
|
||||
oldsigintr = signal(SIGINT, intr);
|
||||
|
||||
p = buf;
|
||||
while(intr_flag == 0){
|
||||
c = ((echo)? _getche(): _getch());
|
||||
if(c == '\n')
|
||||
break;
|
||||
if(of == 0)
|
||||
*p++ = c;
|
||||
of = (p == buf + len);
|
||||
}
|
||||
if(of)
|
||||
p--;
|
||||
*p = 0;
|
||||
|
||||
if(echo == 0){
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
signal(SIGINT, oldsigintr);
|
||||
|
||||
if(intr_flag)
|
||||
return -2;
|
||||
if(of)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
UI_UTIL_read_pw_string(char *buf, int length, const char *prompt, int verify)
|
||||
{
|
||||
|
Reference in New Issue
Block a user