|
7 | 7 | * |
8 | 8 | * |
9 | 9 | * IDENTIFICATION |
10 | | - * $PostgreSQL: pgsql/src/port/exec.c,v 1.21 2004/08/09 20:20:46 tgl Exp $ |
| 10 | + * $PostgreSQL: pgsql/src/port/exec.c,v 1.22 2004/08/16 01:26:31 momjian Exp $ |
11 | 11 | * |
12 | 12 | *------------------------------------------------------------------------- |
13 | 13 | */ |
@@ -381,26 +381,28 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize) |
381 | 381 | { |
382 | 382 | /* So we read some data */ |
383 | 383 | retval = line; |
| 384 | + int len = strlen(line); |
384 | 385 |
|
385 | 386 | /* |
386 | | - * Sometime the child returns "\r\n", which doesn't match |
387 | | - * our version string. The backend uses |
388 | | - * setvbuf(stdout, NULL, _IONBF, 0), but pg_dump doesn't |
389 | | - * so we have to fix it here. |
| 387 | + * If EOL is \r\n, convert to just \n. |
| 388 | + * Because stdout is a text-mode stream, the \n output by |
| 389 | + * the child process is received as \r\n, so we convert it |
| 390 | + * to \n. The server main.c sets |
| 391 | + * setvbuf(stdout, NULL, _IONBF, 0) which has the effect |
| 392 | + * of disabling \n to \r\n expansion for stdout. |
390 | 393 | */ |
391 | | - if (strlen(line) >= 2 && |
392 | | - line[strlen(line)-2] == '\r' && |
393 | | - line[strlen(line)-1] == '\n') |
| 394 | + if (len >= 2 && line[len-2] == '\r' && line[len-1] == '\n') |
394 | 395 | { |
395 | | - line[strlen(line)-2] = '\n'; |
396 | | - line[strlen(line)-1] = '\0'; |
| 396 | + line[len-2] = '\n'; |
| 397 | + line[len-1] = '\0'; |
| 398 | + len--; |
397 | 399 | } |
398 | 400 |
|
399 | 401 | /* |
400 | 402 | * We emulate fgets() behaviour. So if there is no newline |
401 | 403 | * at the end, we add one... |
402 | 404 | */ |
403 | | - if (line[strlen(line)-1] != '\n') |
| 405 | + if (line[len-1] != '\n') |
404 | 406 | strcat(line,"\n"); |
405 | 407 | } |
406 | 408 |
|
|
0 commit comments