2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_CALLS_IOCTL_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_CALLS_IOCTL_H_
|
2021-03-01 07:42:35 +00:00
|
|
|
#include "libc/macros.internal.h"
|
2021-08-12 07:42:14 +00:00
|
|
|
#include "libc/sysv/consts/fio.h"
|
2021-06-24 17:53:27 +00:00
|
|
|
#include "libc/sysv/consts/sio.h"
|
2021-08-12 07:42:14 +00:00
|
|
|
#include "libc/sysv/consts/termios.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
2020-11-25 16:19:00 +00:00
|
|
|
│ cosmopolitan § system calls » ioctl ─╬─│┼
|
2020-06-15 14:18:57 +00:00
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
|
|
|
|
2021-08-12 07:42:14 +00:00
|
|
|
int ioctl(int, uint64_t, ...);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
/*───────────────────────────────────────────────────────────────────────────│─╗
|
2020-11-25 16:19:00 +00:00
|
|
|
│ cosmopolitan § system calls » ioctl » undiamonding (size optimization) ─╬─│┼
|
2020-06-15 14:18:57 +00:00
|
|
|
╚────────────────────────────────────────────────────────────────────────────│*/
|
2020-06-21 07:10:11 +00:00
|
|
|
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-08-12 07:42:14 +00:00
|
|
|
#define ioctl(FD, REQUEST, ...) \
|
|
|
|
__IOCTL_DISPATCH(__EQUIVALENT, ioctl_default(FD, REQUEST, ##__VA_ARGS__), \
|
|
|
|
FD, REQUEST, ##__VA_ARGS__)
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-03-01 07:42:35 +00:00
|
|
|
#define __EQUIVALENT(X, Y) (__builtin_constant_p((X) == (Y)) && ((X) == (Y)))
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-08-12 07:42:14 +00:00
|
|
|
#define __IOCTL_DISPATCH(CMP, DEFAULT, FD, REQUEST, ...) \
|
|
|
|
({ \
|
|
|
|
int ReZ; \
|
|
|
|
if (CMP(REQUEST, TIOCGWINSZ)) { \
|
|
|
|
ReZ = ioctl_tiocgwinsz(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, TIOCSWINSZ)) { \
|
|
|
|
ReZ = ioctl_tiocswinsz(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, TCGETS)) { \
|
|
|
|
ReZ = ioctl_tcgets(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, TCSETS)) { \
|
|
|
|
ReZ = ioctl_tcsets(FD, REQUEST, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, TCSETSW)) { \
|
|
|
|
ReZ = ioctl_tcsets(FD, REQUEST, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, TCSETSF)) { \
|
|
|
|
ReZ = ioctl_tcsets(FD, REQUEST, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, SIOCGIFCONF)) { \
|
|
|
|
ReZ = ioctl_siocgifconf(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, SIOCGIFADDR)) { \
|
|
|
|
ReZ = ioctl_siocgifaddr(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, SIOCGIFNETMASK)) { \
|
|
|
|
ReZ = ioctl_siocgifnetmask(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, SIOCGIFBRDADDR)) { \
|
|
|
|
ReZ = ioctl_siocgifbrdaddr(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, SIOCGIFDSTADDR)) { \
|
|
|
|
ReZ = ioctl_siocgifdstaddr(FD, __VA_ARGS__); \
|
|
|
|
} else if (CMP(REQUEST, SIOCGIFFLAGS)) { \
|
|
|
|
ReZ = ioctl_siocgifflags(FD, __VA_ARGS__); \
|
2021-08-18 21:21:30 +00:00
|
|
|
} else if (CMP(REQUEST, FIONBIO)) { \
|
|
|
|
ReZ = ioctl_default(FD, REQUEST, __VA_ARGS__); \
|
2021-08-12 07:42:14 +00:00
|
|
|
} else if (CMP(REQUEST, FIOCLEX)) { \
|
2021-08-18 21:21:30 +00:00
|
|
|
ReZ = ioctl_fioclex(FD, REQUEST); \
|
2021-08-12 07:42:14 +00:00
|
|
|
} else if (CMP(REQUEST, FIONCLEX)) { \
|
2021-08-18 21:21:30 +00:00
|
|
|
ReZ = ioctl_fioclex(FD, REQUEST); \
|
2021-08-12 07:42:14 +00:00
|
|
|
} else { \
|
|
|
|
ReZ = DEFAULT; \
|
|
|
|
} \
|
|
|
|
ReZ; \
|
|
|
|
})
|
2021-06-24 17:53:27 +00:00
|
|
|
|
2021-02-06 08:24:35 +00:00
|
|
|
int ioctl_tcgets(int, void *);
|
|
|
|
int ioctl_tcgets_nt(int, void *);
|
|
|
|
int ioctl_tcsets(int, uint64_t, void *);
|
|
|
|
int ioctl_tcsets_nt(int, uint64_t, void *);
|
|
|
|
int ioctl_tiocgwinsz(int, void *);
|
|
|
|
int ioctl_tiocgwinsz_nt(int, void *);
|
|
|
|
int ioctl_tiocswinsz(int, void *);
|
|
|
|
int ioctl_tiocswinsz_nt(int, void *);
|
2021-06-24 17:53:27 +00:00
|
|
|
int ioctl_siocgifconf(int, void *);
|
|
|
|
int ioctl_siocgifaddr(int, void *);
|
|
|
|
int ioctl_siocgifdstaddr(int, void *);
|
|
|
|
int ioctl_siocgifnetmask(int, void *);
|
|
|
|
int ioctl_siocgifbrdaddr(int, void *);
|
|
|
|
int ioctl_siocgifflags(int, void *);
|
2021-02-06 08:24:35 +00:00
|
|
|
int ioctl_default(int, uint64_t, void *);
|
2021-08-18 21:21:30 +00:00
|
|
|
int ioctl_fioclex(int, int);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2020-06-21 07:10:11 +00:00
|
|
|
#endif /* GNUC && !ANSI */
|
2020-06-15 14:18:57 +00:00
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_CALLS_IOCTL_H_ */
|