Index: src/port/exec.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/port/exec.c,v
retrieving revision 1.21
diff -c -c -r1.21 exec.c
*** src/port/exec.c	9 Aug 2004 20:20:46 -0000	1.21
--- src/port/exec.c	16 Aug 2004 01:24:38 -0000
***************
*** 381,406 ****
  		{
  			/* So we read some data */
  			retval = line;
  
  			/*
! 			 *	Sometime the child returns "\r\n", which doesn't match
! 			 *	our version string.  The backend uses
! 			 *	setvbuf(stdout, NULL, _IONBF, 0), but pg_dump doesn't
! 			 *	so we have to fix it here.
  			 */
! 			if (strlen(line) >= 2 &&
! 				line[strlen(line)-2] == '\r' &&
! 				line[strlen(line)-1] == '\n')
  			{
! 				line[strlen(line)-2] = '\n';
! 				line[strlen(line)-1] = '\0';
  			}
  
  			/*
  			 *	We emulate fgets() behaviour. So if there is no newline
  			 *	at the end, we add one...
  			 */
! 			if (line[strlen(line)-1] != '\n')
  				strcat(line,"\n");
  		}
  
--- 381,408 ----
  		{
  			/* So we read some data */
  			retval = line;
+ 			int len = strlen(line);
  
  			/*
! 			 *	If EOL is \r\n, convert to just \n.
! 			 *	Because stdout is a text-mode stream, the \n output by
! 			 *	the child process is received as \r\n, so we convert it
! 			 *	to \n.  The server main.c sets
! 			 *	setvbuf(stdout, NULL, _IONBF, 0) which has the effect
! 			 *	of disabling \n to \r\n expansion for stdout.
  			 */
! 			if (len >= 2 && line[len-2] == '\r' && line[len-1] == '\n')
  			{
! 				line[len-2] = '\n';
! 				line[len-1] = '\0';
! 				len--;
  			}
  
  			/*
  			 *	We emulate fgets() behaviour. So if there is no newline
  			 *	at the end, we add one...
  			 */
! 			if (line[len-1] != '\n')
  				strcat(line,"\n");
  		}
  
