diff --git a/reactos/lib/msvcrt/io/read.c b/reactos/lib/msvcrt/io/read.c index 77e56050d8f..6515ffdaca0 100644 --- a/reactos/lib/msvcrt/io/read.c +++ b/reactos/lib/msvcrt/io/read.c @@ -1,7 +1,7 @@ /* * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS system libraries - * FILE: lib/crtdll/io/read.c + * FILE: lib/msvcrt/io/read.c * PURPOSE: Reads a file * PROGRAMER: Boudewijn Dekker * UPDATE HISTORY: @@ -9,14 +9,45 @@ */ #include #include +#include + +#define NDEBUG +#include size_t _read(int _fd, void *_buf, size_t _nbyte) { - DWORD _rbyte; - - if (!ReadFile(_get_osfhandle(_fd),_buf,_nbyte,&_rbyte,NULL)) - { - return -1; - } - return (size_t)_rbyte; + DWORD _rbyte = 0, nbyte = _nbyte, count; + int cr; + char *bufp = (char*)_buf; + + DPRINT("_read(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte); + + 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; }