fmt_os.odin 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //+build !freestanding !js
  2. package fmt
  3. import "core:runtime"
  4. import "core:os"
  5. import "core:io"
  6. // fprint formats using the default print settings and writes to fd
  7. fprint :: proc(fd: os.Handle, args: ..any, sep := " ") -> int {
  8. w := io.to_writer(os.stream_from_handle(fd))
  9. return wprint(w=w, args=args, sep=sep)
  10. }
  11. // fprintln formats using the default print settings and writes to fd
  12. fprintln :: proc(fd: os.Handle, args: ..any, sep := " ") -> int {
  13. w := io.to_writer(os.stream_from_handle(fd))
  14. return wprintln(w=w, args=args, sep=sep)
  15. }
  16. // fprintf formats according to the specififed format string and writes to fd
  17. fprintf :: proc(fd: os.Handle, fmt: string, args: ..any) -> int {
  18. w := io.to_writer(os.stream_from_handle(fd))
  19. return wprintf(w, fmt, ..args)
  20. }
  21. fprint_type :: proc(fd: os.Handle, info: ^runtime.Type_Info) -> (n: int, err: io.Error) {
  22. w := io.to_writer(os.stream_from_handle(fd))
  23. return wprint_type(w, info)
  24. }
  25. fprint_typeid :: proc(fd: os.Handle, id: typeid) -> (n: int, err: io.Error) {
  26. w := io.to_writer(os.stream_from_handle(fd))
  27. return wprint_typeid(w, id)
  28. }
  29. // print formats using the default print settings and writes to os.stdout
  30. print :: proc(args: ..any, sep := " ") -> int { return fprint(fd=os.stdout, args=args, sep=sep) }
  31. // println formats using the default print settings and writes to os.stdout
  32. println :: proc(args: ..any, sep := " ") -> int { return fprintln(fd=os.stdout, args=args, sep=sep) }
  33. // printf formats according to the specififed format string and writes to os.stdout
  34. printf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stdout, fmt, ..args) }
  35. // eprint formats using the default print settings and writes to os.stderr
  36. eprint :: proc(args: ..any, sep := " ") -> int { return fprint(fd=os.stderr, args=args, sep=sep) }
  37. // eprintln formats using the default print settings and writes to os.stderr
  38. eprintln :: proc(args: ..any, sep := " ") -> int { return fprintln(fd=os.stderr, args=args, sep=sep) }
  39. // eprintf formats according to the specififed format string and writes to os.stderr
  40. eprintf :: proc(fmt: string, args: ..any) -> int { return fprintf(os.stderr, fmt, ..args) }