BUG: _read() Returns -1 When Reading Last Byte of a SegmentLast reviewed: July 22, 1997Article ID: Q120153 |
1.00 1.50
WINDOWS
kbprg kbbuglist
The information in this article applies to:
SYMPTOMSIf you open a file with _open() specifying O_TEXT mode or letting it default to O_TEXT mode and then you call _read() to read to the last byte of a segment, the _read() function returns -1. Though this return value indicates that an error occurred, the information was read correctly.
CAUSEThe carry flag is unexpectedly set when looking for carriage return, line feed (CR/LF) pairs at 0xFFFF. The Run-Time incorrectly interprets this as an error and returns -1 instead of the number of characters read.
STATUSMicrosoft has confirmed this to be a bug in the products listed above. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONThe following sample code illustrates the problem:
Sample Code
/* Compile options needed: /AL */ #include <stdio.h> #include <fcntl.h> #include <sys\types.h> #include <sys\stat.h> #include <malloc.h> #include <io.h> #include <dos.h> #include <errno.h> int hfIn; int ret_val; char huge* lpcBase; char huge* lpcTest; void main(void) { lpcBase = (char _huge*) halloc(100000L, 1); lpcTest= lpcBase; FP_OFF(lpcTest)= 0xFFFC; // Point to end of the segment. hfIn = open("C:\\config.sys", _O_RDONLY); ret_val = read(hfIn, lpcTest, 4); if (ret_val< 0) { printf ("ret_val = %i indicating Failure Reading to 0xFFFF\n", ret_val); printf ("errno = %d\n", errno); } close(hfIn); } |
Additional reference words: 6.00 6.00a 6.00ax 7.00 7.00a 1.00 1.50
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |