pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Dmitry Koval <d.koval@postgrespro.ru>
To: Michael Paquier <michael@paquier.xyz>
Cc: Juan José SantamarÃa Flecha <juanjo.santamaria@gmail.com>
Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)
Date: Fri, 19 Nov 2021 11:47:02 +0300
Message-ID: <4c22d38f-efa9-4d83-c551-707f1770e585@postgrespro.ru> (raw )
In-Reply-To: <YZdK6DjbtCT7rz9S@paquier.xyz >
References: <17288-6b58a91025a8a8a3@postgresql.org >
<b95273fb-a51a-d0a9-e4a8-501e32e204e5@postgrespro.ru >
<YZYDZwDtw/Ioojb4@paquier.xyz >
<9e4efe29-0ff9-0808-fe32-d1d50e0be4fa@postgrespro.ru >
<CAC+AXB3BKByL8O39qARu3XYMWmrNqMWhcHZZ_2ygqvrK-W6O1g@mail.gmail.com >
<fe1cde9e-1e52-4f24-3ff7-d01f28a63790@postgrespro.ru >
<YZdK6DjbtCT7rz9S@paquier.xyz >
>I still think that we should not call GetFileInformationByHandle()
>when it comes to an argument that we know will fail, ...
Our program calls function freopen() (this function is used in file
src\backend\utils\error\elog.c). So we don't know exactly that
GetFileInformationByHandle() will fails for stdin/stdout/stderr.
Ior illustration, I attached small example (test.c) for this case:
1) GetFileInformationByHandle() for "stdout" works without error;
2) file "1.txt" after running test contains:
Sample string
attributes = 0x2020, file size = 15
>Each fileno is going to be 0, 1 or 2 in those cases, still
>it would be better to rely on the result of fileno() as v3 is
>doing?
I think fileno() is safer. We can call fclose(stdout) and
_fileno(stdout) returns -1 after that. But I don't know:
can OS reuse fileno=1 or not in this case?
With best regards,
Dmitry.
Attachments:
test.c (text/plain, 726B) download
#include <windows.h>
#include <stdio.h>
#include <io.h>
int main()
{
int err;
FILE* stream;
HANDLE hFile;
BY_HANDLE_FILE_INFORMATION fiData;
if (err = freopen_s(&stream, "1.txt", "a", stdout))
{
printf("freopen_s error %d\n", err);
return 1;
}
printf("Sample string\n");
fflush(stdout);
hFile = (HANDLE)_get_osfhandle(_fileno(stdout));
if (hFile == INVALID_HANDLE_VALUE)
{
printf("_get_osfhandle error\n");
return 1;
}
if (!GetFileInformationByHandle(hFile, &fiData))
{
printf("GetFileInformationByHandle error %d\n", GetLastError());
return 1;
}
printf("attributes = 0x%X, file size = %d\n", fiData.dwFileAttributes, fiData.nFileSizeLow);
return 0;
}
view thread (29+ messages) latest in thread
Message-ID: <4c22d38f-efa9-4d83-c551-707f1770e585@postgrespro.ru>
Permalink: ../4c22d38f-efa9-4d83-c551-707f1770e585@postgrespro.ru/
Also on: postgresql.org/message-id/4c22d38f-efa9-4d83-c551-707f1770e585@postgrespro.ru
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: d.koval@postgrespro.ru, michael@paquier.xyz, juanjo.santamaria@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)
In-Reply-To: <4c22d38f-efa9-4d83-c551-707f1770e585@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox