open-file-input-port - open a file for reading

LIBRARY

(import (rnrs))                     ;R6RS
(import (rnrs io ports))            ;R6RS

SYNOPSIS

(open-file-input-port filename)
(open-file-input-port filename file-options)
(open-file-input-port filename file-options buffer-mode)
(open-file-input-port filename file-options buffer-mode maybe-transcoder)

DESCRIPTION

Returns an input port for the named file.

The file-options argument defaults to the value of (file-options). Note that the standard file options do nothing for input ports.

The buffer-mode argument must be one of the symbols that name a buffer mode. It defaults to block. Note that line buffering is unlikely to be effective on input ports.

Textual ports
If maybe-transcoder is a transcoder, it becomes the transcoder associated with the returned port. The port will then be a textual port.
Binary ports
If maybe-transcoder is #f or absent, the port will be a binary port.
Port positioning
The port will support the port-position(3scm) and set-port-position!(3scm) operations if it is a binary port. Otherwise support is implementation-dependent, and possibly transcoder-dependent.

RETURN VALUES

Returns a single value; a binary or textual input port.

EXAMPLES

;; Return all records in /etc/passwd
(call-with-port
   (open-file-input-port "/etc/passwd"
                         (file-options)
                         (buffer-mode block)
                         (native-transcoder))
  (lambda (p)
    (let lp ()
      (let ((line (get-line p)))
         (if (eof-object? line)
             '()
             (cons line (lp)))))))

APPLICATION USAGE

This is used in applications that open binary files, and ones that open textual files while needing control over the transcoder.

COMPATIBILITY

This procedure is unique to R6RS. Other RnRS revisions have open-input-file(3scm), which is also in R6RS.

ERRORS

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain. In particular, maybe-transcoder must be either a transcoder or #f.
R7RS
The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

SEE ALSO

file-options(7scm), buffer-mode(7scm), open-input-file(3scm), open-file-output-port(3scm)

STANDARDS

R6RS

HISTORY

First appeared in the reworked I/O system in R6RS.

AUTHORS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.


Markup created by unroff 1.0sc,    March 04, 2023.