mirror of
https://github.com/reactos/reactos.git
synced 2025-06-03 08:20:27 +00:00
Added CR-removing for text files.
Added debug messages. svn path=/trunk/; revision=2797
This commit is contained in:
parent
db69b4ae79
commit
e8b5ff7de0
1 changed files with 39 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* COPYRIGHT: See COPYING in the top level directory
|
* COPYRIGHT: See COPYING in the top level directory
|
||||||
* PROJECT: ReactOS system libraries
|
* PROJECT: ReactOS system libraries
|
||||||
* FILE: lib/crtdll/io/read.c
|
* FILE: lib/msvcrt/io/read.c
|
||||||
* PURPOSE: Reads a file
|
* PURPOSE: Reads a file
|
||||||
* PROGRAMER: Boudewijn Dekker
|
* PROGRAMER: Boudewijn Dekker
|
||||||
* UPDATE HISTORY:
|
* UPDATE HISTORY:
|
||||||
|
@ -9,14 +9,45 @@
|
||||||
*/
|
*/
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <msvcrt/io.h>
|
#include <msvcrt/io.h>
|
||||||
|
#include <msvcrt/internal/file.h>
|
||||||
|
|
||||||
|
#define NDEBUG
|
||||||
|
#include <msvcrt/msvcrtdbg.h>
|
||||||
|
|
||||||
size_t _read(int _fd, void *_buf, size_t _nbyte)
|
size_t _read(int _fd, void *_buf, size_t _nbyte)
|
||||||
{
|
{
|
||||||
DWORD _rbyte;
|
DWORD _rbyte = 0, nbyte = _nbyte, count;
|
||||||
|
int cr;
|
||||||
if (!ReadFile(_get_osfhandle(_fd),_buf,_nbyte,&_rbyte,NULL))
|
char *bufp = (char*)_buf;
|
||||||
{
|
|
||||||
return -1;
|
DPRINT("_read(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
|
||||||
}
|
|
||||||
return (size_t)_rbyte;
|
while (nbyte)
|
||||||
|
{
|
||||||
|
if (!ReadFile(_get_osfhandle(_fd), bufp, nbyte, &_rbyte, NULL))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (_rbyte == 0)
|
||||||
|
break;
|
||||||
|
if (__fileno_getmode(_fd) & O_TEXT)
|
||||||
|
{
|
||||||
|
cr = 0;
|
||||||
|
count = _rbyte;
|
||||||
|
while (count)
|
||||||
|
{
|
||||||
|
if (*bufp == '\r')
|
||||||
|
cr++;
|
||||||
|
else if (cr != 0)
|
||||||
|
*(bufp - cr) = *bufp;
|
||||||
|
bufp++;
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
_rbyte -= cr;
|
||||||
|
bufp -= cr;
|
||||||
|
}
|
||||||
|
nbyte -= _rbyte;
|
||||||
|
}
|
||||||
|
DPRINT("%d\n", _nbyte - nbyte);
|
||||||
|
return _nbyte - nbyte;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue