posix.odin 1.6 KB

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