Added PG 10 compatibility wrapper to simple_prompt()

Also checking for malloc failure into previous version's simple_prompt()
calls.
This commit is contained in:
Daniele Varrazzo 2017-04-25 12:24:12 +01:00
parent b9b8e60bda
commit 19e34a3202

View File

@ -434,7 +434,26 @@ simple_string_list_size(SimpleStringList list)
static char * static char *
prompt_for_password(void) prompt_for_password(void)
{ {
return simple_prompt("Password: ", 100, false); char *buf;
#define BUFSIZE 100
#if PG_VERSION_NUM < 100000
buf = simple_prompt("Password: ", BUFSIZE, false);
#else
buf = (char *)malloc(BUFSIZE);
if (buf != NULL)
simple_prompt("Password: ", buf, BUFSIZE, false);
#endif
if (buf == NULL)
ereport(FATAL,
(errcode_errno(),
errmsg("could not allocate memory (" UINT64_FORMAT " bytes): ",
(unsigned long) BUFSIZE)));
return buf;
#undef BUFSIZE
} }