<stdio.h>¶
Console I/O over ttysvc: printf and scanf families, and choosing the terminal.
#include <stdio.h>
Constants¶
| Name | Value | Description |
|---|---|---|
EOF |
(-1) |
Returned by input functions at end of input or on error. |
Functions¶
printf¶
int printf(const char *format,...);
Writes formatted output to the standard output stream (stdout).
| Parameter | Direction | Description |
|---|---|---|
format |
in | printf format. |
... |
in | Arguments. |
Returns: The number of characters printed (excluding the null byte used to end output to strings), or a negative value if an error occurs.
vprintf¶
int vprintf(const char *format, va_list args);
Writes formatted output to the standard output stream (stdout) using a va_list.
| Parameter | Direction | Description |
|---|---|---|
format |
in | printf format. |
args |
in | Arguments. |
Returns: The number of characters printed (excluding the null byte used to end output to strings), or a negative value if an error occurs.
sprintf¶
int sprintf(char *buf, const char *format,...);
Writes formatted output to a string.
| Parameter | Direction | Description |
|---|---|---|
buf |
out | Output buffer; must be large enough, as nothing limits the length. |
format |
in | printf format. |
... |
in | Arguments. |
Returns: The number of characters written to the buffer (excluding the null byte used to end output to strings), or a negative value if an error occurs.
vsprintf¶
int vsprintf(char *buf, const char *format, va_list args);
Writes formatted output to a string using a va_list.
| Parameter | Direction | Description |
|---|---|---|
buf |
out | Output buffer; must be large enough, as nothing limits the length. |
format |
in | printf format. |
args |
in | Arguments. |
Returns: The number of characters written to the buffer (excluding the null byte used to end output to strings), or a negative value if an error occurs.
getchar¶
int getchar(void);
Reads a character from the standard input stream (stdin).
Returns: The character read as an unsigned char cast to an int or EOF on end of file or error.
scanf¶
int scanf(const char *format,...);
Reads one line from the console and parses it, like sscanf().
| Parameter | Direction | Description |
|---|---|---|
format |
in | scanf format. |
... |
out | Where to store the converted items. |
Returns: The number of input items successfully matched and assigned, or EOF if an input failure occurs before any items are matched.
vscanf¶
int vscanf(const char *format, va_list args);
scanf() taking a va_list.
| Parameter | Direction | Description |
|---|---|---|
format |
in | scanf format. |
args |
out | Where to store the converted items. |
Returns: The number of input items successfully matched and assigned, or EOF if an input failure occurs before any items are matched.
stdio_open_tty¶
int stdio_open_tty(void);
Connects stdio to ttysvc now, rather than on first use.
Returns: 0 on success, or -1.
stdio_set_raw¶
int stdio_set_raw(int enable);
Switches the console between cooked (line editing and echo by the terminal service, the default) and raw (every byte passed through; the caller echoes).
In raw mode printf still turns "\n" into "\r\n".
The setting survives a reconnect.
| Parameter | Direction | Description |
|---|---|---|
enable |
in | Non-zero for raw, 0 for cooked. |
Returns: 0 on success, or -1.
stdio_close_tty¶
void stdio_close_tty(void);
Detaches from the tty so another program can take the foreground.
The next stdio call attaches again.
stdio_route_tty¶
int stdio_route_tty(const char *name);
Routes the standard I/O functions to a specific TTY device.
Reconnects at once, so a bad alias is reported here rather than at the next printf.
| Parameter | Direction | Description |
|---|---|---|
name |
in | A ttysvc alias (e.g. "tty0"), or "" for the default endpoint. |
Returns: 0 on success, or -1.
stdio_use_tty¶
int stdio_use_tty(uint32_t index);
stdio_route_tty() to "tty
| Parameter | Direction | Description |
|---|---|---|
index |
in | Terminal number; only its last decimal digit is used. |
Returns: As stdio_route_tty().