.NLIST TOC,SYM .TITLE $CLOSE .SBTTL ULBLIB 010 - Close Files .IDENT \V01.01\ .PSECT .LIBC. .ENABL LC,GBL ; Copyright (c) 1998 by Mentec, Inc., Nashua, NH. ; All rights reserved ; ; This software is furnished under a license for use only on a ; single computer system and may be copied only with the ; inclusion of the above copyright notice. This software, or ; any other copies thereof, may not be provided or otherwise ; made available to any other person except for use on such ; system and to one who agrees to these license terms. Title ; to and ownership of the software shall at all times remain ; in Mentec, Inc. ; ; The information in this document is subject to change without ; notice and should not be construed as a commitment by Digital ; Equipment Corporation, or Mentec, Inc. ; ; Digital and Mentec assume no responsibility for the use or ; reliability of its software on equipment which is not supplied ; by Digital or Mentec, and listed in the Software Product ; Description. ; CG01 10-Feb-79 Corrects a buffer flush problem when the output buffer ; is already full. ; CG02 04-Aug-79 Add file protection check. ; CG03 04-Aug-79 Don't purge file structured devices ;+ ; $CLOSE ; The Close Files routine closes open files. If the file is an output ; file, a buffer flush is done first. ; ; R0 -> File Descriptor Block (FDB) ; ; CALL $CLOSE ; ; C-bit = 0 => no error ; ; C-bit = 1 => error ; F.ERR(R0) = error code ;- .MCALL .CLOSE, .WRITW, .PURGE $CLOSE:: CALL $SAVAL MOV R0,R1 ;Copy the FDB pointer MOVB F.IOCH(R1),R3 ;Get the channel number CMPB #F.IOOUT,F.IOCD(R1) ;Is it an output file? BEQ 10$ ;Branch if so. Close it ;CG03+ TSTB F.DVST(R1) ;Is it RT-11 directory structured? BMI 5$ ;Branch if so. Purge the channel. BITB #20,F.DVST(R1) ;Non RT-11 directory structured? BEQ 5$ ;Branch if not. Purge the channel ;CG03- 10$: TST @F.OPNM(R1) ;Is there a file there? BEQ 5$ ;Branch if not... Purge the channel MOV F.IOBF(R1),R5 ;Point to the I/O buffer MOV F.BPTR(R1),R4 ;Get the buffer pointer CMP R4,R5 ;Anything in the buffer? BNE 1$ ;Branch if so. TST F.IOBK(R1) ;Was anything written? BEQ 5$ ;Branch if not 1$: ADD F.BFSZ(R1),R5 ;Get the hi limit of the buffer SUB R4,R5 ;Get the size of the area left BEQ 3$ ;Branch if buffer already full. ;CG01 2$: CLRB (R4)+ ;Clear a byte DEC R5 ;Done? BNE 2$ ;Branch if not 3$: ADD #F.IO.,R0 ;Point to the I/O block .WRITW ;And write BCC 4$ ;Branch if no error JMP $OERR ;Output error 4$: .CLOSE R3 ;Close the channel BCC 6$ ;Branch if no error ;CG02 MOVB #FE.FCP,F.ERR(R1) ;Set the error code ;CG02 BR 6$ ;Return 5$: .PURGE R3 ;Purge the channel CLC ;Indicate success 6$: RETURN .END