libc: Add ioctl() syscall wrapper

This commit is contained in:
apio 2023-04-09 11:24:13 +02:00
parent fee33e7a14
commit 3e5957f9fc
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 41 additions and 0 deletions

View File

@ -20,6 +20,7 @@ set(SOURCES
src/sys/stat.cpp src/sys/stat.cpp
src/sys/mman.cpp src/sys/mman.cpp
src/sys/wait.cpp src/sys/wait.cpp
src/sys/ioctl.cpp
) )
if(${LUNA_ARCH} STREQUAL "x86_64") if(${LUNA_ARCH} STREQUAL "x86_64")

18
libc/include/sys/ioctl.h Normal file
View File

@ -0,0 +1,18 @@
/* sys/ioctl.h: IO device control. */
#ifndef _SYS_IOCTL_H
#define _SYS_IOCTL_H
#ifdef __cplusplus
extern "C"
{
#endif
/* Perform an IO control operation on a device. */
int ioctl(int fd, int request, ...);
#ifdef __cplusplus
}
#endif
#endif

22
libc/src/sys/ioctl.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <bits/errno-return.h>
#include <stdarg.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <unistd.h>
extern "C"
{
int ioctl(int fd, int request, ...)
{
va_list ap;
va_start(ap, request);
void* arg = va_arg(ap, void*);
long rc = syscall(SYS_ioctl, fd, request, arg);
va_end(ap);
__errno_return(rc, int);
}
}