On Mon, 18 Apr 2022 at 22:41, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Japin Li <japinli@hotmail.com> writes:
>> I found we defined PG_BINARY_R/W/A macros for opening files, however,
>> there are some places use the constant strings. IMO we should use
>> those macros instead of constant strings. Here is a patch for it.
>> Any thoughts?
>
> A lot of these changes look wrong to me: they are substituting "rb" for
> "r", etc, in places that mean to read text files. You have to think
> about the Windows semantics.
>
I do this substituting, since the comment says it can be used for opening
text files. Maybe I misunderstand the comment.
/*
* NOTE: this is also used for opening text files.
* 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.
*/
#if defined(WIN32) || defined(__CYGWIN__)
#define PG_BINARY O_BINARY
#define PG_BINARY_A "ab"
#define PG_BINARY_R "rb"
#define PG_BINARY_W "wb"
#else
#define PG_BINARY 0
#define PG_BINARY_A "a"
#define PG_BINARY_R "r"
#define PG_BINARY_W "w"
#endif
--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.