[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fcntl: On native Windows, use _setmode, not setmode
From: |
Bruno Haible |
Subject: |
fcntl: On native Windows, use _setmode, not setmode |
Date: |
Tue, 11 Aug 2020 21:28:46 +0200 |
User-agent: |
KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; ) |
> With clang, on native Windows, the function 'chsize' is not present any more.
> This matches the deprecation of this spelling by Microsoft
> <https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-chsize>.
Similarly for the 'setmode' function:
<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-setmode>
lib/binary-io.h already uses _setmode. Fine. But that's not all.
2020-08-11 Bruno Haible <bruno@clisp.org>
fcntl: On native Windows, use _setmode, not setmode.
* lib/fcntl.c (dupfd): Use _setmode, not setmode.
* lib/binary-io.h: Update comment.
* tests/test-cloexec.c: Call set_binary_mode, not setmode.
* tests/test-dup2.c: Likewise.
* tests/test-dup-safer.c: Likewise.
* tests/test-fcntl.c: Likewise.
diff --git a/lib/binary-io.h b/lib/binary-io.h
index 477b4bf..d17af7c 100644
--- a/lib/binary-io.h
+++ b/lib/binary-io.h
@@ -56,7 +56,7 @@ __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED)
/* Set FD's mode to MODE, which should be either O_TEXT or O_BINARY.
Return the old mode if successful, -1 (setting errno) on failure.
Ordinarily this function would be called 'setmode', since that is
- its name on MS-Windows, but it is called 'set_binary_mode' here
+ its old name on MS-Windows, but it is called 'set_binary_mode' here
to avoid colliding with a BSD function of another name. */
#if defined __DJGPP__ || defined __EMX__
diff --git a/lib/fcntl.c b/lib/fcntl.c
index 6b9927e..8cd1531 100644
--- a/lib/fcntl.c
+++ b/lib/fcntl.c
@@ -70,14 +70,14 @@ dupfd (int oldfd, int newfd, int flags)
return -1;
}
if (old_handle == INVALID_HANDLE_VALUE
- || (mode = setmode (oldfd, O_BINARY)) == -1)
+ || (mode = _setmode (oldfd, O_BINARY)) == -1)
{
/* oldfd is not open, or is an unassigned standard file
descriptor. */
errno = EBADF;
return -1;
}
- setmode (oldfd, mode);
+ _setmode (oldfd, mode);
flags |= mode;
for (;;)
diff --git a/tests/test-cloexec.c b/tests/test-cloexec.c
index 7c992df..6506340 100644
--- a/tests/test-cloexec.c
+++ b/tests/test-cloexec.c
@@ -62,7 +62,7 @@ is_inheritable (int fd)
}
#if !O_BINARY
-# define setmode(f,m) zero ()
+# define set_binary_mode(f,m) zero ()
static int zero (void) { return 0; }
#endif
@@ -71,8 +71,8 @@ static int zero (void) { return 0; }
static int
is_mode (int fd, int mode)
{
- int value = setmode (fd, O_BINARY);
- setmode (fd, value);
+ int value = set_binary_mode (fd, O_BINARY);
+ set_binary_mode (fd, value);
return mode == value;
}
@@ -107,13 +107,13 @@ main (void)
/* On systems that distinguish between text and binary mode,
dup_cloexec reuses the mode of the source. */
- setmode (fd, O_BINARY);
+ set_binary_mode (fd, O_BINARY);
ASSERT (is_mode (fd, O_BINARY));
fd2 = dup_cloexec (fd);
ASSERT (fd < fd2);
ASSERT (is_mode (fd2, O_BINARY));
ASSERT (close (fd2) == 0);
- setmode (fd, O_TEXT);
+ set_binary_mode (fd, O_TEXT);
ASSERT (is_mode (fd, O_TEXT));
fd2 = dup_cloexec (fd);
ASSERT (fd < fd2);
diff --git a/tests/test-dup-safer.c b/tests/test-dup-safer.c
index 0635541..b1edf14 100644
--- a/tests/test-dup-safer.c
+++ b/tests/test-dup-safer.c
@@ -42,7 +42,7 @@
#endif
#if !O_BINARY
-# define setmode(f,m) zero ()
+# define set_binary_mode(f,m) zero ()
static int zero (void) { return 0; }
#endif
@@ -100,8 +100,8 @@ is_inheritable (int fd)
static bool
is_mode (int fd, int mode)
{
- int value = setmode (fd, O_BINARY);
- setmode (fd, value);
+ int value = set_binary_mode (fd, O_BINARY);
+ set_binary_mode (fd, value);
return mode == value;
}
@@ -143,14 +143,14 @@ main (void)
ASSERT (errno == EBADF);
/* Preserve text vs. binary. */
- setmode (fd, O_BINARY);
+ set_binary_mode (fd, O_BINARY);
ASSERT (dup (fd) == fd + 1);
ASSERT (is_open (fd + 1));
ASSERT (is_inheritable (fd + 1));
ASSERT (is_mode (fd + 1, O_BINARY));
ASSERT (close (fd + 1) == 0);
- setmode (fd, O_TEXT);
+ set_binary_mode (fd, O_TEXT);
ASSERT (dup (fd) == fd + 1);
ASSERT (is_open (fd + 1));
ASSERT (is_inheritable (fd + 1));
diff --git a/tests/test-dup2.c b/tests/test-dup2.c
index 7f7b1c4..c4159ce 100644
--- a/tests/test-dup2.c
+++ b/tests/test-dup2.c
@@ -92,7 +92,7 @@ is_inheritable (int fd)
#endif /* GNULIB_TEST_CLOEXEC */
#if !O_BINARY
-# define setmode(f,m) zero ()
+# define set_binary_mode(f,m) zero ()
static int zero (void) { return 0; }
#endif
@@ -101,8 +101,8 @@ static int zero (void) { return 0; }
static int
is_mode (int fd, int mode)
{
- int value = setmode (fd, O_BINARY);
- setmode (fd, value);
+ int value = set_binary_mode (fd, O_BINARY);
+ set_binary_mode (fd, value);
return mode == value;
}
@@ -203,11 +203,11 @@ main (void)
/* On systems that distinguish between text and binary mode, dup2
reuses the mode of the source. */
- setmode (fd, O_BINARY);
+ set_binary_mode (fd, O_BINARY);
ASSERT (is_mode (fd, O_BINARY));
ASSERT (dup2 (fd, fd + 1) == fd + 1);
ASSERT (is_mode (fd + 1, O_BINARY));
- setmode (fd, O_TEXT);
+ set_binary_mode (fd, O_TEXT);
ASSERT (is_mode (fd, O_TEXT));
ASSERT (dup2 (fd, fd + 1) == fd + 1);
ASSERT (is_mode (fd + 1, O_TEXT));
diff --git a/tests/test-fcntl.c b/tests/test-fcntl.c
index d5e7e63..1f5565a 100644
--- a/tests/test-fcntl.c
+++ b/tests/test-fcntl.c
@@ -46,7 +46,7 @@ SIGNATURE_CHECK (fcntl, int, (int, int, ...));
#include "macros.h"
#if !O_BINARY
-# define setmode(f,m) zero ()
+# define set_binary_mode(f,m) zero ()
static int zero (void) { return 0; }
#endif
@@ -94,8 +94,8 @@ is_inheritable (int fd)
static bool
is_mode (int fd, int mode)
{
- int value = setmode (fd, O_BINARY);
- setmode (fd, value);
+ int value = set_binary_mode (fd, O_BINARY);
+ set_binary_mode (fd, value);
return mode == value;
}
@@ -271,7 +271,7 @@ main (void)
/* For F_DUPFD*, check for correct inheritance, as well as
preservation of text vs. binary. */
- setmode (fd, O_BINARY);
+ set_binary_mode (fd, O_BINARY);
ASSERT (is_open (fd));
ASSERT (!is_open (fd + 1));
ASSERT (!is_open (fd + 2));
@@ -297,7 +297,7 @@ main (void)
ASSERT (is_mode (fd + 2, O_BINARY));
ASSERT (close (fd) == 0);
- setmode (fd + 2, O_TEXT);
+ set_binary_mode (fd + 2, O_TEXT);
ASSERT (fcntl (fd + 2, F_DUPFD, fd + 1) == fd + 1);
ASSERT (!is_open (fd));
ASSERT (is_open (fd + 1));