fmt_os.odin 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //+build !freestanding !js
  2. package fmt
  3. import "core:runtime"
  4. import "core:os"
  5. import "core:io"
  6. fprint :: proc(fd: os.Handle, args: ..any, sep := " ") -> int {
  7. w := io.to_writer(os.stream_from_handle(fd))
  8. return wprint(w=w, args=args, sep=sep)
  9. }
  10. fprintln :: proc(fd: os.Handle, args: ..any, sep := " ") -> int {
  11. w := io.to_writer(os.stream_from_handle(fd))
  12. return wprintln(w=w, args=args, sep=sep)
  13. }
  14. fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
  15. w := io.to_writer(os.stream_from_handle(fd))
  16. return wprintf(w, fmt, ..args)
  17. }
  18. fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info) -> (n: int, err: io.Error) {
  19. w := io.to_writer(os.stream_from_handle(fd))
  20. return wprint_type(w, info)
  21. }
  22. fprint_typeid :: proc(fd: os.Handle, id: typeid) -> (n: int, err: io.Error) {
  23. w := io.to_writer(os.stream_from_handle(fd))
  24. return wprint_typeid(w, id)
  25. }
  26. // print* procedures return the number of bytes written
  27. print :: proc(args: ..any, sep := " ") -> int { return fprint(fd=os.stdout, args=args, sep=sep) }
  28. println :: proc(args: ..any, sep := " ") -> int { return fprintln(fd=os.stdout, args=args, sep=sep) }
  29. printf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stdout, fmt, ..args) }
  30. eprint :: proc(args: ..any, sep := " ") -> int { return fprint(fd=os.stderr, args=args, sep=sep) }
  31. eprintln :: proc(args: ..any, sep := " ") -> int { return fprintln(fd=os.stderr, args=args, sep=sep) }
  32. eprintf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stderr, fmt, ..args) }