Date: Mon, 8 Mar 1999 21:26:33 +0100 From: Frank Heckenbach Message-Id: <124D6181.19990308212633.FOO-19CE.frank@goedel.fjf.gnu.de> X-Mailer: smtphack 0.3.3 by Jan Andres To: djgpp AT delorie DOT com, peter AT gerwinski DOT de Subject: Patch for select() X-Counter: 883 peter AT gerwinski DOT de Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=iso-8859-1 Reply-To: djgpp AT delorie DOT com Hello, while porting some GPC code to DJGPP, I found that select() has different semantics regarding end of file under DJGPP than under Un*x. DJGPP's select() returns `not ready' at the end of a regular file (i.e., no character device under Dos), but select() under Un*x returns `ready' in this situation (verified under Linux and Solaris). DJGPP's behaviour is, of course, due to the behaviour of the Dos interrupt used. The following patch first checks if the file is a regular file and returns `ready' if it is. A small test program (which should write 1) is appended. Frank *** src/libc/compat/time/select.c~ Mon Mar 8 02:32:50 1999 --- src/libc/compat/time/select.c Mon Mar 8 20:32:13 1999 *************** *** 84,89 **** --- 84,103 ---- __dpmi_regs regs; + /* If it's a disk file, always return 1, since according to Un*x + semantics, select() returns ``ready'' at EOF (and before EOF, + anyway). */ + regs.x.ax = 0x4400; + regs.x.bx = fd; + __dpmi_int (0x21, ®s); + if (regs.x.flags & 1) + { + errno = __doserr_to_errno (regs.x.ax); + return -1; + } + if (!(regs.x.dx & 0x80)) + return 1; + regs.x.ax = 0x4406; regs.x.bx = fd; __dpmi_int (0x21, ®s); Test program: #include #include #include #include int main () { fd_set s; struct timeval t = { 0, 0 }; int f = open("foobar", O_RDWR | O_CREAT | O_APPEND, 0666); if (f < 0) abort (); FD_ZERO (&s); FD_SET (f, &s); printf ("%i\n", select (f + 1, &s, NULL, NULL, &t)); return 0; }