DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

(guile.info.gz) File Ports

Info Catalog (guile.info.gz) Port Types (guile.info.gz) String Ports
 
 27.9.1 File Ports
 -----------------
 
 The following procedures are used to open file ports.  See also 
 open Ports and File Descriptors, for an interface to the Unix `open'
 system call.
 
  -- Scheme Procedure: open-file filename mode
  -- C Function: scm_open_file (filename, mode)
      Open the file whose name is FILENAME, 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
            fcntl Ports and File Descriptors.
      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  setvbuf Ports and File
           Descriptors.
 
     `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.
 
  -- Scheme Procedure: open-input-file filename
      Open FILENAME for input.  Equivalent to
           (open-file FILENAME "r")
 
  -- Scheme Procedure: open-output-file filename
      Open FILENAME for output.  Equivalent to
           (open-file FILENAME "w")
 
  -- Scheme Procedure: call-with-input-file file proc
      PROC should be a procedure of one argument, and FILE should be a
      string naming a file.  The file must already exist. These
      procedures call PROC with one argument: the port obtained by
      opening the named file for input or output.  If the file cannot be
      opened, an error is signalled.  If the procedure returns, then the
      port is closed automatically and the value yielded by the
      procedure is returned.  If the procedure does not return, then the
      port will not be closed automatically unless it is possible to
      prove that the port will never again be used for a read or write
      operation.
 
  -- Scheme Procedure: call-with-output-file file proc
      PROC should be a procedure of one argument, and FILE should be a
      string naming a file.  The behaviour is unspecified if the file
      already exists. These procedures call PROC with one argument: the
      port obtained by opening the named file for input or output.  If
      the file cannot be opened, an error is signalled.  If the
      procedure returns, then the port is closed automatically and the
      value yielded by the procedure is returned.  If the procedure does
      not return, then the port will not be closed automatically unless
      it is possible to prove that the port will never again be used for
      a read or write operation.
 
  -- Scheme Procedure: with-input-from-file file thunk
      THUNK must be a procedure of no arguments, and FILE must be a
      string naming a file.  The file must already exist. The file is
      opened for input, an input port connected to it is made the
      default value returned by `current-input-port', and the THUNK is
      called with no arguments.  When the THUNK returns, the port is
      closed and the previous default is restored.  Returns the value
      yielded by THUNK.  If an escape procedure is used to escape from
      the continuation of these procedures, their behavior is
      implementation dependent.
 
  -- Scheme Procedure: with-output-to-file file thunk
      THUNK must be a procedure of no arguments, and FILE must be a
      string naming a file.  The effect is unspecified if the file
      already exists.  The file is opened for output, an output port
      connected to it is made the default value returned by
      `current-output-port', and the THUNK is called with no arguments.
      When the THUNK returns, the port is closed and the previous
      default is restored.  Returns the value yielded by THUNK.  If an
      escape procedure is used to escape from the continuation of these
      procedures, their behavior is implementation dependent.
 
  -- Scheme Procedure: with-error-to-file file thunk
      THUNK must be a procedure of no arguments, and FILE must be a
      string naming a file.  The effect is unspecified if the file
      already exists.  The file is opened for output, an output port
      connected to it is made the default value returned by
      `current-error-port', and the THUNK is called with no arguments.
      When the THUNK returns, the port is closed and the previous
      default is restored.  Returns the value yielded by THUNK.  If an
      escape procedure is used to escape from the continuation of these
      procedures, their behavior is implementation dependent.
 
  -- Scheme Procedure: port-mode port
  -- C Function: scm_port_mode (port)
      Return 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.
 
  -- Scheme Procedure: port-filename port
  -- C Function: scm_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.
 
  -- Scheme Procedure: set-port-filename! port filename
  -- C Function: scm_set_port_filename_x (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.
 
  -- Scheme Procedure: file-port? obj
  -- C Function: scm_file_port_p (obj)
      Determine whether OBJ is a port that is related to a file.
 
Info Catalog (guile.info.gz) Port Types (guile.info.gz) String Ports
automatically generated byinfo2html