string.odin 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package posix
  2. import "core:c"
  3. when ODIN_OS == .Darwin {
  4. foreign import lib "system:System.framework"
  5. } else {
  6. foreign import lib "system:c"
  7. }
  8. // string.h - string operations
  9. // NOTE: most of the symbols in this header are not useful in Odin and have been left out.
  10. foreign lib {
  11. /*
  12. Map the error number to a locale-dependent error message string.
  13. Returns: a string that may be invalidated by subsequent calls
  14. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html ]]
  15. */
  16. @(link_name="strerror")
  17. _strerror :: proc(errnum: Errno) -> cstring ---
  18. /*
  19. Map the error number to a locale-dependent error message string and put it in the buffer.
  20. Returns: ERANGE if the buffer is not big enough
  21. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror_r.html ]]
  22. */
  23. strerror_r :: proc(errnum: Errno, strerrbuf: [^]byte, buflen: c.size_t) -> Errno ---
  24. /*
  25. Map the signal number to an implementation-defined string.
  26. Returns: a string that may be invalidated by subsequent calls
  27. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/strsignal.html ]]
  28. */
  29. strsignal :: proc(sig: Signal) -> cstring ---
  30. }
  31. strerror :: #force_inline proc "contextless" (errnum: Maybe(Errno) = nil) -> cstring {
  32. return _strerror(errnum.? or_else errno())
  33. }