.title fclose Close a currently-open file .ident /000012/ ;;****************************** ;;***PL/I-COMPATIBLE VERSION**** ;;****************************** ; ;+ ; ; Index Close an open file ; ; Usage ; ; fclose(iop); ; FILE *iop; ; ; Internal ; ; mov #iov,r4 ;r4 -> i/o vector ; mov ,r0 ;r0 == 0 to free i/o vector ; call $$clos ;close file. ; ; mov #iov,r4 ;r4 -> i/o vector ; mov ,r0 ;r0 == 0 to free i/o vector ; call $$fcls ;Free buffer space ; ; Description ; ; Close the file. Returns 0 if ok, -1 if an error. ; The error code is saved in $$ferr. ; ; Note that stderr is never closed. On RT11-mode, the ; last block of a disk file which was open for output ; is filled with nulls. ; ; Internal ; ; $$clos is called internally to close a file. ; ; $$fcls is called internally to free buffer space. ; ; After the file has been closed, record buffers (RSX-mode) ; and the file-name buffer (RT11-mode) will be freed. ; ; If r0 is zero on entry, the iov and any wild-card buffer will ; also be freed. This flag is set non-zero by freopen() or ; fnext() to close a file without freeing the iov. ; ; Bugs ; ;- ; ; Edit history ; 000001 18-May-79 MM Modified for the new library ; 000002 10-Mar-80 MM Modified for the newer library ; 000003 14-Mar-80 MM Added $$fcls entry for fmkdl ; 000004 27-Mar-80 MM Merged libraries ; 000005 21-May-80 MM Added $$clos and iov deletion test ; 000006 11-Jun-80 MM Support for fwild ; 000007 22-Jun-80 MM RT11 and RSX squished together ; Note: edit numbers edited out ; 000008 26-Jun-80 MM Added wild-card buffer removal ; 000009 14-Jul-80 MM Check for file name buffer ; 000010 01-Aug-80 MM Track IOV changes, added $$cflu ; 000011 14-Oct-81 MM Split out $$clfu as a separate program ; 000012 08-Feb-82 MM Incorporate Unimation changes -- close rsx record ; format files in SEEable format. ;;***000013 01-OCT-82 WE PLI-COMPATIBLE VERSION ; .iif ndf rsx rsx = 1 ;Assume RSX11M .if ne rsx .mcall CLOSE$ .iff .mcall .CLOSE .endc .psect .prog. fclose:: jsr r5,csv$ ;Get stack frame. mov #cret$,(sp) ;$$clos returns to caller clr $$ferr ;No errors. mov C$PMTR+0(r5),r4 ;Pick up ioptr. beq errxit ;How can I close nothing? clr r0 ;Dump iov signal $$clos:: cmp r4,stderr ;Stderr never closes beq 12$ ;Just flush if someone tries it ;12 mov r0,-(sp) ;save signal ;;***; ;;***; Do a quick check to see that it's in the Lun table ;;***; ;;*** movb V$LUN(r4),r0 ;Get Lun number ;;*** asl r0 ;* 2 as an index .if ne rsx ;;*** cmp r4,$$luns-4(r0) ;Does it match? ;;***.iff ;;*** cmp r4,$$luns(r0) ;Does it match? .iftf ;;*** beq 10$ ;Keep on trucking if so ;;*** tst (sp)+ ;Pop the stack ;;*** br errxit ;and die ;;*** ;;***10$: bit #VF$TTY,(r4) ;Is it a terminal ;12+ beq 15$ ;Go close if so tst (sp)+ ;yes, pop, the stack. bit #VF$MOD,(r4) ;Is it an output device? beq done ;Skip flush if an input terminal 12$: callr $$flsh ;Output terminal, go flush it and return ;to caller directly. 15$: ;12- bit #VF$OPN,(r4) ;Is it really open? beq noclos ;Skip close if not call $$cflu ;Clean up last record .ift mov r4,r0 ;RSX Make r0 point to add #V$FDB,r0 ;RSX file data block CLOSE$ r0 ;RSX Close it out bcc 20$ ;RSX Good exit movb F.ERR(r0),r0 ;RSX Get error code (sign extended) mov r0,$$ferr ;RSX to error global 20$: .iff bit #VF$TTY,(r4) ;RT11 If it's really a terminal bne noclos ;RT11 Nothing to close .close V$LUN(r4) ;RT11 Close the file .endc noclos: mov (sp)+,r0 ;recover iov dump flag ; ; ; Enter at $$fcls to free up space. r0 is zero to free the iov ; $$fcls:: mov r0,-(sp) ;save signal .if ne rsx mov V$BBUF(r4),r0 ;RSX Block buffer. beq 30$ ;RSX Br if none. call $$free ;RSX Free it. clr V$BBUF(r4) ;RSX Mark no more 30$: mov V$RBUF(r4),r0 ;RSX Record buffer. beq 40$ ;RSX Br if none. call $$free ;RSX Free it clr V$RBUF(r4) ;RSX Mark no more 40$: .iff ;09+ mov V$NAME(r4),r0 ;RT11 File name beq 45$ ;RT11 If it's there ;09- call $$free ;RT11 Now it's gone 45$: ;09 .iftf tst (sp)+ ; keep the iov? bne 60$ ; br if so ;08+ mov V$WILD(r4),r0 ; Wild card buffer beq 50$ ; None present call $$free ; Really none present 50$: ;08- ;;*** movb V$LUN(r4),r0 ; Get the lun ;;*** asl r0 ; as an index ;;*** ;;***.ift ;;*** clr $$luns-4(r0) ;RSX Clear the entry ;;***.iff ;;*** clr $$luns(r0) ;RT11 Clear the entry .endc mov r4,r0 ;Free IOV. movb V$LUN(r0),r1 ;lun, & convert byte to word ;;*** mov r1,(r0) ;use IOV as scratch for PL/I arg;;*** mov r0,-(sp) ;address for PL/I arg ;;*** mov #1,-(sp) ;number of args ;;*** jsr pc,plifp ;get PL/I frame pointer in r4 ;;*** jsr r5,PUTLUN ;call PL/I to free the lun ;;*** call $$free ; ;02 60$: mov $$ferr,r0 ;Return 0 if no errors. ;02 beq done ;Br if all ok. errxit: mov #-1,r0 ;Urk done: return ;return to caller ;05 .end