Mail Archives: djgpp-workers/2001/02/26/10:45:36
On Mon, 26 Feb 2001, Bruno Haible wrote:
> > > # define setmode(fd, mode) do { \
> > > if (!isatty ((fd))) \
> > > setmode ((fd), mode); \
> > > } while (0)
> >
> > This will only DTRT if this macro is called _only_ for switching
> > stdin/stdout to binary mode and back. If you ever call the macro on a
> > handle other than 0 or 1, it might silently do nothing without a good
> > reason.
>
> Does this mean your isatty() function is broken?
No, I don't think isatty is broken in DJGPP.
> Note that the real
> test, namely INT 44,00 and checking two bits, is not found in your code.
>
> #define get_handle_info(handle) \
> ({ uint16_t __info; \
> __asm__ ( \
> " pushl %%ebx ;" \
> " movw %1,%%bx ; movw $0x4400,%%ax ; int $0x21 ;" \
> " popl %%ebx " \
> : "=d" /* %dx */ (__info) \
> : "ri" ((uint16_t)(handle)) \
> : "ax","cx","si","di" /* %eax,%ecx,%esi,%edi */ \
> ); \
> __info; \
> })
>
> if ((get_handle_info(0) & 0x81) == 0x81)
>
> if ((get_handle_info(1) & 0x82) == 0x82)
Where is this code from? That's not a DJGPP code.
Here's the code of DJGPP's isatty, sans the copyright stuff and the
include files:
int
isatty(int fd)
{
__dpmi_regs r;
r.x.ax = 0x4400;
r.x.bx = fd;
__dpmi_int(0x21, &r);
if ((r.x.ax & 0x83) == 0x83)
return 1;
return 0;
}
0x83 checks the character device and stdin/stdout bits of the device
status word.
Anyway, the issue I referred to was not in isatty, but in setmode.
setmode treats handle 0 specially, and doesn't look at the stdin/stdout
bits at all.
- Raw text -