--- fhandler.cc 1997/03/05 21:50:29 1.1 +++ fhandler.cc 1997/03/17 21:57:47 @@ -2227,16 +2568,22 @@ debug_printf("FakeReadFile, res = %d, flags = %x\n", res, flags); /* if things are special, just do what we used to */ - if ((!res) - || (flags & ENABLE_LINE_INPUT) - || (ov != 0)) + if ((!res) || (ov !=0)) + { + return ReadFile (hndl, pv, lenin, done, ov); + } + if (flags & ENABLE_LINE_INPUT) { + FlushConsoleInputBuffer(hndl); return ReadFile (hndl, pv, lenin, done, ov); } /* otherwise, do something that works */ unsigned int num_events = 0, ne2, st; + if(ndelay_set == 1) + need_chars=0; + st = GetNumberOfConsoleInputEvents (hndl, &num_events); debug_printf("FakeReadFile, GetNumberOfConsoleInputEvents returned = %d\n", st); @@ -2252,8 +2599,16 @@ /* so are we blocking or what? FIONBIO isn't implemented... */ /* either spin here and read at least one thing, return none... */ /* readfile blocks already, so we probably can't do worse... */ + + if(ndelay_set == 1) + { + need_chars = 0; + } + else + { need_chars = 1; } + } INPUT_RECORD input_rec; @@ -2267,6 +2622,7 @@ return 0; /* seems to be failure */ } /* doc says it will return at least one event... */ + if (num_events) num_events--; /* check if we're just disposing of this one */ @@ -2332,7 +2688,18 @@ need_chars = 0; } *done = copied_chars; - return 1; /* success == true */ + + /* if we haven't got anything of interest, and we don't want to wait for + anything (O_NDELAY is set) force the calling read to error (ret 0) */ + + if (copied_chars == 0 && need_chars == 0) + { + return 0; + } + else + { + return 1; + } /* success == true */ } int --- fhandler.h 1997/03/05 22:43:17 1.2 +++ fhandler.h 1997/03/17 22:05:19 @@ -21,6 +21,8 @@ #include +extern int ndelay_set; /* for fcntl O_NDELAY in FakeReadFile */ + /* Classes fhandler_base normal I/O --- fcntl.cc 1997/03/17 04:26:20 1.1 +++ fcntl.cc 1997/03/17 21:41:35 @@ -20,6 +20,8 @@ #include #include "winsup.h" +int ndelay_set; + extern "C" int _fcntl (int fd, int cmd,...) @@ -88,6 +90,10 @@ res |= O_WRONLY; if (this_procinfo ()->hmap[fd].h->get_access () & GENERIC_ALL) res |= O_RDWR; + if (ndelay_set) + res |= O_NDELAY; + syscall_printf ("fcntl (F_GETFL, %d);\n", res); + goto done; case F_SETFL: @@ -101,6 +107,14 @@ temp |= GENERIC_READ; if (arg & O_WRONLY) temp |= GENERIC_WRITE; + if (arg & O_NDELAY) + { + ndelay_set = 1; + } + else + { + ndelay_set = 0; + } syscall_printf ("fcntl (%d, F_SETFL, %d);\n", arg);