Commit 22045666 authored by Tom Lane's avatar Tom Lane

Fix saveHistory() to not emit bogus complaint during psql exit when using

Darwin's libedit; per my proposal last August.  Also, suppress cast-away-
const warnings.
parent f1e671a0
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 2000-2006, PostgreSQL Global Development Group * Copyright (c) 2000-2006, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.55 2006/06/14 16:49:02 tgl Exp $ * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.56 2006/06/18 17:30:48 tgl Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
...@@ -245,11 +245,14 @@ encode_history(void) ...@@ -245,11 +245,14 @@ encode_history(void)
HIST_ENTRY *cur_hist; HIST_ENTRY *cur_hist;
char *cur_ptr; char *cur_ptr;
for (history_set_pos(0), cur_hist = current_history(); history_set_pos(0);
cur_hist; cur_hist = next_history()) for (cur_hist = current_history(); cur_hist; cur_hist = next_history())
for (cur_ptr = cur_hist->line; *cur_ptr; cur_ptr++) {
/* some platforms declare HIST_ENTRY.line as const char * */
for (cur_ptr = (char *) cur_hist->line; *cur_ptr; cur_ptr++)
if (*cur_ptr == '\n') if (*cur_ptr == '\n')
*cur_ptr = NL_IN_HISTORY; *cur_ptr = NL_IN_HISTORY;
}
} }
/* /*
...@@ -261,11 +264,14 @@ decode_history(void) ...@@ -261,11 +264,14 @@ decode_history(void)
HIST_ENTRY *cur_hist; HIST_ENTRY *cur_hist;
char *cur_ptr; char *cur_ptr;
for (history_set_pos(0), cur_hist = current_history(); history_set_pos(0);
cur_hist; cur_hist = next_history()) for (cur_hist = current_history(); cur_hist; cur_hist = next_history())
for (cur_ptr = cur_hist->line; *cur_ptr; cur_ptr++) {
/* some platforms declare HIST_ENTRY.line as const char * */
for (cur_ptr = (char *) cur_hist->line; *cur_ptr; cur_ptr++)
if (*cur_ptr == NL_IN_HISTORY) if (*cur_ptr == NL_IN_HISTORY)
*cur_ptr = '\n'; *cur_ptr = '\n';
}
} }
#endif /* USE_READLINE */ #endif /* USE_READLINE */
...@@ -339,13 +345,22 @@ saveHistory(char *fname, bool encodeFlag) ...@@ -339,13 +345,22 @@ saveHistory(char *fname, bool encodeFlag)
{ {
if (encodeFlag) if (encodeFlag)
encode_history(); encode_history();
if (write_history(fname) == 0)
/*
* return value of write_history is not standardized across GNU
* readline and libedit. Therefore, check for errno becoming set
* to see if the write failed.
*/
errno = 0;
(void) write_history(fname);
if (errno == 0)
return true; return true;
psql_error("could not save history to file \"%s\": %s\n", psql_error("could not save history to file \"%s\": %s\n",
fname, strerror(errno)); fname, strerror(errno));
} }
#else #else
/* only get here in \s case, so complain */
psql_error("history is not supported by this installation\n"); psql_error("history is not supported by this installation\n");
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment