Files are opened/created by name and type. The following file access methods (FAMs) are recognised:
r/o– fam file “r-o”
r/w– fam file “r-w”
w/o– fam file “w-o”
binfam1 – fam2 file “bin”
When a file is opened/created, it returns a file identifier, wfileid that is used for all other file commands. All file commands also return a status value, wior, that is 0 for a successful operation and an implementation-defined non-zero value in the case of an error.
open-filec-addr u wfam – wfileid wior file “open-file”
create-filec-addr u wfam – wfileid wior file “create-file”
close-filewfileid – wior file “close-file”
delete-filec-addr u – wior file “delete-file”
rename-filec-addr1 u1 c-addr2 u2 – wior file-ext “rename-file”
Rename file c_addr1 u1 to new name c_addr2 u2
read-filec-addr u1 wfileid – u2 wior file “read-file”
read-linec_addr u1 wfileid – u2 flag wior file “read-line”
key-filewfileid – c gforth “paren-key-file”
Read one character c from wfileid. This word disables
buffering for wfileid. If you want to read characters from a
terminal in non-canonical (raw) mode, you have to put the terminal in
non-canonical mode yourself (using the C interface); the exception is
stdin: Gforth automatically puts it into non-canonical mode.
key?-filewfileid – f gforth “key-q-file”
f is true if at least one character can be read from wfileid
without blocking. If you also want to use
read-line on the file, you have to call
key-file first (these two words disable buffering).
write-filec-addr u1 wfileid – wior file “write-file”
write-linec-addr u fileid – ior file “write-line”
emit-filec wfileid – wior gforth “emit-file”
flush-filewfileid – wior file-ext “flush-file”
file-statusc-addr u – wfam wior file-ext “file-status”
file-positionwfileid – ud wior file “file-position”
reposition-fileud wfileid – wior file “reposition-file”
file-sizewfileid – ud wior file “file-size”
resize-fileud wfileid – wior file “resize-file”
slurp-filec-addr1 u1 – c-addr2 u2 gforth “slurp-file”
c-addr1 u1 is the filename, c-addr2 u2 is the file's contents
slurp-fidfid – addr u gforth “slurp-fid”
addr u is the content of the file fid
stdin– wfileid gforth “stdin”
The standard input file of the Gforth process.
stdout– wfileid gforth “stdout”
The standard output file of the Gforth process.
stderr– wfileid gforth “stderr”
The standard error output file of the Gforth process.