diff --git a/src/function.c b/src/function.c index 3b355a33..a705c8a0 100644 --- a/src/function.c +++ b/src/function.c @@ -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) diff --git a/src/os.h b/src/os.h index cce9d34a..888e1163 100644 --- 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 /* Needed for HANDLE */ +HANDLE get_handle_for_fd (int); +#endif diff --git a/src/w32/compat/posixfcn.c b/src/w32/compat/posixfcn.c index 72fe5f2e..7ad0fe0b 100644 --- a/src/w32/compat/posixfcn.c +++ b/src/w32/compat/posixfcn.c @@ -22,6 +22,7 @@ this program. If not, see . */ #include #include #include +#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) diff --git a/src/w32/subproc/sub_proc.c b/src/w32/subproc/sub_proc.c index 8cfa533c..f5d7fe03 100644 --- a/src/w32/subproc/sub_proc.c +++ b/src/w32/subproc/sub_proc.c @@ -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(), diff --git a/src/w32/w32os.c b/src/w32/w32os.c index 9d6d1841..180f421b 100644 --- a/src/w32/w32os.c +++ b/src/w32/w32os.c @@ -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; +}