Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add zero_world_read runtime stdin shim
  • Loading branch information
WalterGropius committed May 21, 2026
commit 0a94978c3373519bdce5b56ce62e9be9ce936626
2 changes: 2 additions & 0 deletions native/zero-c/include/zero_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef enum {

int zero_world_write(int fd, const char *buf, unsigned len);

unsigned zero_world_read(int fd, char *buf, unsigned len);

int64_t zero_json_parse_bytes(ZeroByteView input);

uint64_t zero_http_fetch_result(
Expand Down
14 changes: 14 additions & 0 deletions native/zero-c/runtime/zero_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
#include <io.h>
typedef int ZeroWriteResult;
#define ZERO_RUNTIME_WRITE _write
#define ZERO_RUNTIME_READ _read
#else
#include <unistd.h>
typedef ssize_t ZeroWriteResult;
#define ZERO_RUNTIME_WRITE write
#define ZERO_RUNTIME_READ read
#endif

int zero_world_write(int fd, const char *buf, unsigned len) {
Expand All @@ -30,6 +32,18 @@ int zero_world_write(int fd, const char *buf, unsigned len) {
return 0;
}

unsigned zero_world_read(int fd, char *buf, unsigned len) {
if (len == 0 || !buf) return 0;
for (;;) {
ZeroWriteResult got = ZERO_RUNTIME_READ(fd, buf, len);
if (got < 0) {
if (errno == EINTR) continue;
return 0;
}
return (unsigned)got;
}
}

typedef struct {
const unsigned char *ptr;
size_t len;
Expand Down
Loading