feat: libc - add SYS_GETCHAR_NB and a non-blocking stdin readiness probe

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NQRTGoYgnZQsh7uCh6Jsxm
This commit is contained in:
2026-08-08 14:42:38 +02:00
co-authored by Claude Opus 5
parent fe10216f8b
commit e8407afcdb
11 changed files with 125 additions and 17 deletions
+1
View File
@@ -228,6 +228,7 @@ namespace montauk::abi {
static constexpr uint64_t SYS_WIFI_RESULTS = 163; // (WifiNetwork*, maxCount) -> count, no radio work
static constexpr uint64_t SYS_WIFI_CONNECT_ASYNC = 164; // (ssid, password) -> 0 accepted, <0 on error
static constexpr uint64_t SYS_NETIFS = 165; // (NetIfInfo*, maxCount) -> count
static constexpr uint64_t SYS_GETCHAR_NB = 166; // () -> ascii, 0 if nothing pending; never blocks
// Tunable parameters (for SYS_SDR_SETPARAM / SYS_SDR_GETPARAM).
static constexpr int SDR_PARAM_FREQ = 0; // center frequency, Hz
+1
View File
@@ -189,6 +189,7 @@ extern "C" {
#define MTK_SYS_WIFI_RESULTS 163
#define MTK_SYS_WIFI_CONNECT_ASYNC 164
#define MTK_SYS_NETIFS 165
#define MTK_SYS_GETCHAR_NB 166
/* @SYSCALLS-END */
#define MTK_SOCK_TCP 1
+11
View File
@@ -95,6 +95,17 @@ int ungetc(int c, FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int fputs(const char *s, FILE *stream);
/* MontaukOS extension: non-blocking readiness probe for stdin.
Returns 1 when a complete line is buffered, so a following fgets/fgetc on
stdin returns without blocking; 0 otherwise. Partially typed input is kept.
This is what a select()-style poll over stdin has to be built on -- stdio
descriptors are not waitable kernel objects. */
int montauk_stdin_ready(void);
/* Blocks until a complete line is buffered on stdin, then returns 1. Same
buffer as montauk_stdin_ready(); nothing is consumed either way. */
int montauk_stdin_wait(void);
void perror(const char *s);
FILE *tmpfile(void);
char *tmpnam(char *s);
+2
View File
@@ -197,6 +197,8 @@ namespace montauk {
inline bool is_key_available() { return (bool)syscall0(montauk::abi::SYS_ISKEYAVAILABLE); }
inline void getkey(montauk::abi::KeyEvent* out) { syscall1(montauk::abi::SYS_GETKEY, (uint64_t)out); }
inline char getchar() { return (char)syscall0(montauk::abi::SYS_GETCHAR); }
// Returns 0 rather than blocking when no character is pending.
inline char getchar_nb() { return (char)syscall0(montauk::abi::SYS_GETCHAR_NB); }
inline uint64_t input_wait(uint64_t observedSerial, uint64_t timeoutMs) {
return (uint64_t)syscall2(montauk::abi::SYS_INPUT_WAIT, observedSerial, timeoutMs);
}