Index: src/bin/psql/command.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/command.c,v
retrieving revision 1.117
diff -c -c -r1.117 command.c
*** src/bin/psql/command.c	18 Jun 2004 06:14:04 -0000	1.117
--- src/bin/psql/command.c	11 Jul 2004 00:53:36 -0000
***************
*** 1197,1203 ****
  	if (!error)
  	{
  #endif
! 		stream = fopen(fname, "r");
  		if (!stream)
  		{
  			psql_error("%s: %s\n", fname, strerror(errno));
--- 1197,1203 ----
  	if (!error)
  	{
  #endif
! 		stream = fopen(fname, R_TEXTFILE);
  		if (!stream)
  		{
  			psql_error("%s: %s\n", fname, strerror(errno));
***************
*** 1262,1268 ****
  	if (!filename)
  		return false;
  
! 	fd = fopen(filename, "r");
  
  	if (!fd)
  	{
--- 1262,1268 ----
  	if (!filename)
  		return false;
  
! 	fd = fopen(filename, R_TEXTFILE);
  
  	if (!fd)
  	{
Index: src/bin/psql/common.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/common.h,v
retrieving revision 1.35
diff -c -c -r1.35 common.h
*** src/bin/psql/common.h	19 Apr 2004 17:42:58 -0000	1.35
--- src/bin/psql/common.h	11 Jul 2004 00:53:36 -0000
***************
*** 62,65 ****
--- 62,77 ----
  
  extern char *expand_tilde(char **filename);
  
+ /*
+  *	WIN32 treats Control-Z as EOF in files opened in text mode.
+  *	Therefore, we open files in binary mode on Win32 so we can read
+  *	literal control-Z.  The other affect is that we see CRLF, but
+  *	that is OK because we can already handle those cleanly.
+  */
+ #ifndef WIN32
+ #define R_TEXTFILE	"r"
+ #else
+ #define R_TEXTFILE	"rb"
+ #endif
+ 
  #endif   /* COMMON_H */
Index: src/bin/psql/copy.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/copy.c,v
retrieving revision 1.47
diff -c -c -r1.47 copy.c
*** src/bin/psql/copy.c	7 May 2004 00:24:58 -0000	1.47
--- src/bin/psql/copy.c	11 Jul 2004 00:53:37 -0000
***************
*** 516,522 ****
  	if (options->from)
  	{
  		if (options->file)
! 			copystream = fopen(options->file, "r");
  		else if (!options->psql_inout)
   			copystream = pset.cur_cmd_source;
  		else
--- 516,522 ----
  	if (options->from)
  	{
  		if (options->file)
! 			copystream = fopen(options->file, R_TEXTFILE);
  		else if (!options->psql_inout)
   			copystream = pset.cur_cmd_source;
  		else
Index: src/bin/psql/psqlscan.l
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/psqlscan.l,v
retrieving revision 1.3
diff -c -c -r1.3 psqlscan.l
*** src/bin/psql/psqlscan.l	7 May 2004 00:24:58 -0000	1.3
--- src/bin/psql/psqlscan.l	11 Jul 2004 00:53:38 -0000
***************
*** 1284,1290 ****
  				char		buf[512];
  				size_t		result;
  
! 				fd = popen(cmd, "r");
  				if (!fd)
  				{
  					psql_error("%s: %s\n", cmd, strerror(errno));
--- 1284,1290 ----
  				char		buf[512];
  				size_t		result;
  
! 				fd = popen(cmd, R_TEXTFILE);
  				if (!fd)
  				{
  					psql_error("%s: %s\n", cmd, strerror(errno));
