In file.cecil:
A unix_file
object acts like a mutable, extensible, positionable
stream of characters, as well as supporting lots of standard file
I/O operations.
open_file
. The optional if_error
closure taken by
open_file
and many other file operations is invoked if there was a
standard Unix error during the operation, passing the Unix
errno
value as the integer argument to the closure. The error_string
function converts
errno to an error message, using the Unix
sys_errlist
. The unix_error
function invokes error with an
appropriate error message derived from a user-supplied message and
the
errno code. The nonfatal_unix_error
also prints the error
message, but then successfully returns to the caller.
The three standard files can be returned by the
stdin,
stdout, and
stderr functions. Six functions are available to query properties of
the file: whether or not the file is readable and/or writable and
whether or not writes always append. The
read functions read up to
size characters into a buffer; they return how many characters
actually were read. The read_line
functions work like
read, except
that they stop reading after they've seen (and copied to the buffer)
a newline character. The
write functions write their argument
character buffer (optionally copying only
size characters) to the
file. Collectors can be written to a file directly, more efficiently
than first flattening the collector into a string. Individual
characters can also be written to a file.
The mod_time
operations return the modification timestamp of the file;
get_mod_time
is a convenience in case the file hasn't been opened
yet. (The
time data structure supports parsing the timestamp integer.)
In addition to the other stream-style operations, unix_file
s support
testing whether they have detected the end of the file (subtly different
than actually being at the end of the file) and performing
lseek-style
repositioning relative either to the start of the file, the current
position, or the end of the file.
find_file
operation takes a file name and a directory search path and returns
an absolute path name for the first file that matches the name in
the search path. To do this work find_file
invokes file_exists
to
test whether a given file name is defined and expand to expand away
user file-name prefixes. The parse_path
helper function converts a
Unix search path string (directory names separated by colons) into a
sequence of directory names.