diff options
Diffstat (limited to 'src/bin/pg_upgrade/option.c')
-rw-r--r-- | src/bin/pg_upgrade/option.c | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c index d76f27c9e8f..b62cbbba438 100644 --- a/src/bin/pg_upgrade/option.c +++ b/src/bin/pg_upgrade/option.c @@ -405,6 +405,7 @@ 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); @@ -445,9 +446,12 @@ adjust_data_dir(ClusterInfo *cluster) pclose(output); - /* Remove trailing newline */ - if (strchr(cmd_output, '\n') != NULL) - *strchr(cmd_output, '\n') = '\0'; + /* 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'; cluster->pgdata = pg_strdup(cmd_output); @@ -508,10 +512,15 @@ get_sock_dir(ClusterInfo *cluster, bool live_check) sscanf(line, "%hu", &old_cluster.port); if (lineno == LOCK_FILE_LINE_SOCKET_DIR) { + int len; + cluster->sockdir = pg_strdup(line); - /* strip off newline */ - if (strchr(cluster->sockdir, '\n') != NULL) - *strchr(cluster->sockdir, '\n') = '\0'; + /* 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'; } } fclose(fp); |