|
15 | 15 | #endif
|
16 | 16 |
|
17 | 17 | #include "getopt_long.h"
|
| 18 | +#include "common/string.h" |
18 | 19 | #include "utils/pidfile.h"
|
19 | 20 |
|
20 | 21 | #include "pg_upgrade.h"
|
@@ -411,7 +412,6 @@ adjust_data_dir(ClusterInfo *cluster)
|
411 | 412 | cmd_output[MAX_STRING];
|
412 | 413 | FILE *fp,
|
413 | 414 | *output;
|
414 |
| - int len; |
415 | 415 |
|
416 | 416 | /* Initially assume config dir and data dir are the same */
|
417 | 417 | cluster->pgconfig = pg_strdup(cluster->pgdata);
|
@@ -452,12 +452,8 @@ adjust_data_dir(ClusterInfo *cluster)
|
452 | 452 |
|
453 | 453 | pclose(output);
|
454 | 454 |
|
455 |
| - /* Remove trailing newline, handling Windows newlines as well */ |
456 |
| - len = strlen(cmd_output); |
457 |
| - while (len > 0 && |
458 |
| - (cmd_output[len - 1] == '\n' || |
459 |
| - cmd_output[len - 1] == '\r')) |
460 |
| - cmd_output[--len] = '\0'; |
| 455 | + /* strip trailing newline and carriage return */ |
| 456 | + (void) pg_strip_crlf(cmd_output); |
461 | 457 |
|
462 | 458 | cluster->pgdata = pg_strdup(cmd_output);
|
463 | 459 |
|
@@ -518,15 +514,9 @@ get_sock_dir(ClusterInfo *cluster, bool live_check)
|
518 | 514 | sscanf(line, "%hu", &old_cluster.port);
|
519 | 515 | if (lineno == LOCK_FILE_LINE_SOCKET_DIR)
|
520 | 516 | {
|
521 |
| - int len; |
522 |
| - |
| 517 | + /* strip trailing newline and carriage return */ |
523 | 518 | cluster->sockdir = pg_strdup(line);
|
524 |
| - /* strip off newline, handling Windows newlines as well */ |
525 |
| - len = strlen(cluster->sockdir); |
526 |
| - while (len > 0 && |
527 |
| - (cluster->sockdir[len - 1] == '\n' || |
528 |
| - cluster->sockdir[len - 1] == '\r')) |
529 |
| - cluster->sockdir[--len] = '\0'; |
| 519 | + (void) pg_strip_crlf(cluster->sockdir); |
530 | 520 | }
|
531 | 521 | }
|
532 | 522 | fclose(fp);
|
|
0 commit comments