diff --git a/lib/libspl/include/os/windows/unistd.h b/lib/libspl/include/os/windows/unistd.h index 868e2e071ac9..81588f64d7fc 100644 --- a/lib/libspl/include/os/windows/unistd.h +++ b/lib/libspl/include/os/windows/unistd.h @@ -63,7 +63,9 @@ extern size_t strlcpy(register char *s, register const char *t, extern size_t strlcat(register char *s, register const char *t, register size_t n); -extern ssize_t getline(char **linep, size_t *linecapp, FILE *stream); +extern ssize_t getline_impl(char **linep, size_t *linecapp, FILE *stream, + boolean_t internal); +#define getline(L, C, S) getline_impl((L), (C), (S), FALSE) // int pread_win(HANDLE h, void *buf, size_t nbyte, off_t offset); extern int pipe(int fildes[2]); diff --git a/lib/libspl/include/os/windows/wfunopen.h b/lib/libspl/include/os/windows/wfunopen.h index c58cf6b62ea7..d04b60794982 100644 --- a/lib/libspl/include/os/windows/wfunopen.h +++ b/lib/libspl/include/os/windows/wfunopen.h @@ -122,10 +122,12 @@ static inline ssize_t wosix_getline(char **linep, size_t *linecap, FILE *f) fakeFILE *fFILE = (fakeFILE *)f; int result; - if (fFILE->realFILE) + if (f == stdin) + result = getline_impl(linep, linecap, f, FALSE); + else if (fFILE->realFILE) result = getline(linep, linecap, fFILE->realFILE); else - result = fFILE->readfn(fFILE->cookie, *linep, *linecap); + result = getline_impl(linep, linecap, fFILE, TRUE); return (result); } diff --git a/lib/libspl/os/windows/posix.c b/lib/libspl/os/windows/posix.c index 63f42a197eac..9eba2b95a9ce 100644 --- a/lib/libspl/os/windows/posix.c +++ b/lib/libspl/os/windows/posix.c @@ -40,6 +40,7 @@ #include #include #include +#include /* Magic instruction to compiler to add library */ #pragma comment(lib, "ws2_32.lib") @@ -889,17 +890,21 @@ console_echo(boolean_t willecho) // Not really getline, just used for password input in libzfs_crypto.c #define MAX_GETLINE 128 ssize_t -getline(char **linep, size_t *linecapp, - FILE *stream) +getline_impl(char **linep, size_t *linecapp, + FILE *stream, boolean_t internal) { static char getpassbuf[MAX_GETLINE + 1]; size_t i = 0; + fakeFILE *fFILE = (fakeFILE *)stream; console_echo(FALSE); int c; for (;;) { - c = getc(stream); + if (internal) + fFILE->readfn(fFILE->cookie, &c, 1); + else + c = getc(stream); if ((c == '\r') || (c == '\n')) { getpassbuf[i] = '\0'; break;