Skip to content

Commit 3ca198e

Browse files
SirJosh3917SirJosh3917
SirJosh3917
authored and
SirJosh3917
committed
Add base file-descriptors document.
1 parent 19a57f7 commit 3ca198e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

design/file-descriptors.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# File Descriptors
2+
File Descriptors (witx type `fd`) are an abstract way of representing access to a resource. More often than not, they are processes (WIP), sockets (WIP), files, or even the console.
3+
4+
# Null File Descriptor
5+
A File Descriptor of 0 is a null file descriptor. It's used whenever there is *no* file descriptor. Passing this to a method is a no-no, and receiving one from a method must be handled.
6+
7+
# The Console
8+
When a program is initiated, `stdout`, `stdin`, and `stderr` (respectively `fd` ids `1`, `2`, and `3`) are opened. To print to these, simply call `fd_write` with the corresponding arguments. An simple "Hello World!" program written in `wat` is shown below:
9+
10+
```wat
11+
(module
12+
;; TODO: small hello world?
13+
)
14+
```
15+
16+
# Files
17+
Files can be opened and closed with the commands `fd_open` and `fd_close` respectively. These commands will fail if the WASM environment did not give the program permission to execute these.

0 commit comments

Comments
 (0)