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 #include <errno_private.h> 13 14 15 #define RETURN_AND_SET_ERRNO(err) \ 16 if (err < 0) { \ 17 __set_errno(err); \ 18 return -1; \ 19 } \ 20 return err; 21 22 23 int 24 ioctl(int fd, ulong cmd, ...) 25 { 26 va_list args; 27 void* argument; 28 size_t size; 29 int status; 30 31 va_start(args, cmd); 32 argument = va_arg(args, void*); 33 size = va_arg(args, size_t); 34 va_end(args); 35 36 status = _kern_ioctl(fd, cmd, argument, size); 37 38 RETURN_AND_SET_ERRNO(status) 39 } 40