| Updated: October 28, 2024 |
Register an I/O control handler
#include <ioctl.h>
int _register_ioctl_handler( _ioctl_handler_fct *function,
int command_min,
int command_max );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The _register_ioctl_handler() function registers an I/O control command handler.
The handler function prototype is:
typedef int (*_ioctl_handler_fct)( int fd,
int request,
va_list arg );
The arguments are:
Like ioctl(), this handler function returns a value based on the request, or -1 if an error occurs (errno is set).
static int my_ioctl_handler(const int fd, const int cmd, va_list vl)
{
/* fill in details */
errno = ENOTSUP;
return -1;
}
/* Automatic registration of the ioctl handler with libc */
static void __attribute__ ((constructor)) my_ioctl_handler_init()
{
int ret = _register_ioctl_handler(my_ioctl_handler, CMD1, CMDX);
if (ret) {
fprintf(stderr, "failed to register my ioctl handler (%d)\n", ret);
abort();
}
}
/* Automatic unregistration of the ioctl handler with libc */
static void __attribute__ ((destructor)) my_ioctl_handler_uninit()
{
_unregister_ioctl_handler(my_ioctl_handler);
}
| Safety: | |
|---|---|
| Cancellation point | Yes |
| Interrupt handler | Yes |
| Signal handler | Yes |
| Thread | Yes |