From: H. Peter Anvin Date: Wed, 27 Feb 2008 03:57:26 +0000 (-0800) Subject: getc: support for unknown file sizes X-Git-Tag: syslinux-3.70-pre1~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=95df473c076649078c291bf0c6ffb2a367f6829a;p=profile%2Fivi%2Fsyslinux.git getc: support for unknown file sizes Handle unknown file sizes in getc --- diff --git a/getc.inc b/getc.inc index eddba80..b36115c 100644 --- a/getc.inc +++ b/getc.inc @@ -23,12 +23,11 @@ MAX_GETC equ (1 << MAX_GETC_LG2) bytes_per_getc_lg2 equ 16-MAX_GETC_LG2 bytes_per_getc equ (1 << bytes_per_getc_lg2) secs_per_getc equ bytes_per_getc/SECTOR_SIZE -MAX_UNGET equ 5 ; Max bytes that can be pushed back +MAX_UNGET equ 9 ; Max bytes that can be pushed back struc getc_file gc_file resw 1 ; File pointer gc_bufbytes resw 1 ; Bytes left in buffer -gc_bytes resd 1 ; Bytes left in file gc_bufdata resw 1 ; Pointer to data in buffer gc_unget_cnt resb 1 ; Character pushed back count gc_unget_buf resb MAX_UNGET ; Character pushed back buffer @@ -73,7 +72,6 @@ openfd: mov [CurrentGetC],bx mov [bx+gc_file],si ; File pointer - mov [bx+gc_bytes],eax ; Bytes available xor ax,ax mov [bx+gc_bufbytes],ax ; Buffer empty mov [bx+gc_unget_cnt],al ; ungetc buffer empty @@ -132,27 +130,22 @@ getc: mov [di+gc_bufdata],bx mov si,[di+gc_file] - mov ecx,[di+gc_bytes] - jecxz .empty - cmp ecx,bytes_per_getc - jna .sizeok - mov ecx,bytes_per_getc -.sizeok: - mov [di+gc_bufbytes],cx - sub [di+gc_bytes],ecx - add cx,SECTOR_SIZE-1 - shr cx,SECTOR_SHIFT + and si,si + mov [di+gc_bufbytes],si ; In case SI == 0 + jz .empty + mov cx,bytes_per_getc >> SECTOR_SHIFT call getfssec + mov [di+gc_bufbytes],cx mov [di+gc_file],si + jcxz .empty popad + TRACER 'd' jmp .got_data .empty: - ; CX == 0 at this point; gc_bufbytes was clobbered - ; by the subtract; we need to restore it to zero so - ; we will continue to get EOF on any further attempts - ; to read the file. - mov [di+gc_bufbytes],cx + TRACER 'e' + ; [di+gc_bufbytes] is zero already, thus we will continue + ; to get EOF on any further attempts to read the file. popad xor al,al ; Return a predictable zero stc