コード例 #1
0
ファイル: fileio.c プロジェクト: A1DEVS/lenovo_a1_07_uboot
/****************************************************************************
REMARKS:
VxD implementation of the ANSI C fread function. Note that the VxD file I/O
functions are layered on DOS, so can only read up to 64K at a time. Since
we are expected to handle much larger chunks than this, we handle larger
blocks automatically in here.
****************************************************************************/
size_t fread(
    void *ptr,
    size_t size,
    size_t n,
    FILE *f)
{
    char    *buf = ptr;
    WORD    error;
    int     bytes = size * n;
    int     readbytes,totalbytes = 0;

    while (bytes > 0x10000) {
	if (initComplete) {
	    readbytes  = R0_ReadFile(false,(HANDLE)f->handle,buf,0x8000,f->offset,&error);
	    readbytes += R0_ReadFile(false,(HANDLE)f->handle,buf+0x8000,0x8000,f->offset+0x8000,&error);
	    }
	else {
	    readbytes  = i_read(f->handle,buf,0x8000);
	    readbytes += i_read(f->handle,buf+0x8000,0x8000);
	    }
	totalbytes += readbytes;
	f->offset += readbytes;
	buf += 0x10000;
	bytes -= 0x10000;
	}
    if (bytes) {
	if (initComplete)
	    readbytes = R0_ReadFile(false,(HANDLE)f->handle,buf,bytes,f->offset,&error);
	else
	    readbytes = i_read(f->handle,buf,bytes);
	totalbytes += readbytes;
	f->offset += readbytes;
	}
    return totalbytes / size;
}
コード例 #2
0
ファイル: fileio.c プロジェクト: OS2World/LIB-VIDEO-MGL
/****************************************************************************
REMARKS:
VxD implementation of the ANSI C fread function. Note that the VxD file I/O
functions are layered on DOS, so can only read up to 64K at a time. Since
we are expected to handle much larger chunks than this, we handle larger
blocks automatically in here.
****************************************************************************/
size_t fread(
	void *ptr,
	size_t size,
	size_t n,
	FILE *f)
{
	char	*buf = ptr;
	WORD 	error;
	int		bytes,readbytes,totalbytes = 0;

	/* First copy any data already read into our buffer */
	if ((bytes = (f->curp - f->startp)) > 0) {
		memcpy(buf,f->curp,bytes);
		f->startp = f->curp = f->buf;
		buf += bytes;
		totalbytes += bytes;
		bytes = (size * n) - bytes;
		}
	else
		bytes = size * n;
	while (bytes > 0x10000) {
		if (initComplete) {
			readbytes  = R0_ReadFile(false,(HANDLE)f->handle,buf,0x8000,f->offset,&error);
			readbytes += R0_ReadFile(false,(HANDLE)f->handle,buf+0x8000,0x8000,f->offset+0x8000,&error);
			}
		else {
			readbytes  = i_read(f->handle,buf,0x8000);
			readbytes += i_read(f->handle,buf+0x8000,0x8000);
			}
		totalbytes += readbytes;
		f->offset += readbytes;
		buf += 0x10000;
		bytes -= 0x10000;
		}
	if (bytes) {
		if (initComplete)
			readbytes = R0_ReadFile(false,(HANDLE)f->handle,buf,bytes,f->offset,&error);
		else
			readbytes = i_read(f->handle,buf,bytes);
		totalbytes += readbytes;
		f->offset += readbytes;
		}
	return totalbytes / size;
}