stdlib_libc.odin 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #+build linux, windows, darwin, netbsd, openbsd, freebsd
  2. package posix
  3. import "base:intrinsics"
  4. import "core:c"
  5. import "core:c/libc"
  6. when ODIN_OS == .Windows {
  7. foreign import lib "system:libucrt.lib"
  8. } else when ODIN_OS == .Darwin {
  9. foreign import lib "system:System.framework"
  10. } else {
  11. foreign import lib "system:c"
  12. }
  13. // stdlib.h - standard library definitions
  14. atof :: libc.atof
  15. atoi :: libc.atoi
  16. atol :: libc.atol
  17. atoll :: libc.atoll
  18. strtod :: libc.strtod
  19. strtof :: libc.strtof
  20. strtol :: libc.strtol
  21. strtoll :: libc.strtoll
  22. strtoul :: libc.strtoul
  23. strtoull :: libc.strtoull
  24. rand :: libc.rand
  25. srand :: libc.srand
  26. calloc :: libc.calloc
  27. malloc :: libc.malloc
  28. realloc :: libc.realloc
  29. abort :: libc.abort
  30. atexit :: libc.atexit
  31. at_quick_exit :: libc.at_quick_exit
  32. exit :: libc.exit
  33. _Exit :: libc._Exit
  34. getenv :: libc.getenv
  35. quick_exit :: libc.quick_exit
  36. system :: libc.system
  37. bsearch :: libc.bsearch
  38. qsort :: libc.qsort
  39. abs :: libc.abs
  40. labs :: libc.labs
  41. llabs :: libc.llabs
  42. div :: libc.div
  43. ldiv :: libc.ldiv
  44. lldiv :: libc.lldiv
  45. mblen :: libc.mblen
  46. mbtowc :: libc.mbtowc
  47. wctomb :: libc.wctomb
  48. mbstowcs :: libc.mbstowcs
  49. wcstombs :: libc.wcstombs
  50. free :: #force_inline proc(ptr: $T) where intrinsics.type_is_pointer(T) || intrinsics.type_is_multi_pointer(T) || T == cstring {
  51. libc.free(rawptr(ptr))
  52. }
  53. foreign lib {
  54. /*
  55. Uses the string argument to set environment variable values.
  56. Returns: 0 on success, non-zero (setting errno) on failure
  57. Example:
  58. if posix.putenv("HOME=/usr/home") != 0 {
  59. fmt.panicf("putenv failure: %v", posix.strerror(posix.errno()))
  60. }
  61. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/putenv.html ]]
  62. */
  63. @(link_name=LPUTENV)
  64. putenv :: proc(string: cstring) -> c.int ---
  65. }
  66. EXIT_FAILURE :: libc.EXIT_FAILURE
  67. EXIT_SUCCESS :: libc.EXIT_SUCCESS
  68. RAND_MAX :: libc.RAND_MAX
  69. MB_CUR_MAX :: libc.MB_CUR_MAX
  70. div_t :: libc.div_t
  71. ldiv_t :: libc.ldiv_t
  72. lldiv_t :: libc.lldiv_t
  73. when ODIN_OS == .Windows {
  74. @(private) LPUTENV :: "_putenv"
  75. } else when ODIN_OS == .NetBSD {
  76. @(private) LPUTENV :: "__putenv50"
  77. } else {
  78. @(private) LPUTENV :: "putenv"
  79. }