diff --git a/headers/posix/unistd.h b/headers/posix/unistd.h index 94fa05d71a..54fb22a30e 100644 --- a/headers/posix/unistd.h +++ b/headers/posix/unistd.h @@ -190,7 +190,23 @@ extern int symlinkat(const char *toPath, int fd, const char *symlinkPath); extern int ftruncate(int fd, off_t newSize); extern int truncate(const char *path, off_t newSize); +struct ioctl_args { + void* argument; + size_t size; +}; +int __ioctl(int fd, ulong cmd, struct ioctl_args args); +#ifndef __cplusplus extern int ioctl(int fd, unsigned long op, ...); +#ifndef _KERNEL_MODE +#define ioctl(a, b, c...) __ioctl(a, b, (struct ioctl_args){ c }) +#endif +#else +inline int +ioctl(int fd, unsigned long op, void* argument = NULL, size_t size = 0) +{ + return __ioctl(fd, op, (struct ioctl_args){ argument, size }); +} +#endif extern ssize_t read(int fd, void *buffer, size_t count); extern ssize_t read_pos(int fd, off_t pos, void *buffer, size_t count); diff --git a/src/system/libroot/posix/unistd/ioctl.c b/src/system/libroot/posix/unistd/ioctl.c index 3f733df137..7182e5bfbe 100644 --- a/src/system/libroot/posix/unistd/ioctl.c +++ b/src/system/libroot/posix/unistd/ioctl.c @@ -13,6 +13,14 @@ #include +int +__ioctl(int fd, ulong cmd, struct ioctl_args args) +{ + RETURN_AND_SET_ERRNO(_kern_ioctl(fd, cmd, args.argument, args.size)); +} + + +#undef ioctl int ioctl(int fd, ulong cmd, ...) {