diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt index 0beb030f..83015d48 100644 --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -20,6 +20,7 @@ set(SOURCES src/sys/stat.cpp src/sys/mman.cpp src/sys/wait.cpp + src/sys/ioctl.cpp ) if(${LUNA_ARCH} STREQUAL "x86_64") diff --git a/libc/include/sys/ioctl.h b/libc/include/sys/ioctl.h new file mode 100644 index 00000000..6763b435 --- /dev/null +++ b/libc/include/sys/ioctl.h @@ -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 diff --git a/libc/src/sys/ioctl.cpp b/libc/src/sys/ioctl.cpp new file mode 100644 index 00000000..5163bfc6 --- /dev/null +++ b/libc/src/sys/ioctl.cpp @@ -0,0 +1,22 @@ +#include +#include +#include +#include +#include + +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); + } +}