diff options
Diffstat (limited to 'language/dynamic/files.e')
| -rw-r--r-- | language/dynamic/files.e | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/language/dynamic/files.e b/language/dynamic/files.e index 4822c2f..e0ef533 100644 --- a/language/dynamic/files.e +++ b/language/dynamic/files.e @@ -150,7 +150,7 @@ ~ (filename, file descriptor) ~ Notice that we deferred this allocation until after we know that opening - ~ the file succeeded. We can't leave it any longer thaan this; + ~ the file succeeded. We can't leave it any longer than this; ~ push-input-buffer will allocate memory, which will overwrite the scratch ~ space. swap allocate-string-if-temporary swap @@ -176,3 +176,32 @@ : current-input-file-name main-input-buffer buffer-filename @ ; + +: open-file-for-reading +~ (filename -- metadata pointer or 0) + dup 0 0 sys-open + dup 0 > { + ." Couldn't open " swap emitstring space + ." because " space . ." ." newline + drop 0 exit + } if + ~ (filename, file descriptor) + + ~ As with include, we deferred this allocation until after successful open. + swap allocate-string-if-temporary swap + + allocate-input-buffer-metadata dup zero-input-buffer-metadata + ~ (filename, file descriptor) + + dup 3unroll swap attach-input-buffer-to-file-descriptor ; + + +~ Note that this doesn't clear data that's already in the buffer. +~ +~ (metadata pointer --) +: close-file + dup buffer-file-descriptor @ sys-close drop + ~ Ignore a failed close. + + buffer-file-descriptor -1 swap ! ; + |