std1.0.0-beta-7 SafeC docs
// SafeC Standard Library — I/O declarations (C11/C17/C23 stdio coverage)
#pragma once
#include <std/io_file.h>

// ── Seek / EOF constants ──────────────────────────────────────────────────────
#define SC_SEEK_SET  0
#define SC_SEEK_CUR  1
#define SC_SEEK_END  2
#define SC_EOF       (-1)

// ── Formatted output (stdout) ─────────────────────────────────────────────────
namespace std {

void print(const &char s);
void println(const &char s);
void print_char(int c);
void print_int(long long v);
void print_uint(unsigned long long v);
void print_float(double v);
void print_hex(unsigned long long v);
void print_oct(unsigned long long v);
void print_ptr_raw_(const unsigned char* p);
// Print the address a reference points at ("(nil)" for null).
generic<T>
void print_ptr(const ?&T p) { unsafe { print_ptr_raw_((const unsigned char*)p); } }
void println_int(long long v);
void println_uint(unsigned long long v);
void println_float(double v);
void println_char(int c);

// ── Formatted output (stderr) ─────────────────────────────────────────────────
void eprint(const &char s);
void eprintln(const &char s);
void eprint_int(long long v);
void eprint_float(double v);

// ── Formatted output to buffer (snprintf wrappers) ───────────────────────────
// All return the number of characters written (excluding NUL), or -1 on error.
int io_fmt_int([]char buf, long long v);
int io_fmt_uint([]char buf, unsigned long long v);
int io_fmt_float([]char buf, double v);
int io_fmt_float_prec([]char buf, double v, int prec);
int io_fmt_hex([]char buf, unsigned long long v);
int io_fmt_str([]char buf, const &char s);

// ── Input (stdin) ─────────────────────────────────────────────────────────────
// Read a single character from stdin.  Returns the character or SC_EOF.
int  io_getchar();

// Push a character back onto stdin so the next io_getchar/io_scan_* returns it.
int  io_ungetc(int c);

// Read a line (up to buf.len-1 chars + NUL) from stdin into buf.
// Returns number of characters read (excluding NUL), or -1 on EOF/error.
int  io_read_line([]char buf);

// Read a whitespace-delimited token from stdin.
// Returns number of characters read (0 = EOF before token, -1 = error).
int  io_read_token([]char buf);

// Parse a signed decimal integer from stdin. Returns 1 on success, 0 on error.
int  io_scan_int(&long long out);

// Parse an unsigned decimal integer from stdin. Returns 1 on success.
int  io_scan_uint(&unsigned long long out);

// Parse a floating-point number from stdin. Returns 1 on success.
int  io_scan_float(&double out);

// ── File system operations ────────────────────────────────────────────────────
// Remove (delete) a file.  Returns 0 on success, non-zero on error.
int  io_remove(const &char path);

// Rename / move a file.  Returns 0 on success, non-zero on error.
int  io_rename(const &char old_path, const &char new_path);

// Create a temporary file; returns file handle or NULL on error.
?&File io_tmpfile();

// ── Flush ─────────────────────────────────────────────────────────────────────
void flush_stdout();
void flush_stderr();

} // namespace std