aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/prompt.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2019-08-09 11:05:14 +0900
committerMichael Paquier <michael@paquier.xyz>2019-08-09 11:05:14 +0900
commitb8f2da0ac5a24f669c8d320c58646759b8fc69a5 (patch)
treedc68a064354682b5916a87224ef325f1e83c1bbf /src/bin/psql/prompt.c
parent28b901f73a3924187988bfaac57d20e422a432c3 (diff)
downloadpostgresql-b8f2da0ac5a24f669c8d320c58646759b8fc69a5.tar.gz
postgresql-b8f2da0ac5a24f669c8d320c58646759b8fc69a5.zip
Refactor logic to remove trailing CR/LF characters from strings
b654714 has reworked the way trailing CR/LF characters are removed from strings. This commit introduces a new routine in common/string.c and refactors the code so as the logic is in a single place, mostly. Author: Michael Paquier Reviewed-by: Bruce Momjian Discussion: https://postgr.es/m/20190801031820.GF29334@paquier.xyz
Diffstat (limited to 'src/bin/psql/prompt.c')
-rw-r--r--src/bin/psql/prompt.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 59afbc793a9..0fcb8c77832 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -22,6 +22,7 @@
#include "prompt.h"
#include "settings.h"
+#include "common/string.h"
/*--------------------------
* get_prompt
@@ -264,7 +265,6 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
FILE *fd;
char *file = pg_strdup(p + 1);
int cmdend;
- int buflen;
cmdend = strcspn(file, "`");
file[cmdend] = '\0';
@@ -275,10 +275,10 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
buf[0] = '\0';
pclose(fd);
}
- buflen = strlen(buf);
- while (buflen > 0 && (buf[buflen - 1] == '\n' ||
- buf[buflen - 1] == '\r'))
- buf[--buflen] = '\0';
+
+ /* strip trailing newline and carriage return */
+ (void) pg_strip_crlf(buf);
+
free(file);
p += cmdend + 1;
break;