Mail Archives: djgpp/1999/03/08/17:16:27
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 <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>
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;
}
- Raw text -