diff options
author | Michael Paquier <michael@paquier.xyz> | 2019-08-09 11:05:14 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2019-08-09 11:05:14 +0900 |
commit | b8f2da0ac5a24f669c8d320c58646759b8fc69a5 (patch) | |
tree | dc68a064354682b5916a87224ef325f1e83c1bbf /src/bin/pg_upgrade/option.c | |
parent | 28b901f73a3924187988bfaac57d20e422a432c3 (diff) | |
download | postgresql-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/pg_upgrade/option.c')
-rw-r--r-- | src/bin/pg_upgrade/option.c | 20 |
1 files changed, 5 insertions, 15 deletions
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c index 7e3d3f1bb27..e4093ed5afc 100644 --- a/src/bin/pg_upgrade/option.c +++ b/src/bin/pg_upgrade/option.c @@ -15,6 +15,7 @@ #endif #include "getopt_long.h" +#include "common/string.h" #include "utils/pidfile.h" #include "pg_upgrade.h" @@ -411,7 +412,6 @@ adjust_data_dir(ClusterInfo *cluster) cmd_output[MAX_STRING]; FILE *fp, *output; - int len; /* Initially assume config dir and data dir are the same */ cluster->pgconfig = pg_strdup(cluster->pgdata); @@ -452,12 +452,8 @@ adjust_data_dir(ClusterInfo *cluster) pclose(output); - /* Remove trailing newline, handling Windows newlines as well */ - len = strlen(cmd_output); - while (len > 0 && - (cmd_output[len - 1] == '\n' || - cmd_output[len - 1] == '\r')) - cmd_output[--len] = '\0'; + /* strip trailing newline and carriage return */ + (void) pg_strip_crlf(cmd_output); cluster->pgdata = pg_strdup(cmd_output); @@ -518,15 +514,9 @@ get_sock_dir(ClusterInfo *cluster, bool live_check) sscanf(line, "%hu", &old_cluster.port); if (lineno == LOCK_FILE_LINE_SOCKET_DIR) { - int len; - + /* strip trailing newline and carriage return */ cluster->sockdir = pg_strdup(line); - /* strip off newline, handling Windows newlines as well */ - len = strlen(cluster->sockdir); - while (len > 0 && - (cluster->sockdir[len - 1] == '\n' || - cluster->sockdir[len - 1] == '\r')) - cluster->sockdir[--len] = '\0'; + (void) pg_strip_crlf(cluster->sockdir); } } fclose(fp); |