3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/msvcrt/io/read.c
6 * PURPOSE: Reads a file
7 * PROGRAMER: Boudewijn Dekker
10 * 03/05/2002: made _read() non-greedy - it now returns as soon as
11 * any amount of data has been read. It's the expected
12 * behavior for line-buffered streams (KJK::Hyperion)
15 #include <msvcrt/io.h>
16 #include <msvcrt/internal/file.h>
19 #include <msvcrt/msvcrtdbg.h>
21 size_t _read(int _fd, void *_buf, size_t _nbyte)
23 DWORD _rbyte = 0, nbyte = _nbyte;
24 char *bufp = (char*)_buf;
28 DPRINT("_read(fd %d, buf %x, nbyte %d)\n", _fd, _buf, _nbyte);
34 hfile = _get_osfhandle(_fd);
35 istext = __fileno_getmode(_fd) & O_TEXT;
38 if (!ReadFile(hfile, bufp, nbyte, &_rbyte, NULL))
41 error = GetLastError();
42 if (error == ERROR_BROKEN_PIPE)
56 /* repeat for all bytes in the buffer */
57 for(; count; bufp++, count--)
83 /* shift characters back, to ignore carriage returns */
92 /* ignore the carriage returns */
95 DPRINT("%d\n", _rbyte);