From e8b5ff7de07e563546ae01a4dedd11f15959af82 Mon Sep 17 00:00:00 2001 From: Hartmut Birr Date: Mon, 1 Apr 2002 21:50:56 +0000 Subject: [PATCH] Added CR-removing for text files. Added debug messages. svn path=/trunk/; revision=2797 --- reactos/lib/msvcrt/io/read.c | 47 ++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) 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; }