monetary.odin 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #+build linux, darwin, netbsd, openbsd, freebsd
  2. package posix
  3. import "core:c"
  4. when ODIN_OS == .Darwin {
  5. foreign import lib "system:System.framework"
  6. } else {
  7. foreign import lib "system:c"
  8. }
  9. // monetary.h - monetary types
  10. foreign lib {
  11. /*
  12. Places characters into the array pointed to by s as controlled by the string format.
  13. No more than maxsize bytes are placed into the array.
  14. Returns: -1 (setting errno) on failure, the number of bytes added to s otherwise
  15. Example:
  16. posix.setlocale(.ALL, "en_US.UTF-8")
  17. value := 123456.789
  18. buffer: [100]byte
  19. size := posix.strfmon(raw_data(buffer[:]), len(buffer), "%n", value)
  20. if int(size) == -1 {
  21. fmt.panicf("strfmon failure: %s", posix.strerror(posix.errno()))
  22. }
  23. fmt.println(string(buffer[:size]))
  24. Output:
  25. $123,456.79
  26. [[ More; https://pubs.opengroup.org/onlinepubs/9699919799/functions/strfmon.html ]]
  27. */
  28. strfmon :: proc(
  29. s: [^]byte,
  30. maxsize: c.size_t,
  31. format: cstring,
  32. #c_vararg args: ..any,
  33. ) -> c.size_t ---
  34. }