libstd/stdio
Console and file-descriptor I/O: the variadic print, buffered line input, and the raw read/write syscall wrappers. Including it also brings in libstd/string and libstd/list.
#include <libstd/stdio>
Includes libstd/macro, libstd/string, libstd/list. Same functions and constant names on Linux and Windows: the system-specific part is in wrapper/linux/stdio and wrapper/windows/stdio (see Linux and Windows).
Example
#include <libstd/stdio>
name = "world"
print("Hello, ", name, "! ", 42, " ", 2.5, "\n")
ib = input_buffer_new()
line = input(ib) // one line from standard input, without the newline
fprint(2, "done\n") // standard error
Hello, world! 42 2.500000
Constants
| Name | Linux | Windows | Meaning |
|---|---|---|---|
INPUT_BUFFER_SIZE | 4096 | 4096 |
Classes
A 4096-byte read buffer over a file descriptor; create with input_buffer_new. eof is set when the last read hit the end of the stream.
buf str
len int
pos int
eof intFunctions
Creates an empty InputBuffer. Several independent buffers can exist at once.
Returns the next character from fd through the buffer, issuing a real read only every 4096 characters. Returns '\0' at end of stream or on error and sets ib.eof.
1 if the last read through ib hit the end of the stream (or an error). Needed because input/readline return "" both for an empty line and at end of file.
Reads one line from standard input (up to '\n' or end of file) and returns it without the newline. Check at_eof(ib) to tell an empty line from the end of input.
Like input but from any file descriptor.
Writes a NUL-terminated string to a file descriptor (1 = stdout, 2 = stderr, or any open file/socket). Returns the number of bytes written.
Reads one byte from a file descriptor and returns it (0–255), or -1 at end of file or on error.
Prints any number of arguments of mixed type to standard output with no separator and no trailing newline: str as is, int/long with itoa, float with ftoa, a char as the character (c as int for its code).
Raw read(2): reads up to length bytes into start_offs. Returns the number of bytes read, 0 at end of file, negative on error. No bounds check: the buffer must be at least length bytes. On Windows it reads a socket with recv, so a receive timeout applies.