libc.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef ARK_SYS_LIBC_H
  2. #define ARK_SYS_LIBC_H
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <stdint.h>
  7. #include <stdbool.h>
  8. #include <unistd.h>
  9. #include <fcntl.h>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include <sys/ioctl.h>
  13. #include <sys/mman.h>
  14. #include <sys/socket.h>
  15. #include <sys/un.h>
  16. #include <errno.h>
  17. #include <time.h>
  18. #include <signal.h>
  19. #include <spawn.h>
  20. #include <sys/wait.h>
  21. #include <sys/mount.h>
  22. #include <dirent.h>
  23. #include <pthread.h>
  24. #include <poll.h>
  25. #include <sys/epoll.h>
  26. #include <math.h>
  27. // linux/input.h is not available in the musl static SDK.
  28. // Define the input_event struct and constants we need directly.
  29. struct ark_input_event {
  30. unsigned long sec;
  31. unsigned long usec;
  32. unsigned short type;
  33. unsigned short code;
  34. int value;
  35. };
  36. #define ABS_X 0x00
  37. #define ABS_Y 0x01
  38. // ── Wrappers for variadic/macro C symbols unavailable in Swift's static musl SDK ──
  39. /// Non-variadic wrapper for open(path, flags, mode).
  40. static inline int ark_open(const char *path, int flags, mode_t mode) {
  41. return open(path, flags, mode);
  42. }
  43. /// Two-arg open wrapper (no mode).
  44. static inline int ark_open2(const char *path, int flags) {
  45. return open(path, flags);
  46. }
  47. /// Non-variadic wrapper for fcntl(fd, cmd).
  48. static inline int ark_fcntl(int fd, int cmd) {
  49. return fcntl(fd, cmd);
  50. }
  51. /// Non-variadic wrapper for fcntl(fd, cmd, arg).
  52. static inline int ark_fcntl_arg(int fd, int cmd, int arg) {
  53. return fcntl(fd, cmd, arg);
  54. }
  55. /// Wrapper to access errno (a macro in musl, invisible to Swift).
  56. static inline int ark_errno(void) {
  57. return errno;
  58. }
  59. /// Wrapper to set errno.
  60. static inline void ark_set_errno(int val) {
  61. errno = val;
  62. }
  63. /// Wrapper for read.
  64. static inline ssize_t ark_read(int fd, void *buf, size_t count) {
  65. return read(fd, buf, count);
  66. }
  67. /// Wrapper for write.
  68. static inline ssize_t ark_write(int fd, const void *buf, size_t count) {
  69. return write(fd, buf, count);
  70. }
  71. /// Wrapper for ioctl.
  72. static inline int ark_ioctl(int fd, unsigned long request, void *arg) {
  73. return ioctl(fd, (int)request, arg);
  74. }
  75. #endif // ARK_SYS_LIBC_H