2014-09-21 11:37:38 +00:00
|
|
|
; int __cdecl fclose(FILE *fp)
|
2014-11-05 17:20:02 +00:00
|
|
|
_fclose proc
|
2014-09-21 11:37:38 +00:00
|
|
|
@@res = word ptr -2
|
|
|
|
@@fp = dword ptr 6
|
|
|
|
|
|
|
|
push bp
|
|
|
|
mov bp, sp
|
|
|
|
sub sp, 2
|
|
|
|
push si
|
|
|
|
push di
|
|
|
|
mov [bp+@@res], 0FFFFh
|
|
|
|
mov ax, word ptr [bp+@@fp]
|
|
|
|
or ax, word ptr [bp+@@fp+2]
|
|
|
|
jnz short @@verifyToken
|
|
|
|
jmp @@ret
|
|
|
|
|
|
|
|
@@verifyToken:
|
|
|
|
les bx, [bp+@@fp]
|
|
|
|
mov ax, es:[bx+FILE.token]
|
|
|
|
cmp ax, word ptr [bp+@@fp]
|
|
|
|
jz short @@buffered?
|
|
|
|
jmp @@ret
|
|
|
|
|
|
|
|
@@buffered?:
|
|
|
|
les bx, [bp+@@fp]
|
|
|
|
cmp es:[bx+FILE._bsize], 0
|
|
|
|
jz short @@close?
|
|
|
|
cmp es:[bx+FILE.level], 0
|
|
|
|
jge short @@free?
|
|
|
|
push word ptr [bp+@@fp+2]
|
|
|
|
push bx
|
|
|
|
nopcall _fflush
|
|
|
|
pop cx
|
|
|
|
pop cx
|
|
|
|
or ax, ax
|
|
|
|
jnz short @@ret
|
|
|
|
|
|
|
|
@@free?:
|
|
|
|
les bx, [bp+@@fp]
|
|
|
|
test byte ptr es:[bx+FILE.flags], 4
|
|
|
|
jz short @@close?
|
[JWasm move] Fix improper structure declarations
Really, Borland? You considered it necessary to add directives for object-
oriented programming (in Assembly!) and convenience features like bitfield
records or PUSHSTATE/POPSTATE, yet you never came up with the actually
*helpful* idea of just adding a simple basic pointer data type that depends
on the current memory model's data size?
Like, something like DP... oh wait, that's already taken, as an alias for
DF, the 48-bit 80386 far pointer type.
And this, exactly, is the problem with assemblers. The language itself is
undefined beyond the instructions themselves, but it's obviously very
uncomfortable to program anything with just that, so your assembler needs to
add custom directives on top of that, and of course everyone has different
ideas of the features and use cases that should (and should not) be covered by
syntax. (I'm looking especially at you, NASM.)
And then one of those developers sells their compiler division to a different
company, which then subsequently discontinues all products without ever
releasing the source code, trapping their nice extensions in a single
executable for a single platform that is not even legally available anymore.
tl;dr: http://xkcd.com/927/
2014-11-20 03:55:57 +00:00
|
|
|
push word ptr es:[bx+FILE.buffer+2]
|
|
|
|
push word ptr es:[bx+FILE.buffer]
|
2014-09-21 11:37:38 +00:00
|
|
|
nopcall _farfree
|
|
|
|
pop cx
|
|
|
|
pop cx
|
|
|
|
|
|
|
|
@@close?:
|
|
|
|
les bx, [bp+@@fp]
|
|
|
|
cmp es:[bx+FILE.fd], 0
|
|
|
|
jl short @@reset
|
|
|
|
mov al, es:[bx+FILE.fd]
|
|
|
|
cbw
|
|
|
|
push ax
|
|
|
|
nopcall _close
|
|
|
|
pop cx
|
|
|
|
mov [bp+@@res], ax
|
|
|
|
|
|
|
|
@@reset:
|
|
|
|
les bx, [bp+@@fp]
|
|
|
|
mov es:[bx+FILE.flags], 0
|
|
|
|
mov es:[bx+FILE._bsize], 0
|
|
|
|
mov es:[bx+FILE.level], 0
|
|
|
|
mov es:[bx+FILE.fd], -1
|
|
|
|
cmp es:[bx+FILE.istemp], 0
|
|
|
|
jz short @@ret
|
|
|
|
xor ax, ax
|
|
|
|
push ax
|
|
|
|
push ax
|
|
|
|
push ax
|
|
|
|
push ax
|
|
|
|
push es:[bx+FILE.istemp]
|
|
|
|
call __MKNAME
|
|
|
|
push dx
|
|
|
|
push ax
|
|
|
|
nopcall _unlink
|
|
|
|
pop cx
|
|
|
|
pop cx
|
|
|
|
les bx, [bp+@@fp]
|
|
|
|
mov es:[bx+FILE.istemp], 0
|
|
|
|
|
|
|
|
@@ret:
|
|
|
|
mov ax, [bp+@@res]
|
|
|
|
pop di
|
|
|
|
pop si
|
|
|
|
mov sp, bp
|
|
|
|
pop bp
|
|
|
|
ret
|
|
|
|
_fclose endp
|