mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
Prevent simple_prompt() from locking up in a tight loop at stdin EOF.
This commit is contained in:
parent
0a829cb865
commit
e8a72c0db2
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright 2000 by PostgreSQL Global Development Group
|
* Copyright 2000 by PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.25 2000/11/13 23:37:53 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.26 2000/11/27 01:28:40 tgl Exp $
|
||||||
*/
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@ -217,12 +217,14 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
|
|||||||
if (length > 0 && destination[length - 1] != '\n')
|
if (length > 0 && destination[length - 1] != '\n')
|
||||||
{
|
{
|
||||||
/* eat rest of the line */
|
/* eat rest of the line */
|
||||||
char buf[512];
|
char buf[128];
|
||||||
|
int buflen;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
fgets(buf, 512, stdin);
|
fgets(buf, sizeof(buf), stdin);
|
||||||
} while (buf[strlen(buf) - 1] != '\n');
|
buflen = strlen(buf);
|
||||||
|
} while (buflen > 0 && buf[buflen - 1] != '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (length > 0 && destination[length - 1] == '\n')
|
if (length > 0 && destination[length - 1] == '\n')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user