cosmopolitan/libc/calls/ioctl.h

50 lines
2.7 KiB
C
Raw Normal View History

2020-06-15 14:18:57 +00:00
#ifndef COSMOPOLITAN_LIBC_CALLS_IOCTL_H_
#define COSMOPOLITAN_LIBC_CALLS_IOCTL_H_
#include "libc/macros.h"
#include "libc/sysv/consts/termios.h"
2020-06-15 14:18:57 +00:00
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » ioctl
2020-06-15 14:18:57 +00:00
*/
int ioctl(int, uint64_t, void *);
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § system calls » ioctl » undiamonding (size optimization)
2020-06-15 14:18:57 +00:00
*/
#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
2020-06-15 14:18:57 +00:00
#define ioctl(FD, REQUEST, MEMORY) ioctl_dispatch(FD, REQUEST, MEMORY)
2020-06-15 14:18:57 +00:00
#define __IOCTL_DISPATCH(CMP, FD, REQUEST, MEMORY) \
do { \
if (CMP(request, TIOCGWINSZ)) return ioctl_tiocgwinsz(FD, MEMORY); \
if (CMP(request, TIOCSWINSZ)) return ioctl_tiocswinsz(FD, MEMORY); \
if (CMP(request, TCGETS)) return ioctl_tcgets(FD, MEMORY); \
if (CMP(request, TCSETS)) return ioctl_tcsets(FD, REQUEST, MEMORY); \
if (CMP(request, TCSETSW)) return ioctl_tcsets(FD, REQUEST, MEMORY); \
if (CMP(request, TCSETSF)) return ioctl_tcsets(FD, REQUEST, MEMORY); \
2020-06-15 14:18:57 +00:00
} while (0)
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 *);
int ioctl_default(int, uint64_t, void *);
forceinline int ioctl_dispatch(int fd, uint64_t request, void *memory) {
2020-06-15 14:18:57 +00:00
__IOCTL_DISPATCH(EQUIVALENT, fd, request, memory);
return ioctl_default(fd, request, memory);
2020-06-15 14:18:57 +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_ */