Skip to content

Commit 98e9775

Browse files
committed
Use standard macro for psql binary file open. Add comment explaining
control-z requirement.
1 parent c8c40bb commit 98e9775

File tree

5 files changed

+16
-21
lines changed

5 files changed

+16
-21
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.118 2004/07/11 00:54:55 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.119 2004/07/11 13:29:15 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_TEXTFILE);
1200+
stream = fopen(fname, PG_BINARY_R);
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_TEXTFILE);
1265+
fd = fopen(filename, PG_BINARY_R);
12661266

12671267
if (!fd)
12681268
{

src/bin/psql/common.h

Lines changed: 1 addition & 13 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/common.h,v 1.36 2004/07/11 00:54:55 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/common.h,v 1.37 2004/07/11 13:29:15 momjian Exp $
77
*/
88
#ifndef COMMON_H
99
#define COMMON_H
@@ -62,16 +62,4 @@ 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-
7765
#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.48 2004/07/11 00:54:55 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/copy.c,v 1.49 2004/07/11 13:29:15 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_TEXTFILE);
519+
copystream = fopen(options->file, PG_BINARY_R);
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.4 2004/07/11 00:54:55 momjian Exp $
34+
* $PostgreSQL: pgsql/src/bin/psql/psqlscan.l,v 1.5 2004/07/11 13:29:15 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_TEXTFILE);
1287+
fd = popen(cmd, PG_BINARY_R);
12881288
if (!fd)
12891289
{
12901290
psql_error("%s: %s\n", cmd, strerror(errno));

src/include/c.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/include/c.h,v 1.165 2004/05/21 05:08:03 tgl Exp $
15+
* $PostgreSQL: pgsql/src/include/c.h,v 1.166 2004/07/11 13:29:16 momjian Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -671,6 +671,13 @@ typedef NameData *Name;
671671
* ----------------------------------------------------------------
672672
*/
673673

674+
/*
675+
* NOTE: this is also used for opening text files.
676+
* WIN32 treats Control-Z as EOF in files opened in text mode.
677+
* Therefore, we open files in binary mode on Win32 so we can read
678+
* literal control-Z. The other affect is that we see CRLF, but
679+
* that is OK because we can already handle those cleanly.
680+
*/
674681
#if defined(__CYGWIN__) || defined(WIN32)
675682
#define PG_BINARY O_BINARY
676683
#define PG_BINARY_R "rb"

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