From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=AWL,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 74D7A1F55B for ; Thu, 28 May 2020 10:04:23 +0000 (UTC) Received: from localhost ([::1]:42786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeFOg-0002KY-MC for normalperson@yhbt.net; Thu, 28 May 2020 06:04:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeFOe-0002KO-Dv for bug-gnulib@gnu.org; Thu, 28 May 2020 06:04:20 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:58068) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jeFOd-0007Lu-RM; Thu, 28 May 2020 06:04:19 -0400 Received: from deisui.org ([219.94.251.20]:57058 helo=localhost.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jeFOc-0003dk-Hl; Thu, 28 May 2020 06:04:19 -0400 Message-ID: <87wo4wnzoj.fsf-ueno@gnu.org> From: Daiki Ueno To: Bruno Haible Subject: Re: portability of fopen and 'e' (O_CLOEXEC) flag References: <7d7cfa6e-af75-82d0-e076-bf411b87a3ab@gmx.de> <2318672.ckYohbHQXy@omega> <2446740.5YXOBombHr@omega> <2516365.yJxUV66HyY@omega> <877dwwpefb.fsf-ueno@gnu.org> Date: Thu, 28 May 2020 12:04:12 +0200 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tim =?utf-8?Q?R=C3=BChsen?= , bug-gnulib@gnu.org Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" --=-=-= Content-Type: text/plain Daiki Ueno writes: > Bruno Haible writes: > >>> Here are proposed patches for other modules. Does this look right? >> >> There were no objections. I pushed the changes. > > Thank you for this. I have rebased GnuTLS on top of it, but noticed a > strange test failures on Windows CI, which involve reading binary files > (OCSP response): > https://gitlab.com/gnutls/gnutls/-/jobs/569815031 > > It seems that the fopen module ignores a 'b' flag. The attached patch > fixes the failures. Sorry, attached an old patch; this would be simpler (and also supports other platforms that need O_BINARY). --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-fopen-gnu-make-b-flag-can-be-used-with-e-on-Windows.patch >From 81695244eb467603009a2777c3a8438f1a707954 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 28 May 2020 11:40:49 +0200 Subject: [PATCH] fopen-gnu: make 'b' flag can be used with 'e' on Windows * lib/fopen.c (rpl_fopen): Pass O_BINARY to open, if a 'b' flag is specified on Windows. * tests/test-fopen-gnu.c (DATA): New define. (main): Add test for reading binary files with an 'e' flag. --- ChangeLog | 8 ++++++++ lib/fopen.c | 4 ++++ tests/test-fopen-gnu.c | 17 +++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/ChangeLog b/ChangeLog index c17b76b72..ea2716b2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2020-05-28 Daiki Ueno + + fopen-gnu: make 'b' flag can be used with 'e' on Windows + * lib/fopen.c (rpl_fopen): Pass O_BINARY to open, if a 'b' flag is + specified on Windows. + * tests/test-fopen-gnu.c (DATA): New define. + (main): Add test for reading binary files with an 'e' flag. + 2020-05-27 Bruno Haible Don't assume that UNICODE is not defined. diff --git a/lib/fopen.c b/lib/fopen.c index 20065e4c6..47d7f194d 100644 --- a/lib/fopen.c +++ b/lib/fopen.c @@ -101,6 +101,10 @@ rpl_fopen (const char *filename, const char *mode) #endif continue; case 'b': + /* While it is non-standard, O_BINARY is guaranteed by + gnulib . We can also assume that orig_fopen + supports the 'b' flag. */ + open_flags_standard |= O_BINARY; #if GNULIB_FOPEN_GNU if (q < fdopen_mode_buf + BUF_SIZE) *q++ = *p; diff --git a/tests/test-fopen-gnu.c b/tests/test-fopen-gnu.c index cae40421a..eeb1712c7 100644 --- a/tests/test-fopen-gnu.c +++ b/tests/test-fopen-gnu.c @@ -29,15 +29,20 @@ #define BASE "test-fopen-gnu.t" +/* 0x1a is an EOF on Windows. */ +#define DATA "abc\x1adef" + int main (void) { FILE *f; int fd; int flags; + char buf[16]; /* Remove anything from prior partial run. */ unlink (BASE "file"); + unlink (BASE "binary"); /* Create the file. */ f = fopen (BASE "file", "w"); @@ -64,8 +69,20 @@ main (void) ASSERT (f == NULL); ASSERT (errno == EEXIST); + /* Open a binary file and check that the 'e' mode doesn't interfere. */ + f = fopen (BASE "binary", "wbe"); + ASSERT (f); + ASSERT (fwrite (DATA, 1, sizeof(DATA)-1, f) == sizeof(DATA)-1); + ASSERT (fclose (f) == 0); + + f = fopen (BASE "binary", "rbe"); + ASSERT (f); + ASSERT (fread (buf, 1, sizeof(buf), f) == sizeof(DATA)-1); + ASSERT (fclose (f) == 0); + /* Cleanup. */ ASSERT (unlink (BASE "file") == 0); + ASSERT (unlink (BASE "binary") == 0); return 0; } -- 2.26.2 --=-=-= Content-Type: text/plain Regards, -- Daiki Ueno --=-=-=--