1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-23 03:21:12 +03:00

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
This commit is contained in:
Michael Paquier
2019-08-09 11:05:14 +09:00
parent 28b901f73a
commit b8f2da0ac5
8 changed files with 45 additions and 45 deletions

View File

@ -22,6 +22,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include "common/string.h"
#include "libpq/libpq.h"
#include "storage/fd.h"
@ -112,11 +113,8 @@ run_ssl_passphrase_command(const char *prompt, bool is_server_start, char *buf,
goto error;
}
/* strip trailing newline, including \r in case we're on Windows */
len = strlen(buf);
while (len > 0 && (buf[len - 1] == '\n' ||
buf[len - 1] == '\r'))
buf[--len] = '\0';
/* strip trailing newline and carriage return */
len = pg_strip_crlf(buf);
error:
pfree(command.data);