<p>Hi Vincent & Eliot,</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>I think it is worse than that.  If I use the following test code in a<br>
cygwin terminal:</p>
<pre><code>#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("--\n");
printf("%s\n", buf);
printf("--\n");
printf("Read %d characters\n", count);
exit(0);
}
</code></pre>
<p>And compile it with mingw:</p>
<pre><code>$ i686-w64-mingw32-gcc -m32 consolestdio.c
</code></pre>
<p>It won't recognise EOF (Control-D).</p>
<pre><code>$ ./a.exe
hello world
<Ctrl-D>
asdfasdfasdfasdfasdf
--
hello world

asdf
--
Read 17 characters
Error, not at end of file
</code></pre>
<p>If I compile it with gcc:</p>
<pre><code>$ gcc -m32 consolestdio.c
</code></pre>
<p>It works as expected:</p>
<pre><code>$ ./a.exe
hello world
<Ctrl-D>
--
hello world

--
Read 12 characters
</code></pre>
<p>So the best option I see for supporting both cygwin terminals and dos<br>
boxes is to make our own dll that wraps around the cygwin1.dll functions<br>
and to load it as required.  Although I'm a bit concerned that I haven't<br>
found any mention of doing this elsewhere (and it's a lot of work for<br>
one specific use case).</p>
<blockquote>
<p>But I don't get it.  IIRC, it used to be the case that ReadConsole/WriteConsole worked in both.</p>
</blockquote>
<p>I'd still like to be proved wrong...</p>
<p>Thanks,<br>
Alistair</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you commented.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/254#issuecomment-384886716">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AhLyW8a70wTxstgB0rJS8WqsnS8HOX25ks5tssXZgaJpZM4Tg0qx">mute the thread</a>.<img src="https://github.com/notifications/beacon/AhLyWwMu87ykv3kdrHlifJk3H9foHDqMks5tssXZgaJpZM4Tg0qx.gif" height="1" width="1" alt="" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/254#issuecomment-384886716"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #254: Hi Vincent \u0026 Eliot,\r\n\r\n\u003e 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. \r\n\r\nI think it is worse than that.  If I use the following test code in a \r\ncygwin terminal:\r\n\r\n```\r\n#include \u003cstdio.h\u003e\r\n#include \u003cstdlib.h\u003e\r\n\r\n\r\nint main()\r\n{\r\nchar\tbuf[1024];\r\nchar\t*bufp;\r\nint\tcread;\r\nint\tcount = 0;\r\n\r\nbufp = \u0026buf[0];\r\ndo {\r\n    cread = fread(bufp, 1, 1, stdin);\r\n    count += cread;\r\n    bufp += cread;\r\n    if (count \u003e 16) break; }\r\nwhile (cread \u003e 0);\r\nbuf[count] = 0;\r\n\r\nif (! feof(stdin))\r\n    fprintf(stderr, \"Error, not at end of file\\n\");\r\n\r\nprintf(\"--\\n\");\r\nprintf(\"%s\\n\", buf);\r\nprintf(\"--\\n\");\r\nprintf(\"Read %d characters\\n\", count);\r\nexit(0);\r\n}\r\n```\r\n\r\nAnd compile it with mingw:\r\n\r\n```\r\n$ i686-w64-mingw32-gcc -m32 consolestdio.c\r\n```\r\n\r\nIt won't recognise EOF (Control-D).\r\n\r\n```\r\n$ ./a.exe\r\nhello world\r\n\u003cCtrl-D\u003e\r\nasdfasdfasdfasdfasdf\r\n--\r\nhello world\r\n\r\nasdf\r\n--\r\nRead 17 characters\r\nError, not at end of file\r\n```\r\n\r\n\r\n\r\nIf I compile it with gcc:\r\n\r\n```\r\n$ gcc -m32 consolestdio.c\r\n```\r\n\r\nIt works as expected:\r\n\r\n```\r\n$ ./a.exe\r\nhello world\r\n\u003cCtrl-D\u003e\r\n--\r\nhello world\r\n\r\n--\r\nRead 12 characters\r\n```\r\n\r\n\r\nSo the best option I see for supporting both cygwin terminals and dos\r\nboxes is to make our own dll that wraps around the cygwin1.dll functions\r\nand to load it as required.  Although I'm a bit concerned that I haven't\r\nfound any mention of doing this elsewhere (and it's a lot of work for \r\none specific use case).\r\n\r\n\r\n\r\n\u003e But I don't get it.  IIRC, it used to be the case that ReadConsole/WriteConsole worked in both.\r\n\r\nI'd still like to be proved wrong...\r\n\r\n\r\n\r\nThanks,\r\nAlistair\r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/254#issuecomment-384886716"}}}</script>