diff --git a/kaem.windows.run b/kaem.windows.run index e18c8176..3caa60e5 100755 --- a/kaem.windows.run +++ b/kaem.windows.run @@ -84,6 +84,7 @@ M2-Planet \ -f ${srcdest}lib/linux/malloc.c \ -f ${srcdest}lib/windows/ntdll.c \ -f ${srcdest}lib/string/memset.c \ + -f ${srcdest}lib/windows/_read.c \ -f ${srcdest}lib/windows/read.c \ -f ${srcdest}lib/mes/fdgetc.c \ -f ${srcdest}lib/stdio/getchar.c \ diff --git a/lib/windows/_read.c b/lib/windows/_read.c index fd411091..97596fc6 100644 --- a/lib/windows/_read.c +++ b/lib/windows/_read.c @@ -16,16 +16,34 @@ * You should have received a copy of the GNU General Public License * along with GNU Mes. If not, see . */ - -/* Stands in for lib/linux/_read.c. On Linux _read is the bare SYS_read and - * read is the same call; here read (lib/windows/read.c) is already the bare - * NtReadFile with nothing between, so this is that. */ - +#include +#include #include -#include +#include + +/* Stands in for lib/linux/_read.c: the bare read, with nothing above it. + * configure-lib.sh's lists build read from lib/posix/buffered-read.c, whose + * __buffered_read fills its buffer with this, so this must not call read. + * NtReadFile is NtWriteFile's twin, and an NTSTATUS below zero is how the end + * of the file arrives as much as how a failure does -- both mean nothing more + * was read, which is what a caller of read wants to hear as 0. */ ssize_t _read (int filedes, void *buffer, size_t size) { - return read (filedes, buffer, size); + int NtReadFile; + int *iosb; + int handle; + int rc; + + NtReadFile = __ntdll_resolve ("NtReadFile"); + iosb = __iosb (); + iosb[0] = 0; + iosb[1] = 0; + handle = __handle (filedes); + + rc = __ntcall9 (NtReadFile, handle, 0, 0, 0, iosb, buffer, size, 0, 0); + if (rc < 0) + return 0; + return iosb[1]; } diff --git a/lib/windows/read.c b/lib/windows/read.c index 06d0c1e9..375256c5 100644 --- a/lib/windows/read.c +++ b/lib/windows/read.c @@ -16,32 +16,16 @@ * You should have received a copy of the GNU General Public License * along with GNU Mes. If not, see . */ -#include -#include #include #include -/* Stands in for lib/linux/read.c. NtReadFile is NtWriteFile's twin, and an - * NTSTATUS below zero is how the end of the file arrives as much as how a - * failure does -- both mean nothing more was read, which is what a caller of - * read wants to hear as 0. */ +/* Stands in for lib/linux/read.c, for a build that buffers nothing, as + * kaem.windows.run's does: there read is lib/windows/_read.c's bare + * NtReadFile. configure-lib.sh's lists take read from + * lib/posix/buffered-read.c instead, and do not build this file. */ ssize_t read (int filedes, void *buffer, size_t size) { - int NtReadFile; - int *iosb; - int handle; - int rc; - - NtReadFile = __ntdll_resolve ("NtReadFile"); - iosb = __iosb (); - iosb[0] = 0; - iosb[1] = 0; - handle = __handle (filedes); - - rc = __ntcall9 (NtReadFile, handle, 0, 0, 0, iosb, buffer, size, 0, 0); - if (rc < 0) - return 0; - return iosb[1]; + return _read (filedes, buffer, size); }