summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier2018-09-19 23:54:37 +0000
committerMichael Paquier2018-09-19 23:54:37 +0000
commit40cfe86068f4c385517a8423cb8b3001e2f6a2fd (patch)
tree690e928b1c1ec4495500f0a4a2a02b08b1aa45a7
parent0d38e4ebb7a136a4376536c7989bf8f61f052688 (diff)
Enforce translation mode for Windows frontends to text with open/fopen
Allowing frontends to use concurrent-safe open() and fopen() via 0ba06e0 has the side-effect of switching the default translation mode from text to binary, so the switch can cause breakages for frontend tools when the caller of those new versions specifies neither binary and text. This commit makes sure to maintain strict compatibility with past versions, so as no frontends should see a difference when upgrading. Author: Laurenz Albe Reviewed-by: Michael Paquier, Tom Lane Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/port/open.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/port/open.c b/src/port/open.c
index a3ad946a60..a2f1044a20 100644
--- a/src/port/open.c
+++ b/src/port/open.c
@@ -71,6 +71,20 @@ pgwin32_open(const char *fileName, int fileFlags,...)
_O_SHORT_LIVED | O_DSYNC | O_DIRECT |
(O_CREAT | O_TRUNC | O_EXCL) | (O_TEXT | O_BINARY))) == fileFlags);
+#ifdef FRONTEND
+
+ /*
+ * Since PostgreSQL 12, those concurrent-safe versions of open() and
+ * fopen() can be used by frontends, having as side-effect to switch the
+ * file-translation mode from O_TEXT to O_BINARY if none is specified.
+ * Caller may want to enforce the binary or text mode, but if nothing is
+ * defined make sure that the default mode maps with what versions older
+ * than 12 have been doing.
+ */
+ if ((fileFlags & O_BINARY) == 0)
+ fileFlags |= O_TEXT;
+#endif
+
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;