Newer
Older
(unless routine
(error "Could not find any input routine for ~S" target-type))
(setf (fd-stream-ibuf-sap stream) (next-available-buffer))
(setf (fd-stream-ibuf-length stream) bytes-per-buffer)
(setf (fd-stream-ibuf-tail stream) 0)
(setf (fd-stream-in stream) routine
(setf (fd-stream-in stream) #'ill-in
(when (or (eql size 1)
(eql size 2)
(eql size 4))
;; Support for n-byte operations on 8-, 16-, and 32-bit streams
(setf (fd-stream-n-bin stream) #'fd-stream-read-n-bytes)
(when (and buffer-p (eql size 1)
(or (eq type 'unsigned-byte)
(eq type :default)))
;; We only create this buffer for streams of type
;; (unsigned-byte 8). Because there's no buffer, the
;; other element-types will dispatch to the appropriate
;; input (output) routine in fast-read-byte.
(make-array in-buffer-length
:element-type '(unsigned-byte 8)))))
(setf input-size size)
(setf input-type type)))
(when output-p
(multiple-value-bind
(routine type size)
(pick-output-routine target-type (fd-stream-buffering stream))
(unless routine
(error "Could not find any output routine for ~S buffered ~S."
(fd-stream-buffering stream)
target-type))
(setf (fd-stream-obuf-sap stream) (next-available-buffer))
(setf (fd-stream-obuf-length stream) bytes-per-buffer)
(setf (fd-stream-obuf-tail stream) 0)
(if (subtypep type 'character)
(setf (fd-stream-out stream) routine
(fd-stream-bout stream) #'ill-bout)
(setf (fd-stream-out stream)
(or (if (eql size 1)
(fd-stream-buffering stream)))
#'ill-out)
(fd-stream-bout stream) routine))
(setf (fd-stream-sout stream)
(if (eql size 1) #'fd-sout #'ill-out))
(setf (fd-stream-char-pos stream) 0)
(setf output-size size)
(setf output-type type)))
(when (and input-size output-size
(not (eq input-size output-size)))
(error "Element sizes for input (~S:~S) and output (~S:~S) differ?"
input-type input-size
output-type output-size))
(setf (fd-stream-element-size stream)
(or input-size output-size))
(setf (fd-stream-element-type stream)
(cond ((equal input-type output-type)
input-type)
((null output-type)
input-type)
((null input-type)
output-type)
((subtypep input-type output-type)
input-type)
((subtypep output-type input-type)
output-type)
(t
(error "Input type (~S) and output type (~S) are unrelated?"
input-type
output-type))))))
;;; REVERT-FILE -- internal
;;;
;;; Revert a file, if possible; otherwise just delete it. Used during
;;; CLOSE when the abort flag is set.
;;;
(defun revert-file (filename original)
(declare (type simple-base-string filename)
(type (or simple-base-string null) original))
(if original
(multiple-value-bind (okay err) (unix:unix-rename original filename)
(unless okay
(cerror "Go on as if nothing bad happened."
filename (unix:get-unix-error-msg err))))
(multiple-value-bind (okay err) (unix:unix-unlink filename)
(unless okay
(cerror "Go on as if nothing bad happened."
"Could not remove ~S: ~A"
filename (unix:get-unix-error-msg err))))))
;;; DELETE-ORIGINAL -- internal
;;;
;;; Delete a backup file. Used during CLOSE.
;;;
(defun delete-original (filename original)
(declare (type simple-base-string filename)
(type (or simple-base-string null) original))
(when original
(multiple-value-bind (okay err) (unix:unix-unlink original)
(unless okay
(cerror "Go on as if nothing bad happened."
"Could not delete ~S during close of ~S: ~A"
original filename (unix:get-unix-error-msg err))))))
;;; FD-STREAM-MISC-ROUTINE -- input
;;;
;;; Handle the various misc operations on fd-stream.
;;;
(defun fd-stream-misc-routine (stream operation &optional arg1 arg2)
(or (not (eql (fd-stream-ibuf-head stream)
(fd-stream-ibuf-tail stream)))
(fd-stream-listen stream)
(setf (fd-stream-listen stream)
(eql (alien:with-alien ((read-fds (alien:struct unix:fd-set)))
(unix:fd-zero read-fds)
(unix:fd-set (fd-stream-fd stream) read-fds)
(unix:unix-fast-select (1+ (fd-stream-fd stream))
(alien:addr read-fds) nil nil
0 0))
1))))
(setf (fd-stream-unread stream) arg1)
(setf (fd-stream-listen stream) t))
(:close
(cond (arg1
;; We got us an abort on our hands.
(when (fd-stream-handler stream)
(system:remove-fd-handler (fd-stream-handler stream))
(setf (fd-stream-handler stream) nil))
(when (and (fd-stream-file stream) (fd-stream-obuf-sap stream))
(revert-file (fd-stream-file stream)
(fd-stream-original stream))))
(when (fd-stream-delete-original stream)
(delete-original (fd-stream-file stream)
(fd-stream-original stream)))))
(when (fboundp 'cancel-finalization)
(cancel-finalization stream))
(when (fd-stream-obuf-sap stream)
(push (fd-stream-obuf-sap stream) *available-buffers*)
(setf (fd-stream-obuf-sap stream) nil))
(when (fd-stream-ibuf-sap stream)
(push (fd-stream-ibuf-sap stream) *available-buffers*)
(setf (fd-stream-ibuf-sap stream) nil))
(:clear-input
(setf (fd-stream-unread stream) nil)
(setf (fd-stream-ibuf-head stream) 0)
(setf (fd-stream-ibuf-tail stream) 0)
(multiple-value-bind
(count errno)
(alien:with-alien ((read-fds (alien:struct unix:fd-set)))
(unix:fd-zero read-fds)
(unix:fd-set (fd-stream-fd stream) read-fds)
(unix:unix-fast-select (1+ (fd-stream-fd stream))
(alien:addr read-fds) nil nil 0 0))
(cond ((eql count 1)
(do-input stream)
(setf (fd-stream-ibuf-head stream) 0)
(setf (fd-stream-ibuf-tail stream) 0))
((and (not count) (eql errno unix:eintr)))
(:force-output
(flush-output-buffer stream))
(:finish-output
(flush-output-buffer stream)
(do ()
((null (fd-stream-output-later stream)))
(system:serve-all-events)))
(:element-type
(fd-stream-element-type stream))
(:interactive-p
(unix:unix-isatty (fd-stream-fd stream)))
(:line-length
80)
(:charpos
(fd-stream-char-pos stream))
(:file-length
(unless (fd-stream-file stream)
(error 'simple-type-error
:datum stream
:expected-type 'file-stream
:format-control "~s is not a stream associated with a file."
:format-arguments (list stream)))
(multiple-value-bind
(okay dev ino mode nlink uid gid rdev size
atime mtime ctime blksize blocks)
(declare (ignore ino nlink uid gid rdev
atime mtime ctime blksize blocks))
(unless okay
(error 'simple-file-error
:format-control "Error fstating ~S: ~A"
:format-arguments (list stream (unix:get-unix-error-msg dev))))
(if (zerop mode)
(values (truncate size (fd-stream-element-size stream))))))
(fd-stream-file-position stream arg1))))
;;; FD-STREAM-FILE-POSITION -- internal.
;;;
(defun fd-stream-file-position (stream &optional newpos)
(declare (type fd-stream stream)
(type (or (integer 0) (member nil :start :end)) newpos))
;; First, find the position of the UNIX file descriptor in the file.
(posn errno)
(unix:unix-lseek (fd-stream-fd stream) 0 unix:l_incr)
(declare (type (or (integer 0) null) posn))
(cond (posn
;; Adjust for buffered output:
;; If there is any output buffered, the *real* file position
;; will be larger than reported by lseek because lseek
;; sent yet.
(dolist (later (fd-stream-output-later stream))
(incf posn (- (the index (caddr later))
(the index (cadr later)))))
(incf posn (fd-stream-obuf-tail stream))
;; Adjust for unread input:
;; If there is any input read from UNIX but not supplied to
;; the user of the stream, the *real* file position will
;; smaller than reported, because we want to look like the
;; unread stuff is still available.
(decf posn (- (fd-stream-ibuf-tail stream)
(fd-stream-ibuf-head stream)))
(when (fd-stream-unread stream)
(decf posn))
;; Divide bytes by element size.
(truncate posn (fd-stream-element-size stream)))
nil)
(t
(system:with-interrupts
(error "Error lseek'ing ~S: ~A"
stream
(let ((offset 0)
origin)
(declare (type (integer 0) offset))
;; Make sure we don't have any output pending, because if we move the
;; file pointer before writing this stuff, it will be written in the
;; wrong location.
(flush-output-buffer stream)
(do ()
((null (fd-stream-output-later stream)))
(system:serve-all-events))
;; Clear out any pending input to force the next read to go to the
;; disk.
(setf (fd-stream-unread stream) nil)
(setf (fd-stream-ibuf-head stream) 0)
(setf (fd-stream-ibuf-tail stream) 0)
;; Trash cached value for listen, so that we check next time.
(setf (fd-stream-listen stream) nil)
(setf offset 0
origin unix:l_set))
(setf offset 0
origin unix:l_xtnd))
((typep newpos '(integer 0))
(t
(error "Invalid position given to file-position: ~S" newpos)))
(multiple-value-bind
(posn errno)
(unix:unix-lseek (fd-stream-fd stream) offset origin)
;;;; Creation routines (MAKE-FD-STREAM and OPEN)
;;; MAKE-FD-STREAM -- Public.
;;;
;;; Returns a FD-STREAM on the given file.
;;;
(defun make-fd-stream (fd
&key
(input nil input-p)
(output nil output-p)
timeout
pathname
(format nil "descriptor ~D" fd)))
auto-close)
(declare (type index fd) (type (or index null) timeout)
(type (member :none :line :full) buffering))
"Create a stream for the given unix file descriptor.
If input is non-nil, allow input operations.
If output is non-nil, allow output operations.
If neither input nor output are specified, default to allowing input.
Element-type indicates the element type to use (as for open).
Buffering indicates the kind of buffering to use.
Timeout (if true) is the number of seconds to wait for input. If NIL (the
default), then wait forever. When we time out, we signal IO-TIMEOUT.
File is the name of the file (will be returned by PATHNAME).
Name is used to identify the stream when printed."
(cond ((not (or input-p output-p))
(setf input t))
((not (or input output))
(error "File descriptor must be opened either for input or output.")))
(let ((stream (%make-fd-stream :fd fd
:name name
:file file
:original original
:delete-original delete-original
:pathname pathname
:buffering buffering
:timeout timeout)))
(set-routines stream element-type input output input-buffer-p)
(when (and auto-close (fboundp 'finalize))
(finalize stream
#'(lambda ()
(format *terminal-io* "** Closed ~A~%" name)
(when original
(revert-file file original)))))
;;; PICK-BACKUP-NAME -- internal
;;;
;;; Pick a name to use for the backup file.
;;;
(defvar *backup-extension* ".BAK"
"This is a string that OPEN tacks on the end of a file namestring to produce
a name for the :if-exists :rename-and-delete and :rename options. Also,
this can be a function that takes a namestring and returns a complete
namestring.")
;;;
(defun pick-backup-name (name)
(declare (type simple-string name))
(let ((ext *backup-extension*))
(etypecase ext
(simple-string (concatenate 'simple-string name ext))
(function (funcall ext name)))))
;;; NEXT-VERSION -- internal
;;;
;;; Find the next available versioned name for a file.
;;;
(defun next-version (name)
(declare (type simple-string name))
(let* ((sep (position #\/ name :from-end t))
(base (if sep (subseq name 0 (1+ sep)) ""))
(dir (unix:open-dir base)))
(multiple-value-bind (name type version)
(extract-name-type-and-version name (if sep (1+ sep) 0) (length name))
(let ((version (if (symbolp version) 1 (1+ version)))
(match (if type
(concatenate 'string name "." type ".~")
(concatenate 'string name ".~"))))
(when dir
(unwind-protect
(loop
(let ((name (unix:read-dir dir)))
(cond ((null name) (return))
((and (> (length name) (length match))
(string= name match :end1 (length match)))
(multiple-value-bind (v e)
(parse-integer name :start (length match)
:junk-allowed t)
(when (and v
(= (length name) (1+ e))
(char= (schar name e) #\~))
(setq version (max version (1+ v)))))))))
(unix:close-dir dir)))
(concatenate 'string base
match (quick-integer-to-string version) "~")))))
;;; ASSURE-ONE-OF -- internal
;;;
;;; Assure that the given arg is one of the given list of valid things.
;;; Allow the user to fix any problems.
;;;
(defun assure-one-of (item list what)
(unless (member item list)
(loop
(cerror "Enter new value for ~*~S"
"~S is invalid for ~S. Must be one of~{ ~S~}"
item
what
list)
(format (the stream *query-io*) "Enter new value for ~S: " what)
(force-output *query-io*)
(setf item (read *query-io*))
(when (member item list)
(return))))
item)
;;; DO-OLD-RENAME -- Internal
;;;
;;; Rename Namestring to Original. First, check if we have write access,
;;; since we don't want to trash unwritable files even if we technically can.
;;;
(defun do-old-rename (namestring original)
(unless (unix:unix-access namestring unix:w_ok)
(cerror "Try to rename it anyway." "File ~S is not writable." namestring))
(multiple-value-bind
(okay err)
(cond (okay t)
(t
(cerror "Use :SUPERSEDE instead."
"Could not rename ~S to ~S: ~A."
namestring
original
;;; FD-OPEN -- Internal
;;;
;;; Open a file.
;;;
(defun fd-open (pathname direction if-exists if-exists-given
if-does-not-exist if-does-not-exist-given)
(declare (type pathname pathname)
(type (member :input :output :io :probe) direction)
(type (member :error :new-version :rename :rename-and-delete
:overwrite :append :supersede nil) if-exists)
(type (member :error :create nil) if-does-not-exist))
(multiple-value-bind (input output mask)
(ecase direction
(:input (values t nil unix:o_rdonly))
(:output (values nil t unix:o_wronly))
(:io (values t t unix:o_rdwr))
(:probe (values t nil unix:o_rdonly)))
(declare (type index mask))
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
;; Process if-exists argument if we are doing any output.
(cond (output
(unless if-exists-given
(setf if-exists
(if (eq (pathname-version pathname) :newest)
:new-version
:error)))
(case if-exists
((:error nil)
(setf mask (logior mask unix:o_excl)))
((:new-version :rename :rename-and-delete)
(setf mask (logior mask unix:o_creat)))
(:supersede
(setf mask (logior mask unix:o_trunc)))))
(t
(setf if-exists nil))) ; :ignore-this-arg
(unless if-does-not-exist-given
(setf if-does-not-exist
(cond ((eq direction :input) :error)
((and output
(member if-exists '(:overwrite :append)))
:error)
((eq direction :probe)
nil)
(t
:create))))
(if (eq if-does-not-exist :create)
(setf mask (logior mask unix:o_creat)))
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
(let ((name (cond ((unix-namestring pathname input))
((and input (eq if-does-not-exist :create))
(unix-namestring pathname nil)))))
(let ((original (cond ((eq if-exists :new-version)
(next-version name))
((member if-exists '(:rename :rename-and-delete))
(pick-backup-name name))))
(delete-original (eq if-exists :rename-and-delete))
(mode #o666))
(when original
;; We are doing a :rename or :rename-and-delete.
;; Determine if the file already exists, make sure the original
;; file is not a directory and keep the mode
(let ((exists
(and name
(multiple-value-bind
(okay err/dev inode orig-mode)
(unix:unix-stat name)
(declare (ignore inode)
(type (or index null) orig-mode))
(cond
(okay
(when (and output (= (logand orig-mode #o170000)
#o40000))
(error 'simple-file-error
:pathname pathname
:format-control
"Cannot open ~S for output: Is a directory."
:format-arguments (list name)))
(setf mode (logand orig-mode #o777))
t)
((eql err/dev unix:enoent)
nil)
(t
(error 'simple-file-error
:pathname pathname
:format-control "Cannot find ~S: ~A"
:format-arguments
(list name
(unix:get-unix-error-msg err/dev)))))))))
(unless (and exists
(do-old-rename name original))
(setf original nil)
(setf delete-original nil)
;; In order to use SUPERSEDE instead, we have
;; to make sure unix:o_creat corresponds to
;; if-does-not-exist. unix:o_creat was set
;; before because of if-exists being :rename.
(unless (eq if-does-not-exist :create)
(setf mask (logior (logandc2 mask unix:o_creat)
unix:o_trunc)))
(setf if-exists :supersede))))
;; Okay, now we can try the actual open.
(loop
(multiple-value-bind (fd errno)
(if name
(unix:unix-open name mask mode)
(values nil unix:enoent))
(cond ((fixnump fd)
(when (eq if-exists :append)
(unix:unix-lseek fd 0 unix:l_xtnd)) ; SEEK_END
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
(return (values fd name original delete-original)))
((eql errno unix:enoent)
(case if-does-not-exist
(:error
(cerror "Return NIL."
'simple-file-error
:pathname pathname
:format-control "Error opening ~S, ~A."
:format-arguments
(list pathname
(unix:get-unix-error-msg errno))))
(:create
(cerror "Return NIL."
'simple-file-error
:pathname pathname
:format-control
"Error creating ~S, path does not exist."
:format-arguments (list pathname))))
(return nil))
((eql errno unix:eexist)
(unless (eq nil if-exists)
(cerror "Return NIL."
'simple-file-error
:pathname pathname
:format-control "Error opening ~S, ~A."
:format-arguments
(list pathname
(unix:get-unix-error-msg errno))))
(return nil))
((eql errno unix:eacces)
(cerror "Try again."
'simple-file-error
:pathname pathname
:format-control "Error opening ~S, ~A."
:format-arguments
(list pathname
(unix:get-unix-error-msg errno))))
(t
(cerror "Return NIL."
'simple-file-error
:pathname pathname
:format-control "Error opening ~S, ~A."
:format-arguments
(list pathname
(unix:get-unix-error-msg errno)))
(return nil)))))))))
;;; OPEN-FD-STREAM -- Internal
;;;
;;; Open an fd-stream connected to a file.
;;;
(defun open-fd-stream (pathname &key (direction :input)
(element-type 'base-char)
(if-exists nil if-exists-given)
(if-does-not-exist nil if-does-not-exist-given)
(external-format :default))
(declare (type pathname pathname)
(type (member :input :output :io :probe) direction)
(type (member :error :new-version :rename :rename-and-delete
:overwrite :append :supersede nil) if-exists)
(type (member :error :create nil) if-does-not-exist)
(ignore external-format))
(multiple-value-bind (fd namestring original delete-original)
(fd-open pathname direction if-exists if-exists-given
if-does-not-exist if-does-not-exist-given)
(when fd
(case direction
((:input :output :io)
(make-fd-stream fd
:input (member direction '(:input :io))
:output (member direction '(:output :io))
:element-type element-type
:file namestring
:original original
:delete-original delete-original
:pathname pathname
:input-buffer-p t
:auto-close t))
(:probe
(let ((stream (%make-fd-stream :name namestring :fd fd
:pathname pathname
:element-type element-type)))
(close stream)
stream))))))
;;; OPEN -- public
;;;
;;; Open the given file.
;;;
(defun open (filename &rest options
&key (direction :input)
(element-type 'base-char element-type-given)
(if-exists nil if-exists-given)
(if-does-not-exist nil if-does-not-exist-given)
(external-format :default)
class mapped input-handle output-handle
&allow-other-keys
&aux ; Squelch assignment warning.
(direction direction)
(if-does-not-exist if-does-not-exist)
(if-exists if-exists))
"Return a stream which reads from or writes to Filename.
Defined keywords:
:direction - one of :input, :output, :io, or :probe
:element-type - Type of object to read or write, default BASE-CHAR
:if-exists - one of :error, :new-version, :rename, :rename-and-delete,
:overwrite, :append, :supersede or nil
:if-does-not-exist - one of :error, :create or nil
:external-format - :default
(declare (ignore external-format input-handle output-handle))
;; OPEN signals a file-error if the filename is wild.
(when (wild-pathname-p filename)
(error 'file-error :pathname filename))
;; First, make sure that DIRECTION is valid. Allow it to be changed if not.
(assure-one-of direction
'(:input :output :io :probe)
:direction))
(setf (getf options :direction) direction)
(when (and if-exists-given (member direction '(:output :io)))
(setq if-exists
(assure-one-of if-exists
'(:error :new-version :rename
:rename-and-delete :overwrite
:append :supersede nil)
:if-exists))
(setf (getf options :if-exists) if-exists))
(when if-does-not-exist-given
(setq if-does-not-exist
(assure-one-of if-does-not-exist
'(:error :create nil)
:if-does-not-exist))
(setf (getf options :if-does-not-exist) if-does-not-exist))
(let ((filespec (pathname filename))
(options (copy-list options))
(cond ((eq class 'fd-stream)
(remf options :class)
(remf options :mapped)
(remf options :input-handle)
(remf options :output-handle)
(apply #'open-fd-stream filespec options))
((subtypep class 'stream:simple-stream)
(when element-type-given
(cerror "Do it anyway."
"Can't create simple-streams with an element-type."))
(when (and (eq class 'stream:file-simple-stream) mapped)
(setq class 'stream:mapped-file-simple-stream)
(setf (getf options :class) 'stream:mapped-file-simple-stream))
(when (subtypep class 'stream:file-simple-stream)
(when (eq direction :probe)
(apply #'make-instance class :filename filespec options))
((subtypep class 'ext:fundamental-stream)
(remf options :class)
(remf options :mapped)
(remf options :input-handle)
(remf options :output-handle)
(let ((stream (apply #'open-fd-stream filespec options)))
(when stream
(make-instance class :lisp-stream stream))))
(t
(error "Unable to open streams of class ~S." class)))))
;;;; Initialization.
(defvar *tty* nil
"The stream connected to the controlling terminal or NIL if there is none.")
(defvar *stdin* nil
"The stream connected to the standard input (file descriptor 0).")
(defvar *stdout* nil
"The stream connected to the standard output (file descriptor 1).")
(defvar *stderr* nil
"The stream connected to the standard error output (file descriptor 2).")
;;; STREAM-INIT -- internal interface
;;;
;;; Called when the cold load is first started up.
;;;
(defun stream-init ()
(stream-reinit)
(setf *terminal-io* (make-synonym-stream '*tty*))
(setf *standard-output* (make-synonym-stream '*stdout*))
(setf *standard-input*
(make-two-way-stream (make-synonym-stream '*stdin*)
*standard-output*))
(setf *error-output* (make-synonym-stream '*stderr*))
(setf *query-io* (make-synonym-stream '*terminal-io*))
(setf *trace-output* *standard-output*)
nil)
;;; STREAM-REINIT -- internal interface
;;;
;;; Called whenever a saved core is restarted.
;;;
(defun stream-reinit ()
(setf *available-buffers* nil)
(setf *stdin*
(make-fd-stream 0 :name "Standard Input" :input t :buffering :line))
(setf *stdout*
(make-fd-stream 1 :name "Standard Output" :output t :buffering :line))
(setf *stderr*
(make-fd-stream 2 :name "Standard Error" :output t :buffering :line))
(let ((tty (and (not *batch-mode*)
(unix:unix-open "/dev/tty" unix:o_rdwr #o666))))
(setf *tty*
(if tty
:buffering :line :auto-close t)
(make-two-way-stream *stdin* *stdout*))))
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
nil)
;;;; Beeping.
(defun default-beep-function (stream)
(write-char #\bell stream)
(finish-output stream))
(defvar *beep-function* #'default-beep-function
"This is called in BEEP to feep the user. It takes a stream.")
(defun beep (&optional (stream *terminal-io*))
(funcall *beep-function* stream))
;;; File-Name -- internal interface
;;;
;;; Kind of like File-Position, but is an internal hack used by the filesys
;;; stuff to get and set the file name.
;;;
(defun file-name (stream &optional new-name)
(typecase stream
(stream:simple-stream
(if new-name
(stream::%file-rename stream new-name)
(stream::%file-name stream)))
(fd-stream
(cond (new-name
(setf (fd-stream-pathname stream) new-name)
(setf (fd-stream-file stream)
(unix-namestring new-name nil))
t)
(t
(fd-stream-pathname stream))))))
;;;; Degenerate international character support:
(defun file-string-length (stream object)
(declare (type (or string character) object)
(type (or file-stream broadcast-stream stream:simple-stream) stream))
"Return the delta in Stream's FILE-POSITION that would be caused by writing
Object to Stream. Non-trivial only in implementations that support
international character sets."
(typecase stream
(stream:simple-stream (stream::%file-string-length stream object))
(broadcast-stream
;; CLHS says we must return 1 in this case
1)