scsh-0.6/scheme/rts/channel.scm

53 lines
1.5 KiB
Scheme
Raw Normal View History

1999-09-14 08:45:02 -04:00
; Copyright (c) 1993-1999 by Richard Kelsey and Jonathan Rees. See file COPYING.
; Provides input and output channels.
(define (input-channel? thing)
(and (channel? thing)
(or (= (channel-status thing)
(enum channel-status-option input))
(= (channel-status thing)
(enum channel-status-option special-input)))))
(define (output-channel? thing)
(and (channel? thing)
(or (= (channel-status thing)
(enum channel-status-option output))
(= (channel-status thing)
(enum channel-status-option special-output)))))
;;; Scsh changes umask and cwd lazily
;;; placeholder until scsh sets it
(define (with-fs-context-aligned* thunk)
(thunk))
(define (set-with-fs-context-aligned*! wpca*)
(set! with-fs-context-aligned* wpca*))
1999-09-14 08:45:02 -04:00
(define (open-input-channel filename)
(let ((channel (with-fs-context-aligned*
(lambda ()
(open-channel filename (enum channel-status-option input))))))
1999-09-14 08:45:02 -04:00
(if (channel? channel)
channel
(error "cannot open input file" filename))))
(define (open-output-channel filename)
(let ((channel (with-fs-context-aligned*
(lambda ()
(open-channel filename (enum channel-status-option output))))))
1999-09-14 08:45:02 -04:00
(if (channel? channel)
channel
(error "cannot open output file" filename))))
(define (close-input-channel channel)
(if (input-channel? channel)
(close-channel channel)
(call-error close-input-channel channel)))
(define (close-output-channel channel)
(if (output-channel? channel)
(close-channel channel)
(call-error close-output-channel channel)))