Hi Vincent & Eliot,

Ugh. I didn't realize one couldn't use the same code in both :-(. I guess we have to test to find out what the context is and use dread in one and ReadConsole in the other.

I think it is worse than that. If I use the following test code in a
cygwin terminal:

#include <stdio.h>
#include <stdlib.h>

int main()
char	buf[1024];
char	*bufp;
int	cread;
int	count = 0;

bufp = &buf[0];
do {
    cread = fread(bufp, 1, 1, stdin);
    count += cread;
    bufp += cread;
    if (count > 16) break; }
while (cread > 0);
buf[count] = 0;

if (! feof(stdin))
    fprintf(stderr, "Error, not at end of file\n");

printf("%s\n", buf);
printf("Read %d characters\n", count);

And compile it with mingw:

$ i686-w64-mingw32-gcc -m32 consolestdio.c

It won't recognise EOF (Control-D).

$ ./a.exe
hello world
hello world

Read 17 characters
Error, not at end of file

If I compile it with gcc:

$ gcc -m32 consolestdio.c

It works as expected:

$ ./a.exe
hello world
hello world

Read 12 characters

So the best option I see for supporting both cygwin terminals and dos
boxes is to make our own dll that wraps around the cygwin1.dll functions
and to load it as required. Although I'm a bit concerned that I haven't
found any mention of doing this elsewhere (and it's a lot of work for
one specific use case).

But I don't get it. IIRC, it used to be the case that ReadConsole/WriteConsole worked in both.

I'd still like to be proved wrong...


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.