1 // Copyright 2016 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #pragma once 6 7 #include <zircon/compiler.h> 8 #include <stddef.h> 9 #include <stdio.h> 10 #include <sys/types.h> 11 12 __BEGIN_CDECLS 13 14 extern ssize_t fdio_ioctl(int fd, int op, const void* in_buf, size_t in_len, void* out_buf, size_t out_len); 15 16 #define IOCTL_WRAPPER(name, op) \ 17 static inline ssize_t name(int fd) { \ 18 return fdio_ioctl(fd, op, NULL, 0, NULL, 0); \ 19 } 20 21 #define IOCTL_WRAPPER_IN(name, op, type) \ 22 static inline ssize_t name(int fd, const type* in) { \ 23 return fdio_ioctl(fd, op, in, in ? sizeof(*in) : 0, NULL, 0); \ 24 } 25 26 #define IOCTL_WRAPPER_VARIN(name, op, type) \ 27 static inline ssize_t name(int fd, const type* in, size_t in_len) { \ 28 return fdio_ioctl(fd, op, in, in_len, NULL, 0); \ 29 } 30 31 #define IOCTL_WRAPPER_OUT(name, op, type) \ 32 static inline ssize_t name(int fd, type* out) { \ 33 return fdio_ioctl(fd, op, NULL, 0, out, out ? sizeof(*out) : 0); \ 34 } 35 36 #define IOCTL_WRAPPER_VAROUT(name, op, type) \ 37 static inline ssize_t name(int fd, type* out, size_t out_len) { \ 38 return fdio_ioctl(fd, op, NULL, 0, out, out_len); \ 39 } 40 41 #define IOCTL_WRAPPER_INOUT(name, op, intype, outtype) \ 42 static inline ssize_t name(int fd, const intype* in, outtype* out) { \ 43 return fdio_ioctl(fd, op, in, in ? sizeof(*in) : 0, out, out ? sizeof(*out) : 0); \ 44 } 45 46 #define IOCTL_WRAPPER_VARIN_OUT(name, op, intype, outtype) \ 47 static inline ssize_t name(int fd, const intype* in, size_t in_len, outtype* out) { \ 48 return fdio_ioctl(fd, op, in, in_len, out, out ? sizeof(*out) : 0); \ 49 } 50 51 #define IOCTL_WRAPPER_IN_VAROUT(name, op, intype, outtype) \ 52 static inline ssize_t name(int fd, const intype* in, outtype* out, size_t out_len) { \ 53 return fdio_ioctl(fd, op, in, in ? sizeof(*in) : 0, out, out_len); \ 54 } 55 56 #define IOCTL_WRAPPER_VARIN_VAROUT(name, op, intype, outtype) \ 57 static inline ssize_t name(int fd, const intype* in, size_t in_len, outtype* out, size_t out_len) { \ 58 return fdio_ioctl(fd, op, in, in_len, out, out_len); \ 59 } 60 61 __END_CDECLS 62