monetary.odin 977 B

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