Corrected mailing lists link
[reactos.git] / reactos / lib / msvcrt / io / read.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/msvcrt/io/read.c
5 * PURPOSE: Reads a file
6 * PROGRAMER: Boudewijn Dekker
7 * UPDATE HISTORY:
8 * 28/12/98: Created
9 */
10 #include <windows.h>
11 #include <msvcrt/io.h>
12 #include <msvcrt/internal/file.h>
13
14 #define NDEBUG
15 #include <msvcrt/msvcrtdbg.h>
16
17 size_t _read(int _fd, void *_buf, size_t _nbyte)
18 {
19 DWORD _rbyte = 0, nbyte = _nbyte, count;
20 int cr;
21 char *bufp = (char*)_buf;
22
23 DPRINT("_read(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
24
25 while (nbyte)
26 {
27 if (!ReadFile(_get_osfhandle(_fd), bufp, nbyte, &_rbyte, NULL))
28 {
29 return -1;
30 }
31 if (_rbyte == 0)
32 break;
33 if (__fileno_getmode(_fd) & O_TEXT)
34 {
35 cr = 0;
36 count = _rbyte;
37 while (count)
38 {
39 if (*bufp == '\r')
40 cr++;
41 else if (cr != 0)
42 *(bufp - cr) = *bufp;
43 bufp++;
44 count--;
45 }
46 _rbyte -= cr;
47 bufp -= cr;
48 }
49 nbyte -= _rbyte;
50 }
51 DPRINT("%d\n", _nbyte - nbyte);
52 return _nbyte - nbyte;
53 }