1 ;;; Guile-R6RS-Libs --- Implementation of R6RS standard libraries.
2 ;;; Copyright (C) 2007, 2009 Ludovic Courtès <ludo@gnu.org>
4 ;;; Guile-R6RS-Libs is free software; you can redistribute it and/or
5 ;;; modify it under the terms of the GNU Lesser General Public
6 ;;; License as published by the Free Software Foundation; either
7 ;;; version 2.1 of the License, or (at your option) any later version.
9 ;;; Guile-R6RS-Libs is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; Lesser General Public License for more details.
14 ;;; You should have received a copy of the GNU Lesser General Public
15 ;;; License along with Guile-R6RS-Libs; if not, write to the Free Software
16 ;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 (define-module (rnrs io ports)
19 :re-export (eof-object? port? input-port? output-port?)
22 ;; input & output ports
23 port-transcoder binary-port? transcoded-port
24 port-position set-port-position!
25 port-has-port-position? port-has-set-port-position!?
29 open-bytevector-input-port
30 make-custom-binary-input-port
34 get-bytevector-n get-bytevector-n!
35 get-bytevector-some get-bytevector-all
39 open-bytevector-output-port))
41 (load-extension "libguile-r6rs-libs-v-0" "scm_init_r6rs_ports")
46 ;;; Input and output ports.
49 (define (port-transcoder port)
50 (error "port transcoders are not supported" port))
52 (define (binary-port? port)
53 ;; So far, we don't support transcoders other than the binary transcoder.
56 (define (transcoded-port port)
57 (error "port transcoders are not supported" port))
59 (define (port-position port)
60 "Return the offset (an integer) indicating where the next octet will be
61 read from/written to in @var{port}."
63 ;; FIXME: We should raise an `&assertion' error when not supported.
64 (seek port 0 SEEK_CUR))
66 (define (set-port-position! port offset)
67 "Set the position where the next octet will be read from/written to
70 ;; FIXME: We should raise an `&assertion' error when not supported.
71 (seek port offset SEEK_SET))
73 (define (port-has-port-position? port)
74 "Return @code{#t} is @var{port} supports @code{port-position}."
75 (and (false-if-exception (port-position port)) #t))
77 (define (port-has-set-port-position!? port)
78 "Return @code{#t} is @var{port} supports @code{set-port-position!}."
79 (and (false-if-exception (set-port-position! port (port-position port)))
82 (define (call-with-port port proc)
83 "Call @var{proc}, passing it @var{port} and closing @var{port} upon exit of
84 @var{proc}. Return the return values of @var{proc}."