Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 330c6c4

Browse files
committed
Open files in binary mode on Win32 so control-z isn't seen as EOF.
1 parent e5ca4bd commit 330c6c4

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/bin/psql/command.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.117 2004/06/18 06:14:04 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.118 2004/07/11 00:54:55 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "command.h"
@@ -1197,7 +1197,7 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
11971197
if (!error)
11981198
{
11991199
#endif
1200-
stream = fopen(fname, "r");
1200+
stream = fopen(fname, R_TEXTFILE);
12011201
if (!stream)
12021202
{
12031203
psql_error("%s: %s\n", fname, strerror(errno));
@@ -1262,7 +1262,7 @@ process_file(char *filename)
12621262
if (!filename)
12631263
return false;
12641264

1265-
fd = fopen(filename, "r");
1265+
fd = fopen(filename, R_TEXTFILE);
12661266

12671267
if (!fd)
12681268
{

src/bin/psql/common.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.35 2004/04/19 17:42:58 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.36 2004/07/11 00:54:55 momjian Exp $
77
*/
88
#ifndef COMMON_H
99
#define COMMON_H
@@ -62,4 +62,16 @@ extern char parse_char(char **buf);
6262

6363
extern char *expand_tilde(char **filename);
6464

65+
/*
66+
* WIN32 treats Control-Z as EOF in files opened in text mode.
67+
* Therefore, we open files in binary mode on Win32 so we can read
68+
* literal control-Z. The other affect is that we see CRLF, but
69+
* that is OK because we can already handle those cleanly.
70+
*/
71+
#ifndef WIN32
72+
#define R_TEXTFILE "r"
73+
#else
74+
#define R_TEXTFILE "rb"
75+
#endif
76+
6577
#endif /* COMMON_H */

src/bin/psql/copy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.47 2004/05/07 00:24:58 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.48 2004/07/11 00:54:55 momjian Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "copy.h"
@@ -516,7 +516,7 @@ do_copy(const char *args)
516516
if (options->from)
517517
{
518518
if (options->file)
519-
copystream = fopen(options->file, "r");
519+
copystream = fopen(options->file, R_TEXTFILE);
520520
else if (!options->psql_inout)
521521
copystream = pset.cur_cmd_source;
522522
else

src/bin/psql/psqlscan.l

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* Portions Copyright (c) 1994, Regents of the University of California
3232
*
3333
* IDENTIFICATION
34-
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.3 2004/05/07 00:24:58 tgl Exp $
34+
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.4 2004/07/11 00:54:55 momjian Exp $
3535
*
3636
*-------------------------------------------------------------------------
3737
*/
@@ -1284,7 +1284,7 @@ psql_scan_slash_option(PsqlScanState state,
12841284
char buf[512];
12851285
size_t result;
12861286

1287-
fd = popen(cmd, "r");
1287+
fd = popen(cmd, R_TEXTFILE);
12881288
if (!fd)
12891289
{
12901290
psql_error("%s: %s\n", cmd, strerror(errno));

0 commit comments

Comments
 (0)