mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 20:23:34 +00:00
fix all msvcrt file winetests
svn path=/trunk/; revision=43522
This commit is contained in:
parent
821924adcb
commit
2def6506a9
1 changed files with 64 additions and 66 deletions
|
@ -902,10 +902,18 @@ int CDECL fseek(FILE* file, long offset, int whence)
|
||||||
{
|
{
|
||||||
/* Flush output if needed */
|
/* Flush output if needed */
|
||||||
if(file->_flag & _IOWRT)
|
if(file->_flag & _IOWRT)
|
||||||
flush_buffer(file);
|
flush_buffer(file);
|
||||||
|
|
||||||
if(whence == SEEK_CUR && file->_flag & _IOREAD ) {
|
if(whence == SEEK_CUR && file->_flag & _IOREAD ) {
|
||||||
offset -= file->_cnt;
|
offset -= file->_cnt;
|
||||||
|
if (fdesc[file->_file].wxflag & WX_TEXT) {
|
||||||
|
/* Black magic correction for CR removal */
|
||||||
|
int i;
|
||||||
|
for (i=0; i<file->_cnt; i++) {
|
||||||
|
if (file->_ptr[i] == '\n')
|
||||||
|
offset--;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* Discard buffered input */
|
/* Discard buffered input */
|
||||||
file->_cnt = 0;
|
file->_cnt = 0;
|
||||||
|
@ -1556,27 +1564,6 @@ int CDECL _rmtmp(void)
|
||||||
return num_removed;
|
return num_removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
|
||||||
* (internal) remove_cr
|
|
||||||
*
|
|
||||||
* Translate all \r\n to \n inplace.
|
|
||||||
* return the number of \r removed
|
|
||||||
* Corner cases required by some apps:
|
|
||||||
* \r\r\n -> \r\n
|
|
||||||
* BUG: should save state across calls somehow, so CR LF that
|
|
||||||
* straddles buffer boundary gets recognized properly?
|
|
||||||
*/
|
|
||||||
static unsigned int remove_cr(char *buf, unsigned int count)
|
|
||||||
{
|
|
||||||
unsigned int i, j;
|
|
||||||
|
|
||||||
for (i=0, j=0; j < count; j++)
|
|
||||||
if ((buf[j] != '\r') || ((j+1) < count && buf[j+1] != '\n'))
|
|
||||||
buf[i++] = buf[j];
|
|
||||||
|
|
||||||
return count - i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
* (internal) read_i
|
* (internal) read_i
|
||||||
*/
|
*/
|
||||||
|
@ -1604,18 +1591,25 @@ static int read_i(int fd, void *buf, unsigned int count)
|
||||||
{
|
{
|
||||||
if (fdesc[fd].wxflag & WX_TEXT)
|
if (fdesc[fd].wxflag & WX_TEXT)
|
||||||
{
|
{
|
||||||
int i;
|
DWORD i, j;
|
||||||
/* in text mode, a ctrl-z signals EOF */
|
for (i=0, j=0; i<num_read; i++)
|
||||||
for (i=0; i<num_read; i++)
|
|
||||||
{
|
{
|
||||||
|
/* in text mode, a ctrl-z signals EOF */
|
||||||
if (bufstart[i] == 0x1a)
|
if (bufstart[i] == 0x1a)
|
||||||
{
|
{
|
||||||
num_read = i;
|
|
||||||
fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF);
|
fdesc[fd].wxflag |= (WX_ATEOF|WX_READEOF);
|
||||||
TRACE(":^Z EOF %s\n",debugstr_an(buf,num_read));
|
TRACE(":^Z EOF %s\n",debugstr_an(buf,num_read));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
/* in text mode, strip \r if followed by \n.
|
||||||
|
* BUG: should save state across calls somehow, so CR LF that
|
||||||
|
* straddles buffer boundary gets recognized properly?
|
||||||
|
*/
|
||||||
|
if ((bufstart[i] != '\r')
|
||||||
|
|| ((i+1) < num_read && bufstart[i+1] != '\n'))
|
||||||
|
bufstart[j++] = bufstart[i];
|
||||||
}
|
}
|
||||||
|
num_read = j;
|
||||||
}
|
}
|
||||||
if (count != 0 && num_read == 0)
|
if (count != 0 && num_read == 0)
|
||||||
{
|
{
|
||||||
|
@ -1650,10 +1644,6 @@ int CDECL _read(int fd, void *buf, unsigned int count)
|
||||||
{
|
{
|
||||||
int num_read;
|
int num_read;
|
||||||
num_read = read_i(fd, buf, count);
|
num_read = read_i(fd, buf, count);
|
||||||
if (num_read>0 && fdesc[fd].wxflag & WX_TEXT)
|
|
||||||
{
|
|
||||||
num_read -= remove_cr(buf,num_read);
|
|
||||||
}
|
|
||||||
return num_read;
|
return num_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1955,17 +1945,13 @@ int CDECL fgetc(FILE* file)
|
||||||
{
|
{
|
||||||
unsigned char *i;
|
unsigned char *i;
|
||||||
unsigned int j;
|
unsigned int j;
|
||||||
do {
|
if (file->_cnt>0) {
|
||||||
if (file->_cnt>0) {
|
file->_cnt--;
|
||||||
file->_cnt--;
|
i = (unsigned char *)file->_ptr++;
|
||||||
i = (unsigned char *)file->_ptr++;
|
j = *i;
|
||||||
j = *i;
|
} else
|
||||||
} else
|
j = _filbuf(file);
|
||||||
j = _filbuf(file);
|
return j;
|
||||||
if (!(fdesc[file->_file].wxflag & WX_TEXT)
|
|
||||||
|| ((j != '\r') || (file->_cnt && file->_ptr[0] != '\n')))
|
|
||||||
return j;
|
|
||||||
} while(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************
|
/*********************************************************************
|
||||||
|
@ -2300,11 +2286,13 @@ int CDECL _flsbuf(int c, FILE* file)
|
||||||
}
|
}
|
||||||
if(file->_bufsiz) {
|
if(file->_bufsiz) {
|
||||||
int res=flush_buffer(file);
|
int res=flush_buffer(file);
|
||||||
return res?res : fputc(c, file);
|
return res?res : fputc(c, file);
|
||||||
} else {
|
} else {
|
||||||
unsigned char cc=c;
|
unsigned char cc=c;
|
||||||
int len;
|
int len;
|
||||||
len = _write(file->_file, &cc, 1);
|
/* set _cnt to 0 for unbuffered FILEs */
|
||||||
|
file->_cnt = 0;
|
||||||
|
len = _write(file->_file, &cc, 1);
|
||||||
if (len == 1) return c & 0xff;
|
if (len == 1) return c & 0xff;
|
||||||
file->_flag |= _IOERR;
|
file->_flag |= _IOERR;
|
||||||
return EOF;
|
return EOF;
|
||||||
|
@ -2336,8 +2324,6 @@ size_t CDECL fread(void *ptr, size_t size, size_t nmemb, FILE* file)
|
||||||
memcpy(ptr, file->_ptr, pcnt);
|
memcpy(ptr, file->_ptr, pcnt);
|
||||||
file->_cnt -= pcnt;
|
file->_cnt -= pcnt;
|
||||||
file->_ptr += pcnt;
|
file->_ptr += pcnt;
|
||||||
if (fdesc[file->_file].wxflag & WX_TEXT)
|
|
||||||
pcnt -= remove_cr(ptr,pcnt);
|
|
||||||
read += pcnt ;
|
read += pcnt ;
|
||||||
rcnt -= pcnt ;
|
rcnt -= pcnt ;
|
||||||
ptr = (char*)ptr + pcnt;
|
ptr = (char*)ptr + pcnt;
|
||||||
|
@ -2493,17 +2479,26 @@ int CDECL fsetpos(FILE* file, const fpos_t *pos)
|
||||||
*/
|
*/
|
||||||
LONG CDECL ftell(FILE* file)
|
LONG CDECL ftell(FILE* file)
|
||||||
{
|
{
|
||||||
|
/* TODO: just call fgetpos and return lower half of result */
|
||||||
int off=0;
|
int off=0;
|
||||||
long pos;
|
long pos;
|
||||||
if(file->_bufsiz) {
|
|
||||||
if( file->_flag & _IOWRT ) {
|
|
||||||
off = file->_ptr - file->_base;
|
|
||||||
} else {
|
|
||||||
off = -file->_cnt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pos = _tell(file->_file);
|
pos = _tell(file->_file);
|
||||||
if(pos == -1) return pos;
|
if(pos == -1) return -1;
|
||||||
|
if(file->_bufsiz) {
|
||||||
|
if( file->_flag & _IOWRT ) {
|
||||||
|
off = file->_ptr - file->_base;
|
||||||
|
} else {
|
||||||
|
off = -file->_cnt;
|
||||||
|
if (fdesc[file->_file].wxflag & WX_TEXT) {
|
||||||
|
/* Black magic correction for CR removal */
|
||||||
|
int i;
|
||||||
|
for (i=0; i<file->_cnt; i++) {
|
||||||
|
if (file->_ptr[i] == '\n')
|
||||||
|
off--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return off + pos;
|
return off + pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2512,22 +2507,25 @@ LONG CDECL ftell(FILE* file)
|
||||||
*/
|
*/
|
||||||
int CDECL fgetpos(FILE* file, fpos_t *pos)
|
int CDECL fgetpos(FILE* file, fpos_t *pos)
|
||||||
{
|
{
|
||||||
/* This code has been lifted form the ftell function */
|
|
||||||
int off=0;
|
int off=0;
|
||||||
|
|
||||||
*pos = _lseeki64(file->_file,0,SEEK_CUR);
|
*pos = _lseeki64(file->_file,0,SEEK_CUR);
|
||||||
|
if(*pos == -1) return -1;
|
||||||
if (*pos == -1) return -1;
|
|
||||||
|
|
||||||
if(file->_bufsiz) {
|
if(file->_bufsiz) {
|
||||||
if( file->_flag & _IOWRT ) {
|
if( file->_flag & _IOWRT ) {
|
||||||
off = file->_ptr - file->_base;
|
off = file->_ptr - file->_base;
|
||||||
} else {
|
} else {
|
||||||
off = -file->_cnt;
|
off = -file->_cnt;
|
||||||
}
|
if (fdesc[file->_file].wxflag & WX_TEXT) {
|
||||||
|
/* Black magic correction for CR removal */
|
||||||
|
int i;
|
||||||
|
for (i=0; i<file->_cnt; i++) {
|
||||||
|
if (file->_ptr[i] == '\n')
|
||||||
|
off--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*pos += off;
|
*pos += off;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue