1From 3d074c8fca5fcf3e6b83d33788f35a8f1b3a44a2 Mon Sep 17 00:00:00 2001
2From: Jens Rehsack <sno@netbsd.org>
3Date: Fri, 21 Feb 2020 19:29:49 +0100
4Subject: [PATCH 3/3] posixfcn: fcntl: gnulib > make-emulated
5
6Rate the fcntl emulation from gnulib higher than the own one.
7
8Signed-off-by: Jens Rehsack <sno@netbsd.org>
9---
10Upstream-Status: Pending (https://savannah.gnu.org/bugs/?57888)
11
12 src/output.h              | 19 ++++++++++++++-----
13 src/w32/compat/posixfcn.c |  2 ++
14 2 files changed, 16 insertions(+), 5 deletions(-)
15
16diff --git a/src/output.h b/src/output.h
17index a506505..d3ce6b7 100644
18--- a/src/output.h
19+++ b/src/output.h
20@@ -67,14 +67,21 @@ void output_dump (struct output *out);
21
22 # ifdef WINDOWS32
23 /* For emulations in w32/compat/posixfcn.c.  */
24-#  define F_GETFD 1
25-#  define F_SETLKW 2
26+#  ifndef F_GETFD
27+#   define F_GETFD 1
28+#  endif
29+#  ifndef F_SETLKW
30+#   define F_SETLKW 2
31+#  endif
32 /* Implementation note: None of the values of l_type below can be zero
33    -- they are compared with a static instance of the struct, so zero
34    means unknown/invalid, see w32/compat/posixfcn.c. */
35-#  define F_WRLCK 1
36-#  define F_UNLCK 2
37-
38+#  ifndef F_WRLCK
39+#   define F_WRLCK 1
40+#  endif
41+#  ifndef F_UNLCK
42+#   define F_UNLCK 2
43+#  endif
44 struct flock
45   {
46     short l_type;
47@@ -89,7 +96,9 @@ struct flock
48 typedef intptr_t sync_handle_t;
49
50 /* Public functions emulated/provided in posixfcn.c.  */
51+#  ifndef HAVE_GNULIB_FCNTL
52 int fcntl (intptr_t fd, int cmd, ...);
53+#  endif
54 intptr_t create_mutex (void);
55 int same_stream (FILE *f1, FILE *f2);
56
57diff --git a/src/w32/compat/posixfcn.c b/src/w32/compat/posixfcn.c
58index 975dfb7..d337b9c 100644
59--- a/src/w32/compat/posixfcn.c
60+++ b/src/w32/compat/posixfcn.c
61@@ -29,6 +29,7 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
62 #ifndef NO_OUTPUT_SYNC
63 /* Support for OUTPUT_SYNC and related functionality.  */
64
65+#ifndef HAVE_GNULIB_FCNTL
66 /* Emulation of fcntl that supports only F_GETFD and F_SETLKW.  */
67 int
68 fcntl (intptr_t fd, int cmd, ...)
69@@ -142,6 +143,7 @@ fcntl (intptr_t fd, int cmd, ...)
70         return -1;
71     }
72 }
73+#endif /* GNULIB_TEST_FCNTL */
74
75 static intptr_t mutex_handle = -1;
76
77--
782.17.1
79
80