1 // stdio.asm: WORD p_stream,'STREAM',fasm
7 Data stack: ( fd size -- addr ) or ( block -1 -- addr )
10 "STREAM" is a function word that sets up a buffer for an input file
11 descriptor or for a memory block (of size+data).
13 ==== File descriptor backed STREAM
15 A file descriptor backed STREAM gains a buffer of the given size
16 prefixed by a 32 byte STREAM header of the following layout:
20 [caption='Stream layout {counter:layout}, for ']
22 8 bytes = size of buffer (excluding the 32 byte header)
23 8 bytes source file descriptor
25 8 current read position
29 ==== Memory block backed STREAM
31 A memory block stream is only the header (though allocated via
32 <<p_malloc,MALLOC>> which reserves a full kernel page) with the
37 [caption='Stream layout {counter:layout}, for ']
39 8 bytes = block address
40 8 -1 (indicates memory block)
41 8 size of block (taken from the block's first 8 bytes)
42 8 current read position