posix.odin 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Raw bindings for most `POSIX` APIs.
  3. Targets glibc and musl compatibility.
  4. APIs that have been left out are due to not being useful,
  5. being fully replaced (and better) by other Odin packages,
  6. or when one of the targets hasn't implemented the API or option.
  7. The struct fields that are cross-platform are documented with `[PSX]`.
  8. Accessing these fields on one target should be the same on others.
  9. Other fields are implementation specific.
  10. The parts of POSIX that Windows implements are also supported here, but
  11. other symbols are undefined on Windows targets.
  12. Most macros have been reimplemented in Odin with inlined functions.
  13. Unimplemented headers:
  14. - aio.h
  15. - complex.h | See `core:c/libc` and our own complex types
  16. - cpio.h
  17. - ctype.h | See `core:c/libc` for most of it
  18. - ndbm.h
  19. - fenv.h
  20. - float.h
  21. - fmtmsg.h
  22. - ftw.h
  23. - semaphore.h | See `core:sync`
  24. - inttypes.h | See `core:c`
  25. - iso646.h | Impossible
  26. - math.h | See `core:c/libc`
  27. - mqueue.h | Targets don't seem to have implemented it
  28. - regex.h | See `core:text/regex`
  29. - search.h | Not useful in Odin
  30. - spawn.h | Use `fork`, `execve`, etc.
  31. - stdarg.h | See `core:c/libc`
  32. - stdint.h | See `core:c`
  33. - stropts.h
  34. - syslog.h
  35. - pthread.h | Only the actual threads API is bound, see `core:sync` for synchronization primitives
  36. - string.h | Most of this is not useful in Odin, only a select few symbols are bound
  37. - tar.h
  38. - tgmath.h
  39. - trace.h
  40. - wchar.h
  41. - wctype.h
  42. */
  43. package posix
  44. import "base:intrinsics"
  45. import "core:c"
  46. IS_SUPPORTED :: _IS_SUPPORTED
  47. result :: enum c.int {
  48. // Use `errno` and `strerror` for more information.
  49. FAIL = -1,
  50. // Operation succeeded.
  51. OK = 0,
  52. }
  53. FD :: distinct c.int
  54. @(private)
  55. log2 :: intrinsics.constant_log2
  56. when ODIN_OS == .Darwin && ODIN_ARCH == .amd64 {
  57. @(private)
  58. INODE_SUFFIX :: "$INODE64"
  59. } else {
  60. @(private)
  61. INODE_SUFFIX :: ""
  62. }