File Ports
----------
The following procedures are used to open file ports. See also Note:open, for an interface to the Unix `open'
system call.
- primitive: open-file filename modes
Open the file whose name is STRING, and return a port representing
that file. The attributes of the port are determined by the MODE
string. The way in which this is interpreted is similar to C
stdio:
The first character must be one of the following:
`r'
Open an existing file for input.
`w'
Open a file for output, creating it if it doesn't already
exist or removing its contents if it does.
`a'
Open a file for output, creating it if it doesn't already
exist. All writes to the port will go to the end of the file.
The "append mode" can be turned off while the port is in use
Note:fcntl.
The following additional characters can be appended:
`+'
Open the port for both input and output. E.g., `r+': open an
existing file for both input and output.
`0'
Create an "unbuffered" port. In this case input and output
operations are passed directly to the underlying port
implementation without additional buffering. This is likely
to slow down I/O operations. The buffering mode can be
changed while a port is in use Note:setvbuf.
`l'
Add line-buffering to the port. The port output buffer will
be automatically flushed whenever a newline character is
written.
In theory we could create read/write ports which were buffered in
one direction only. However this isn't included in the current
interfaces.
If a file cannot be opened with the access requested, `open-file'
throws an exception.
- procedure: open-input-file filename
Open FILENAME for input. Equivalent to
(open-file FILENAME "r")
- procedure: open-output-file filename
Open FILENAME for output. Equivalent to
(open-file FILENAME "w")
- primitive: port-mode port
Returns the port modes associated with the open port PORT. These
will not necessarily be identical to the modes used when the port
was opened, since modes such as "append" which are used only during
port creation are not retained.
- primitive: port-filename port
Return the filename associated with PORT. This function returns
the strings "standard input", "standard output" and "standard
error" when called on the current input, output and error ports
respectively.
- primitive: set-port-filename! port filename
Change the filename associated with PORT, using the current input
port if none is specified. Note that this does not change the
port's source of data, but only the value that is returned by
`port-filename' and reported in diagnostic output.