|
Packit Service |
a2ae7a |
/* ioctl.c --- wrappers for Windows ioctl function
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Copyright (C) 2008-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
a2ae7a |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2ae7a |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
a2ae7a |
(at your option) any later version.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2ae7a |
GNU General Public License for more details.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2ae7a |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Written by Paolo Bonzini */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <config.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <sys/ioctl.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <stdarg.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#if HAVE_IOCTL
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Provide a wrapper with the POSIX prototype. */
|
|
Packit Service |
a2ae7a |
# undef ioctl
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
rpl_ioctl (int fd, int request, ... /* {void *,char *} arg */)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
void *buf;
|
|
Packit Service |
a2ae7a |
va_list args;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
va_start (args, request);
|
|
Packit Service |
a2ae7a |
buf = va_arg (args, void *);
|
|
Packit Service |
a2ae7a |
va_end (args);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Cast 'request' so that when the system's ioctl function takes a 64-bit
|
|
Packit Service |
a2ae7a |
request argument, the value gets zero-extended, not sign-extended. */
|
|
Packit Service |
a2ae7a |
return ioctl (fd, (unsigned int) request, buf);
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#else /* mingw */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
# include <errno.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Get HANDLE. */
|
|
Packit Service |
a2ae7a |
# define WIN32_LEAN_AND_MEAN
|
|
Packit Service |
a2ae7a |
# include <windows.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
# include "fd-hook.h"
|
|
Packit Service |
a2ae7a |
/* Get _get_osfhandle. */
|
|
Packit Service |
a2ae7a |
# if GNULIB_MSVC_NOTHROW
|
|
Packit Service |
a2ae7a |
# include "msvc-nothrow.h"
|
|
Packit Service |
a2ae7a |
# else
|
|
Packit Service |
a2ae7a |
# include <io.h>
|
|
Packit Service |
a2ae7a |
# endif
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
static int
|
|
Packit Service |
a2ae7a |
primary_ioctl (int fd, int request, void *arg)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
/* We don't support FIONBIO on pipes here. If you want to make pipe
|
|
Packit Service |
a2ae7a |
fds non-blocking, use the gnulib 'nonblocking' module, until
|
|
Packit Service |
a2ae7a |
gnulib implements fcntl F_GETFL / F_SETFL with O_NONBLOCK. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
if ((HANDLE) _get_osfhandle (fd) != INVALID_HANDLE_VALUE)
|
|
Packit Service |
a2ae7a |
errno = ENOSYS;
|
|
Packit Service |
a2ae7a |
else
|
|
Packit Service |
a2ae7a |
errno = EBADF;
|
|
Packit Service |
a2ae7a |
return -1;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
ioctl (int fd, int request, ... /* {void *,char *} arg */)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
void *arg;
|
|
Packit Service |
a2ae7a |
va_list args;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
va_start (args, request);
|
|
Packit Service |
a2ae7a |
arg = va_arg (args, void *);
|
|
Packit Service |
a2ae7a |
va_end (args);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
# if WINDOWS_SOCKETS
|
|
Packit Service |
a2ae7a |
return execute_all_ioctl_hooks (primary_ioctl, fd, request, arg);
|
|
Packit Service |
a2ae7a |
# else
|
|
Packit Service |
a2ae7a |
return primary_ioctl (fd, request, arg);
|
|
Packit Service |
a2ae7a |
# endif
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#endif
|