string_libc.odin 836 B

123456789101112131415161718192021222324252627282930
  1. #+build linux, windows, darwin, netbsd, openbsd, freebsd
  2. package posix
  3. when ODIN_OS == .Windows {
  4. foreign import lib "system:libucrt.lib"
  5. } else when ODIN_OS == .Darwin {
  6. foreign import lib "system:System.framework"
  7. } else {
  8. foreign import lib "system:c"
  9. }
  10. // string.h - string operations
  11. // NOTE: most of the symbols in this header are not useful in Odin and have been left out.
  12. foreign lib {
  13. /*
  14. Map the error number to a locale-dependent error message string.
  15. Returns: a string that may be invalidated by subsequent calls
  16. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/strerror.html ]]
  17. */
  18. @(link_name="strerror")
  19. _strerror :: proc(errnum: Errno) -> cstring ---
  20. }
  21. strerror :: #force_inline proc "contextless" (errnum: Maybe(Errno) = nil) -> cstring {
  22. return _strerror(errnum.? or_else errno())
  23. }