1 /* 2 * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <unistd.h> 8 #include <syscalls.h> 9 #include <stdarg.h> 10 #include <errno.h> 11 12 13 #define RETURN_AND_SET_ERRNO(err) \ 14 if (err < 0) { \ 15 errno = err; \ 16 return -1; \ 17 } \ 18 return err; 19 20 21 int 22 ioctl(int fd, ulong cmd, ...) 23 { 24 va_list args; 25 void* argument; 26 size_t size; 27 int status; 28 29 va_start(args, cmd); 30 argument = va_arg(args, void*); 31 size = va_arg(args, size_t); 32 va_end(args); 33 34 status = _kern_ioctl(fd, cmd, argument, size); 35 36 RETURN_AND_SET_ERRNO(status) 37 } 38