33 *
44 * Copyright (c) 2000-2006, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.55 2006/06/14 16:49:02 tgl Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/input.c,v 1.56 2006/06/18 17:30:48 tgl Exp $
77 */
88#include "postgres_fe.h"
99
@@ -245,11 +245,14 @@ encode_history(void)
245245HIST_ENTRY * cur_hist ;
246246char * cur_ptr ;
247247
248- for (history_set_pos (0 ),cur_hist = current_history ();
249- cur_hist ;cur_hist = next_history ())
250- for (cur_ptr = cur_hist -> line ;* cur_ptr ;cur_ptr ++ )
248+ history_set_pos (0 );
249+ for (cur_hist = current_history ();cur_hist ;cur_hist = next_history ())
250+ {
251+ /* some platforms declare HIST_ENTRY.line as const char * */
252+ for (cur_ptr = (char * )cur_hist -> line ;* cur_ptr ;cur_ptr ++ )
251253if (* cur_ptr == '\n' )
252254* cur_ptr = NL_IN_HISTORY ;
255+ }
253256}
254257
255258/*
@@ -261,11 +264,14 @@ decode_history(void)
261264HIST_ENTRY * cur_hist ;
262265char * cur_ptr ;
263266
264- for (history_set_pos (0 ),cur_hist = current_history ();
265- cur_hist ;cur_hist = next_history ())
266- for (cur_ptr = cur_hist -> line ;* cur_ptr ;cur_ptr ++ )
267+ history_set_pos (0 );
268+ for (cur_hist = current_history ();cur_hist ;cur_hist = next_history ())
269+ {
270+ /* some platforms declare HIST_ENTRY.line as const char * */
271+ for (cur_ptr = (char * )cur_hist -> line ;* cur_ptr ;cur_ptr ++ )
267272if (* cur_ptr == NL_IN_HISTORY )
268273* cur_ptr = '\n' ;
274+ }
269275}
270276#endif /* USE_READLINE */
271277
@@ -339,13 +345,22 @@ saveHistory(char *fname, bool encodeFlag)
339345{
340346if (encodeFlag )
341347encode_history ();
342- if (write_history (fname )== 0 )
348+
349+ /*
350+ * return value of write_history is not standardized across GNU
351+ * readline and libedit. Therefore, check for errno becoming set
352+ * to see if the write failed.
353+ */
354+ errno = 0 ;
355+ (void )write_history (fname );
356+ if (errno == 0 )
343357return true;
344358
345359psql_error ("could not save history to file \"%s\": %s\n" ,
346360fname ,strerror (errno ));
347361}
348362#else
363+ /* only get here in \s case, so complain */
349364psql_error ("history is not supported by this installation\n" );
350365#endif
351366