Skip to content

Commit c7ae53a

Browse files
committed
Clarify need for \r\n -> \n translation in version checking code.
1 parent 1a3de15 commit c7ae53a

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/port/exec.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* 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 $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -381,26 +381,28 @@ static char *pipe_read_line(char *cmd, char *line, int maxsize)
381381
{
382382
/* So we read some data */
383383
retval = line;
384+
int len = strlen(line);
384385

385386
/*
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.
390393
*/
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')
394395
{
395-
line[strlen(line)-2] = '\n';
396-
line[strlen(line)-1] = '\0';
396+
line[len-2] = '\n';
397+
line[len-1] = '\0';
398+
len--;
397399
}
398400

399401
/*
400402
* We emulate fgets() behaviour. So if there is no newline
401403
* at the end, we add one...
402404
*/
403-
if (line[strlen(line)-1] != '\n')
405+
if (line[len-1] != '\n')
404406
strcat(line,"\n");
405407
}
406408

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy