]> git.ipfire.org Git - thirdparty/make.git/commitdiff
Fix GCC compile warning for "bad-function-cast" on Windows
authorTorbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Fri, 9 Jun 2023 19:00:32 +0000 (21:00 +0200)
committerPaul Smith <psmith@gnu.org>
Tue, 4 Jul 2023 18:26:58 +0000 (14:26 -0400)
Trick the compiler by hiding the cast in a function call.

* src/os.h: Declare the new function.
* src/w32/w32os.c (get_handle_for_fd): Convert and cast a file
descriptor into a Windows HANDLE.
(check_io_state): Call the new function rather than casting.
(osync_release): Ditto.
(fd_inherit): Ditto.
(fd_noinherit): Ditto.
* src/function.c (windows32_openpipe): Ditto.
* src/w32/compat/posixfcn.c (isatty): Ditto.
* src/w32/subproc/sub_proc.c (process_easy): Ditto.

src/function.c
src/os.h
src/w32/compat/posixfcn.c
src/w32/subproc/sub_proc.c
src/w32/w32os.c

index 3b355a33ab9b6254f015afb6d7fb707140efb1a6..a705c8a0c4bfd5233febdb928b994ea45b4e92fa 100644 (file)
@@ -1674,7 +1674,7 @@ windows32_openpipe (int *pipedes, int errfd, pid_t *pid_p, char **command_argv,
           return -1;
         }
     }
-  tmpErr = (HANDLE)_get_osfhandle (errfd);
+  tmpErr = get_handle_for_fd (errfd);
   if (DuplicateHandle (GetCurrentProcess (), tmpErr,
                        GetCurrentProcess (), &hErr,
                        0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE)
index cce9d34ab7b6156a53160a675a34c1d9e21ccd74..888e11637eee693e3b93f2fde0a4d898e2b04b05 100644 (file)
--- a/src/os.h
+++ b/src/os.h
@@ -156,3 +156,8 @@ void osync_release (void);
 #else
 int get_bad_stdin (void);
 #endif
+
+#if MK_OS_W32
+#include <windows.h> /* Needed for HANDLE */
+HANDLE get_handle_for_fd (int);
+#endif
index 72fe5f2eb1872829c73fe89b30dbbcd602fae55d..7ad0fe0b85ca56e9282812e44a618759a6f4e3ef 100644 (file)
@@ -22,6 +22,7 @@ this program.  If not, see <https://www.gnu.org/licenses/>.  */
 #include <stdarg.h>
 #include <errno.h>
 #include <windows.h>
+#include "os.h"
 
 #include "dlfcn.h"
 
@@ -125,7 +126,7 @@ dlclose (void *handle)
 int
 isatty (int fd)
 {
-  HANDLE fh = (HANDLE) _get_osfhandle (fd);
+  HANDLE fh = get_handle_for_fd (fd);
   DWORD con_mode;
 
   if (fh == INVALID_HANDLE_VALUE)
index 8cfa533cfebfc05eb8bf37129918bd6e3a2905e1..f5d7fe0367269278183f46d708f7ba1f7cfb89df 100644 (file)
@@ -1481,7 +1481,7 @@ process_easy(
     }
   }
   if (outfd >= 0)
-    tmpOut = (HANDLE)_get_osfhandle (outfd);
+    tmpOut = get_handle_for_fd (outfd);
   else
     tmpOut = GetStdHandle (STD_OUTPUT_HANDLE);
   if (DuplicateHandle(GetCurrentProcess(),
@@ -1511,7 +1511,7 @@ process_easy(
     }
   }
   if (errfd >= 0)
-    tmpErr = (HANDLE)_get_osfhandle (errfd);
+    tmpErr = get_handle_for_fd (errfd);
   else
     tmpErr = GetStdHandle(STD_ERROR_HANDLE);
   if (DuplicateHandle(GetCurrentProcess(),
index 9d6d184115bf4f71589e5c714e57e860a6203bd3..180f421bdee879ce479f4b8913c733da0f3828b4 100644 (file)
@@ -43,10 +43,10 @@ check_io_state ()
 
   /* Could have used GetHandleInformation, but that isn't supported
      on Windows 9X.  */
-  outfd = (HANDLE)_get_osfhandle (fileno (stdout));
-  errfd = (HANDLE)_get_osfhandle (fileno (stderr));
+  outfd = get_handle_for_fd (fileno (stdout));
+  errfd = get_handle_for_fd (fileno (stderr));
 
-  if ((HANDLE)_get_osfhandle (fileno (stdin)) != INVALID_HANDLE_VALUE)
+  if (get_handle_for_fd (fileno (stdin)) != INVALID_HANDLE_VALUE)
     state |= IO_STDIN_OK;
   if (outfd != INVALID_HANDLE_VALUE)
     state |= IO_STDOUT_OK;
@@ -497,21 +497,31 @@ osync_release ()
 void
 fd_inherit(int fd)
 {
-  HANDLE fh = (HANDLE)_get_osfhandle(fd);
+  HANDLE fh = get_handle_for_fd (fd);
 
   if (fh && fh != INVALID_HANDLE_VALUE)
-        SetHandleInformation(fh, HANDLE_FLAG_INHERIT, 1);
+        SetHandleInformation (fh, HANDLE_FLAG_INHERIT, 1);
 }
 
 void
 fd_noinherit(int fd)
 {
-  HANDLE fh = (HANDLE)_get_osfhandle(fd);
+  HANDLE fh = get_handle_for_fd (fd);
 
   if (fh && fh != INVALID_HANDLE_VALUE)
-        SetHandleInformation(fh, HANDLE_FLAG_INHERIT, 0);
+        SetHandleInformation (fh, HANDLE_FLAG_INHERIT, 0);
 }
 
 void
 fd_set_append (int fd UNUSED)
 {}
+
+
+HANDLE
+get_handle_for_fd (int fd)
+{
+  /* This funcion call is needed to get around the "bad-function-cast"-warning
+     emitted by GCC when casting and assigning in the same statement.  */
+  intptr_t fh = _get_osfhandle (fd);
+  return (HANDLE) fh;
+}