Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mnzY7-0002F0-Fd for pgsql-bugs@arkaria.postgresql.org; Fri, 19 Nov 2021 08:47:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mnzY6-0004ro-9E for pgsql-bugs@arkaria.postgresql.org; Fri, 19 Nov 2021 08:47:10 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mnzY5-0004rf-SP for pgsql-bugs@lists.postgresql.org; Fri, 19 Nov 2021 08:47:10 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mnzXz-0004zT-96 for pgsql-bugs@lists.postgresql.org; Fri, 19 Nov 2021 08:47:09 +0000 Received: from [192.168.28.32] (cyclops.postgrespro.ru [93.174.131.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id CD71721C2A33; Fri, 19 Nov 2021 11:47:01 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1637311621; bh=B0ZJbqC9oTxLGHoQZPQmYDC9Vvh/aM1zqZtC3MVP8Ew=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=UO7jSy5w0K5fP1NM0COvPB+YWSs7S5Mi/Mn5BqJllMUqrpelSGdv0XCr7OKyHg3Tx x9Y4aK+XUt+i0YjrbFiuT8bz1HfEYSqFkq5WXX9GGn/UHpsjBMPFhm6eFVvBX8mm0X T1zToPb8CtJIQLfvK0u8WJbdjVECAkZuRDAWnLqo= Content-Type: multipart/mixed; boundary="------------sKP4hhspg10NywuVtGM9HSu5" Message-ID: <4c22d38f-efa9-4d83-c551-707f1770e585@postgrespro.ru> Date: Fri, 19 Nov 2021 11:47:02 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: BUG #17288: PSQL bug with COPY command (Windows) Content-Language: ru To: Michael Paquier Cc: =?UTF-8?Q?Juan_Jos=c3=a9_Santamar=c3=ada_Flecha?= , PostgreSQL mailing lists References: <17288-6b58a91025a8a8a3@postgresql.org> <9e4efe29-0ff9-0808-fe32-d1d50e0be4fa@postgrespro.ru> From: Dmitry Koval In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------sKP4hhspg10NywuVtGM9HSu5 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit >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. --------------sKP4hhspg10NywuVtGM9HSu5 Content-Type: text/plain; charset=UTF-8; name="test.c" Content-Disposition: attachment; filename="test.c" Content-Transfer-Encoding: base64 I2luY2x1ZGUgPHdpbmRvd3MuaD4NCiNpbmNsdWRlIDxzdGRpby5oPg0KI2luY2x1ZGUgPGlv Lmg+DQoNCmludCBtYWluKCkNCnsNCglpbnQgZXJyOw0KCUZJTEUqIHN0cmVhbTsNCglIQU5E TEUgaEZpbGU7DQoJQllfSEFORExFX0ZJTEVfSU5GT1JNQVRJT04gZmlEYXRhOw0KDQoJaWYg KGVyciA9IGZyZW9wZW5fcygmc3RyZWFtLCAiMS50eHQiLCAiYSIsIHN0ZG91dCkpDQoJew0K CQlwcmludGYoImZyZW9wZW5fcyBlcnJvciAlZFxuIiwgZXJyKTsNCgkJcmV0dXJuIDE7DQoJ fQ0KDQoJcHJpbnRmKCJTYW1wbGUgc3RyaW5nXG4iKTsNCglmZmx1c2goc3Rkb3V0KTsNCg0K CWhGaWxlID0gKEhBTkRMRSlfZ2V0X29zZmhhbmRsZShfZmlsZW5vKHN0ZG91dCkpOw0KCWlm IChoRmlsZSA9PSBJTlZBTElEX0hBTkRMRV9WQUxVRSkNCgl7DQoJCXByaW50ZigiX2dldF9v c2ZoYW5kbGUgZXJyb3JcbiIpOw0KCQlyZXR1cm4gMTsNCgl9DQoNCglpZiAoIUdldEZpbGVJ bmZvcm1hdGlvbkJ5SGFuZGxlKGhGaWxlLCAmZmlEYXRhKSkNCgl7DQoJCXByaW50ZigiR2V0 RmlsZUluZm9ybWF0aW9uQnlIYW5kbGUgZXJyb3IgJWRcbiIsIEdldExhc3RFcnJvcigpKTsN CgkJcmV0dXJuIDE7DQoJfQ0KDQoJcHJpbnRmKCJhdHRyaWJ1dGVzID0gMHglWCwgZmlsZSBz aXplID0gJWRcbiIsIGZpRGF0YS5kd0ZpbGVBdHRyaWJ1dGVzLCBmaURhdGEubkZpbGVTaXpl TG93KTsNCg0KCXJldHVybiAwOw0KfQ0K --------------sKP4hhspg10NywuVtGM9HSu5--