Patch for COPY command - Mailing list pgsql-cygwin

From Kevin Chase
Subject Patch for COPY command
Date
Msg-id F96dcpLyuIQpfI4iodI0000ba6a@hotmail.com
Whole thread Raw
List pgsql-cygwin
I just started playing around with postgresql on cygwin, and hit my first
snag.  The COPY command assumes its input/output to have UNIX style line
endings, which is an inconvenience since notepad is my favorite editor
(seriously).  Here's an obvious patch to src\backend\commands\copy.c which
all platforms should be happy with (note: PG_BINARY_R,W should probably be
"rb","wb" on all platforms rather than having the current ifdef for cygwin).

I suspect there are other places in the code that should be using explicit
text-mode open calls, but I don't have time to do an exhaustive search.

--Kevin

bash-2.05a$ diff -u copy.c.orig copy.c
--- copy.c.orig Thu Aug 16 12:36:37 2001
+++ copy.c      Sun Jan 27 22:43:56 2002
@@ -273,6 +273,7 @@
        Relation        rel;
        const AclMode required_access = from ? ACL_WR : ACL_RD;
        int                     result;
+       char *open_mode = NULL;

        /*
         * Open and lock the relation, using the appropriate lock type.
@@ -326,7 +327,8 @@
                }
                else
                {
-                       fp = AllocateFile(filename, PG_BINARY_R);
+                       open_mode = binary ? "rb" : "r";
+                       fp = AllocateFile(filename, open_mode);
                        if (fp == NULL)
                                elog(ERROR, "COPY command, running in
backend with "
                                         "effective uid %d, could not open
file '%s' for "
@@ -370,7 +372,8 @@
                                         " COPY command.");

                        oumask = umask((mode_t) 022);
-                       fp = AllocateFile(filename, PG_BINARY_W);
+                       open_mode = binary ? "wb" : "w";
+                       fp = AllocateFile(filename, open_mode);
                        umask(oumask);

                        if (fp == NULL)



_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx


pgsql-cygwin by date:

Previous
From: "ewan galloway"
Date:
Subject: Installing PostgreSQL on Windows XP.
Next
From: "Henshall, Stuart - WCP"
Date:
Subject: Re: Installing PostgreSQL on Windows XP.