From 8d95dd6ea7aad938b37d37e60496768a0e3a1c2f Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 11 Aug 2020 21:25:45 +0200 Subject: [PATCH] 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. --- ChangeLog | 10 ++++++++++ lib/binary-io.h | 2 +- lib/fcntl.c | 4 ++-- tests/test-cloexec.c | 10 +++++----- tests/test-dup-safer.c | 10 +++++----- tests/test-dup2.c | 10 +++++----- tests/test-fcntl.c | 10 +++++----- 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index cd1fdc96b8..a19ee8b59c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2020-08-11 Bruno Haible + + 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. + 2020-08-11 Bruno Haible execute, spawn-pipe: Use _spawnvpe, not spawnvpe. diff --git a/lib/binary-io.h b/lib/binary-io.h index 477b4bf4dd..d17af7c380 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 6b9927ec4e..8cd1531527 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 7c992df012..650634088a 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 0635541bc3..b1edf14347 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 7f7b1c487e..c4159ce90d 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 d5e7e6313c..1f5565a029 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)); -- 2.39.5