;;; -*- Mode: Common-Lisp; Package: FS; Base: 10.; Patch-File: T -*-

;;; Reason:  Fixed FILE-POSITION to handle position option :end. [10726]

;;;                           RESTRICTED RIGHTS LEGEND
;;;
;;; Use, duplication, or disclosure by the Government is subject to
;;; restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
;;; Technical Data and Computer Software clause at 52.227-7013.
;;;
;;;   TEXAS INSTRUMENTS INCORPORATED      
;;;   P.O. BOX 2909, M/S 2151             
;;;   AUSTIN, TEXAS 78769                 
;;;
;;; Copyright (C) 1989 Texas Instruments Incorporated.
;;; All rights reserved.

;;; Written 10/24/89 15:44:30 by BERGER,
;;; while running on ARIES from band LODX
;;; With SYSTEM 6.22, VIRTUAL-MEMORY 6.2, EH 6.5, MAKE-SYSTEM 6.2, MICRONET 6.0, LOCAL-FILE 6.1,
;;;  BASIC-PATHNAME 6.2, NETWORK-SUPPORT-COLD 6.2, BASIC-NAMESPACE 6.6, NETWORK-NAMESPACE 6.0,
;;;  DISK-IO 6.1, DISK-LABEL 6.0, BASIC-FILE 6.4, MAC-PATHNAME 6.0, NETWORK-PATHNAME 6.0,
;;;  COMPILER 6.14, TV 6.17, DATALINK 6.0, CHAOSNET 6.1, GC 6.3, MEMORY-AUX 6.0, NVRAM 6.2,
;;;  SYSLOG 6.2, STREAMER-TAPE 6.4, UCL 6.0, INPUT-EDITOR 6.0, METER 6.1, ZWEI 6.7,
;;;  DEBUG-TOOLS 6.3, NETWORK-SUPPORT 6.0, NETWORK-SERVICE 6.2, DATALINK-DISPLAYS 6.0,
;;;  FONT-EDITOR 6.1, SERIAL 6.0, PRINTER 6.3, MAC-PRINTER-TYPES 6.1, PRINTER-TYPES 6.2,
;;;  IMAGEN 6.1, SUGGESTIONS 6.1, MAIL-DAEMON 6.3, MAIL-READER 6.5, TELNET 6.0, VT100 6.0,
;;;  NAMESPACE-EDITOR 6.4, PROFILE 6.2, VISIDOC 6.5, TI-CLOS 6.26, CLEH 6.5, IP 3.54,
;;;  Experimental CLX 6.6, CLUE 6.27, X11M 6.15, Experimental BUG 11.15,  microcode 429,
;;;  Band Name: rel6.0 10/23

#!C
; From file OPEN.LISP#> BASIC-FILE; sys:
#10R FILE-SYSTEM#:
(COMPILER-LET ((*PACKAGE* (FIND-PACKAGE "FILE-SYSTEM"))
                          (SI:*LISP-MODE* :COMMON-LISP)
                          (*READTABLE* COMMON-LISP-READTABLE)
                          (SI:*READER-SYMBOL-SUBSTITUTIONS* SYS::*COMMON-LISP-SYMBOL-SUBSTITUTIONS*))
  (COMPILER#:PATCH-SOURCE-FILE "SYS: BASIC-FILE; OPEN.#"


(DEFUN FILE-POSITION (FILE-STREAM &OPTIONAL NEW-POSITION)
  "Return or set the stream pointer of FILE-STREAM.
With one argument, return the stream pointer of FILE-STREAM, or NIL if not known.
With two argumens, try set the stream pointer to NEW-POSITION
 and return T if it was really possible to do so."
  (IF NEW-POSITION
      (let ((read-tyi nil) results)  ; DAB 10-24-89
	(setf results  ; DAB 10-24-89
	      (IF (SEND FILE-STREAM :SEND-IF-HANDLES :SET-POINTER
			(CASE NEW-POSITION
			  (:START 0.)
			  (:END
			   ;;DAB 10-24-89 Some input stream will not allow up to set-pointer to the value returned
                           ;;by file-length because it is beyond the end of the file. So in this case let's set the pointer
                           ;;to one less, then later do a tyi to get to EOF. This will also what for IO streams.
			   (if (send file-stream :operation-handled-p :tyi)
			       (progn (setf read-tyi t)
				      (1- (file-length file-stream)))
			       (file-length file-stream)))
			  (T NEW-POSITION)))
		  T
		  ())
	      ) ;setf 
	(when read-tyi (send file-stream :tyi)) ; DAB 10-24-89
	results) ; DAB 10-24-89
      
      (SEND FILE-STREAM :SEND-IF-HANDLES :READ-POINTER))
  )
))
