29 lines
703 B
Plaintext
29 lines
703 B
Plaintext
// io — stream interface (Plan 9 Bio / Hare io::stream shape).
|
|
//
|
|
// No closures, no methods. A `stream` is a struct of function
|
|
// pointers plus a `ctx: *void`. The error channel is the return
|
|
// value of read/write/close. Negative i32 = errno-style code,
|
|
// non-negative = bytes transferred.
|
|
|
|
type stream = struct {
|
|
ctx: *void,
|
|
read: fn(s: *stream, buf: []u8) i32,
|
|
write: fn(s: *stream, buf: []u8) i32,
|
|
close: fn(s: *stream) i32,
|
|
};
|
|
|
|
def eof: i32 = -1;
|
|
def closed: i32 = -2;
|
|
|
|
export fn read(s: *stream, buf: []u8) i32 = {
|
|
return s.read(s, buf);
|
|
};
|
|
|
|
export fn write(s: *stream, buf: []u8) i32 = {
|
|
return s.write(s, buf);
|
|
};
|
|
|
|
export fn close(s: *stream) i32 = {
|
|
return s.close(s);
|
|
};
|