diff options
Diffstat (limited to 'src/bin/pg_ctl/pg_ctl.c')
-rw-r--r-- | src/bin/pg_ctl/pg_ctl.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index a10bc8d545b..3a9a65d31d7 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -2176,6 +2176,7 @@ adjust_data_dir(void) filename[MAXPGPATH], *my_exec_path; FILE *fd; + int len; /* do nothing if we're working without knowledge of data dir */ if (pg_config == NULL) @@ -2218,9 +2219,12 @@ adjust_data_dir(void) pclose(fd); free(my_exec_path); - /* Remove trailing newline */ - if (strchr(filename, '\n') != NULL) - *strchr(filename, '\n') = '\0'; + /* Remove trailing newline, handling Windows newlines as well */ + len = strlen(filename); + while (len > 0 && + (filename[len - 1] == '\n' || + filename[len - 1] == '\r')) + filename[--len] = '\0'; free(pg_data); pg_data = pg_strdup(filename); |