_read(): In _O_TEXT mode make Readfile calls in chunks as big as
possible.
This commit is contained in:
parent
d1fa4b2d73
commit
6fbcacbb92
|
@ -1163,12 +1163,28 @@ int _rmtmp(void)
|
||||||
return num_removed;
|
return num_removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*********************************************************************
|
||||||
|
* (internal) remove_cr
|
||||||
|
*
|
||||||
|
* Remove all \r inplace.
|
||||||
|
* return the number of \r removed
|
||||||
|
*/
|
||||||
|
static unsigned int remove_cr(char *buf, unsigned int count)
|
||||||
|
{
|
||||||
|
unsigned int i, j;
|
||||||
|
|
||||||
|
for (i = 0; i < count; i++) if (buf[i] == '\r') break;
|
||||||
|
for (j = i + 1; j < count; j++) if (buf[j] != '\r') buf[i++] = buf[j];
|
||||||
|
return count - i;
|
||||||
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* _read (MSVCRT.@)
|
* _read (MSVCRT.@)
|
||||||
*/
|
*/
|
||||||
int _read(int fd, void *buf, unsigned int count)
|
int _read(int fd, void *buf, unsigned int count)
|
||||||
{
|
{
|
||||||
DWORD num_read;
|
DWORD num_read, all_read =0;
|
||||||
|
char *bufstart = buf;
|
||||||
HANDLE hand = msvcrt_fdtoh(fd);
|
HANDLE hand = msvcrt_fdtoh(fd);
|
||||||
|
|
||||||
/* Dont trace small reads, it gets *very* annoying */
|
/* Dont trace small reads, it gets *very* annoying */
|
||||||
|
@ -1177,56 +1193,49 @@ int _read(int fd, void *buf, unsigned int count)
|
||||||
if (hand == INVALID_HANDLE_VALUE)
|
if (hand == INVALID_HANDLE_VALUE)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (MSVCRT_flags[fd]& _O_BINARY)
|
/* Reading single bytes in O_TEXT mode makes things slow
|
||||||
{
|
* So read big chunks, then remove the \r in memory and try reading
|
||||||
if (ReadFile(hand, buf, count, &num_read, NULL))
|
* the rest until the request is satisfied or EOF is met
|
||||||
{
|
*/
|
||||||
if (num_read != count && MSVCRT_files[fd])
|
while ( all_read < count)
|
||||||
{
|
{
|
||||||
TRACE(":EOF\n");
|
if (ReadFile(hand, bufstart+all_read, count - all_read, &num_read, NULL))
|
||||||
MSVCRT_flags[fd] |= MSVCRT__IOEOF;
|
{
|
||||||
/*
|
if (num_read != (count- all_read))
|
||||||
MSVCRT_files[fd]->_flag |= MSVCRT__IOEOF;
|
{
|
||||||
*/
|
TRACE(":EOF\n");
|
||||||
}
|
if ( MSVCRT_files[fd])
|
||||||
TRACE("%s\n",debugstr_an(buf,num_read));
|
{
|
||||||
return num_read;
|
MSVCRT_flags[fd] |= MSVCRT__IOEOF;
|
||||||
}
|
/*
|
||||||
TRACE(":failed-last error (%ld)\n",GetLastError());
|
MSVCRT_files[fd]->_flag |= MSVCRT__IOEOF;
|
||||||
if (MSVCRT_files[fd])
|
*/
|
||||||
MSVCRT_files[fd]->_flag |= MSVCRT__IOERR;
|
}
|
||||||
return -1;
|
if ((MSVCRT_flags[fd]& _O_BINARY ) != _O_BINARY )
|
||||||
}
|
num_read -= remove_cr(bufstart+all_read,num_read);
|
||||||
else
|
all_read += num_read;
|
||||||
{
|
if (count > 4)
|
||||||
char cc, *s=(char*)buf,* buf_start=(char*)buf;
|
TRACE("%s\n",debugstr_an(buf,all_read));
|
||||||
unsigned int i;
|
return all_read;
|
||||||
|
}
|
||||||
for (i = 0 , num_read = 1; i < count && (num_read == 1);)
|
if ((MSVCRT_flags[fd]& _O_BINARY ) != _O_BINARY )
|
||||||
{
|
{
|
||||||
if (ReadFile(hand, &cc, 1, &num_read, NULL))
|
num_read -= remove_cr(bufstart+all_read,num_read);
|
||||||
if (num_read == 1)
|
}
|
||||||
if ((cc != '\r') || MSVCRT_flags[fd] & _O_BINARY)
|
all_read += num_read;
|
||||||
{
|
}
|
||||||
*s++ = (char)cc;
|
else
|
||||||
i++;
|
{
|
||||||
}
|
TRACE(":failed-last error (%ld)\n",GetLastError());
|
||||||
}
|
if (MSVCRT_files[fd])
|
||||||
if (num_read != 1)
|
MSVCRT_files[fd]->_flag |= MSVCRT__IOERR;
|
||||||
{
|
return -1;
|
||||||
TRACE(":EOF\n");
|
}
|
||||||
if (MSVCRT_files[fd])
|
}
|
||||||
MSVCRT_flags[fd] |= MSVCRT__IOEOF;
|
|
||||||
/*
|
if (count > 4)
|
||||||
MSVCRT_files[fd]->_flag |= MSVCRT__IOEOF;
|
TRACE("%s\n",debugstr_an(buf, all_read));
|
||||||
*/
|
return all_read;
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 4)
|
|
||||||
TRACE("%s\n",debugstr_an(buf_start, s-buf_start));
|
|
||||||
return s-buf_start;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
|
Loading…
Reference in New Issue