mirror of
https://github.com/mirror/make.git
synced 2024-12-27 13:20:34 +08:00
Fix GCC compile warning for "bad-function-cast" on Windows
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.
This commit is contained in:
parent
8d76fb8778
commit
1000374759
@ -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)
|
||||
|
5
src/os.h
5
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
|
||||
|
@ -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)
|
||||
|
@ -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(),
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user