Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

We don't know one millionth of one percent about anything.


devel / comp.lang.c / ot: on stdin, stdout, stderr and crlf on windows

SubjectAuthor
* ot: on stdin, stdout, stderr and crlf on windowsMeredith Montgomery
+- Re: ot: on stdin, stdout, stderr and crlf on windowsMike Terry
+* Re: ot: on stdin, stdout, stderr and crlf on windowsMike Terry
|`* Re: ot: on stdin, stdout, stderr and crlf on windowsMeredith Montgomery
| +- Re: ot: on stdin, stdout, stderr and crlf on windowsKeith Thompson
| `* Re: ot: on stdin, stdout, stderr and crlf on windowsMike Terry
|  `- Re: ot: on stdin, stdout, stderr and crlf on windowsMeredith Montgomery
+- Re: ot: on stdin, stdout, stderr and crlf on windowsBonita Montero
+* Re: ot: on stdin, stdout, stderr and crlf on windowsBonita Montero
|`* Re: ot: on stdin, stdout, stderr and crlf on windowsJohn Forkosh
| +- Re: ot: on stdin, stdout, stderr and crlf on windowsBonita Montero
| `* Re: ot: on stdin, stdout, stderr and crlf on windowsBen Bacarisse
|  `* Re: ot: on stdin, stdout, stderr and crlf on windowsBonita Montero
|   `* Re: ot: on stdin, stdout, stderr and crlf on windowsBen Bacarisse
|    +* Re: ot: on stdin, stdout, stderr and crlf on windowsManfred
|    |+* Re: ot: on stdin, stdout, stderr and crlf on windowsMalcolm McLean
|    ||`- Re: ot: on stdin, stdout, stderr and crlf on windowsManfred
|    |`* Re: ot: on stdin, stdout, stderr and crlf on windowsBen Bacarisse
|    | `- Re: ot: on stdin, stdout, stderr and crlf on windowsScott Lurndal
|    `* Re: ot: on stdin, stdout, stderr and crlf on windowsJohn Forkosh
|     `* Re: ot: on stdin, stdout, stderr and crlf on windowsBart
|      `- Re: ot: on stdin, stdout, stderr and crlf on windowsJohn Forkosh
`* Re: ot: on stdin, stdout, stderr and crlf on windowsTim Rentsch
 `- Re: ot: on stdin, stdout, stderr and crlf on windowsKenny McCormack

1
ot: on stdin, stdout, stderr and crlf on windows

<86fsr8uf6a.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19269&group=comp.lang.c#19269

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!KxJZyxgbHwhKzYAX04rqlQ.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: ot: on stdin, stdout, stderr and crlf on windows
Date: Sat, 04 Dec 2021 20:24:29 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86fsr8uf6a.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="22862"; posting-host="KxJZyxgbHwhKzYAX04rqlQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:iw5sSSLxFk6Yo/sdNUdAtPlzrcg=
 by: Meredith Montgomery - Sat, 4 Dec 2021 23:24 UTC

I know this isn't C. I'm not aware of any group like
comp.windows.programmer. If there is one, I'd appreciate if you set the
follow-up-to header. Thank you.

Windows provides me _setmode(), with which I can put stdout on
_O_BINARY. It then stops replacing \n with \r\n. However, it seems
that Windows does not do any such replacements on stdin and stderr. I
looked for a confirmation of this apparent fact and could not find it.

Can you advise? I don't see the replacements taking place; only on
stdout it seems to happen.

I'm not sure how to prove that. Here's my attempt. This program below
shows all bytes it reads from stdin.

C:\tmp>cat show-c.c
#include <stdio.h>

int main() {
int c;
while ( (c = getchar()) != EOF) {
printf("%d", c);
}
printf("\n");
}

C:\tmp>show-c.exe < empty.txt
10

So empty.txt must contain at least byte 10. But if Windows were fixing
my line-terminations, it should have added a byte 13 (on my back).

Perhaps I just proved that Windows is not replacing anything on my
stdin.

(*) Not sure of the relevance of this

C:\tmp>file show-c
show-c: PE32+ executable (console) x86-64, for MS Windows

Thank you so much.

Re: ot: on stdin, stdout, stderr and crlf on windows

<KICdnYDLlcjYnDH8nZ2dnUU78WXNnZ2d@brightview.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19270&group=comp.lang.c#19270

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!buffer1.nntp.ams1.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 04 Dec 2021 18:01:09 -0600
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Newsgroups: comp.lang.c
References: <86fsr8uf6a.fsf@levado.to>
From: news.dea...@darjeeling.plus.com (Mike Terry)
Date: Sun, 5 Dec 2021 00:01:08 +0000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7.1
MIME-Version: 1.0
In-Reply-To: <86fsr8uf6a.fsf@levado.to>
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <KICdnYDLlcjYnDH8nZ2dnUU78WXNnZ2d@brightview.co.uk>
Lines: 41
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-uSZ1euTJXnYzriQnakIlQOckMxaDu5T8VWYN++iIsmAbk6ZhnU1DAQRnYMZYAy1SKIncQsDMcdhhB61!0fX0kGnb57wBXU98276VJn9FA6Wf2I6fChVNgyyiK5J2CF5LjFbUK4G48vTwKEqjAJcSfxsocVod!3r2fQMZ+cpqHafXj395nkbkWGqM=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2396
 by: Mike Terry - Sun, 5 Dec 2021 00:01 UTC

On 04/12/2021 23:24, Meredith Montgomery wrote:
> I know this isn't C. I'm not aware of any group like
> comp.windows.programmer. If there is one, I'd appreciate if you set the
> follow-up-to header. Thank you.
>
> Windows provides me _setmode(), with which I can put stdout on
> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
> that Windows does not do any such replacements on stdin and stderr. I
> looked for a confirmation of this apparent fact and could not find it.
>
> Can you advise? I don't see the replacements taking place; only on
> stdout it seems to happen.

Not sure of the proper group. Anyway, have you read the _setmode()
documentation?


<https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode>

That page contains a code example to change stdin to binary - exactly
what you're after.

>
> I'm not sure how to prove that. Here's my attempt. This program below
> shows all bytes it reads from stdin.
>
> C:\tmp>cat show-c.c
> #include <stdio.h>
>
> int main() {
> int c;
> while ( (c = getchar()) != EOF) {
> printf("%d", c);
> }
> printf("\n");
> }

Um, there's no call to _setmode() in your code. :)

Mike.

Re: ot: on stdin, stdout, stderr and crlf on windows

<-56dnQtxBsW3mTH8nZ2dnUU78RnNnZ2d@brightview.co.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19271&group=comp.lang.c#19271

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!border2.nntp.ams1.giganews.com!nntp.giganews.com!buffer2.nntp.ams1.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 04 Dec 2021 18:13:30 -0600
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Newsgroups: comp.lang.c
References: <86fsr8uf6a.fsf@levado.to>
From: news.dea...@darjeeling.plus.com (Mike Terry)
Date: Sun, 5 Dec 2021 00:13:29 +0000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7.1
MIME-Version: 1.0
In-Reply-To: <86fsr8uf6a.fsf@levado.to>
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <-56dnQtxBsW3mTH8nZ2dnUU78RnNnZ2d@brightview.co.uk>
Lines: 52
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-uaYyKayFVay4JTXZUGGt14AjrUNtBLaRjmTdDCzILZVFKwD1QmDMLZKrH6HdEroqnF963r+uRncqNZs!/CQ+ONWOeKOF5pm4rk3ik2IuBeeK8IvI52WD/Q0GcwxDDQdfOeBydvPs3/wvPE8pgoyqMmIYvQEm!rZd03fsrrmsJt55qDgIs3XOglKs=
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
X-Original-Bytes: 2883
 by: Mike Terry - Sun, 5 Dec 2021 00:13 UTC

On 04/12/2021 23:24, Meredith Montgomery wrote:
> I know this isn't C. I'm not aware of any group like
> comp.windows.programmer. If there is one, I'd appreciate if you set the
> follow-up-to header. Thank you.
>
> Windows provides me _setmode(), with which I can put stdout on
> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
> that Windows does not do any such replacements on stdin and stderr. I
> looked for a confirmation of this apparent fact and could not find it.
>
> Can you advise? I don't see the replacements taking place; only on
> stdout it seems to happen.
>
> I'm not sure how to prove that. Here's my attempt. This program below
> shows all bytes it reads from stdin.
>
> C:\tmp>cat show-c.c
> #include <stdio.h>
>
> int main() {
> int c;
> while ( (c = getchar()) != EOF) {
> printf("%d", c);
> }
> printf("\n");
> }
>
> C:\tmp>show-c.exe < empty.txt
> 10
>
> So empty.txt must contain at least byte 10. But if Windows were fixing
> my line-terminations, it should have added a byte 13 (on my back).

This is backwards - by default Windows (well, VC++ compiler at least)
assumes text lines end CR LF (decimal values 13, 10). The default text
mode will convert CR LF to just LF, which you are seeing above -
presumably empty.txt has just a single empty line terminated by CR LF ??
If you set the stdin mode to binary you should then expect output "1310".

Mike.

>
> Perhaps I just proved that Windows is not replacing anything on my
> stdin.
>
> (*) Not sure of the relevance of this
>
> C:\tmp>file show-c
> show-c: PE32+ executable (console) x86-64, for MS Windows
>
> Thank you so much.
>

Re: ot: on stdin, stdout, stderr and crlf on windows

<86zgpfsszj.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19272&group=comp.lang.c#19272

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!KxJZyxgbHwhKzYAX04rqlQ.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Sat, 04 Dec 2021 23:09:04 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86zgpfsszj.fsf@levado.to>
References: <86fsr8uf6a.fsf@levado.to>
<-56dnQtxBsW3mTH8nZ2dnUU78RnNnZ2d@brightview.co.uk>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="49937"; posting-host="KxJZyxgbHwhKzYAX04rqlQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Cancel-Lock: sha1:3Kn5hWDQLiDt3voMiHcPJLUh4RY=
X-Notice: Filtered by postfilter v. 0.9.2
 by: Meredith Montgomery - Sun, 5 Dec 2021 02:09 UTC

Mike Terry <news.dead.person.stones@darjeeling.plus.com> writes:

> On 04/12/2021 23:24, Meredith Montgomery wrote:
>> I know this isn't C. I'm not aware of any group like
>> comp.windows.programmer. If there is one, I'd appreciate if you set the
>> follow-up-to header. Thank you.
>> Windows provides me _setmode(), with which I can put stdout on
>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>> that Windows does not do any such replacements on stdin and stderr.

Sorry. It does happen on stderr. (And now I understand what I missed
about stdin. See below.) And thank you, Mike Terry.

>> I looked for a confirmation of this apparent fact and could not find
>> it. Can you advise? I don't see the replacements taking place; only
>> on stdout it seems to happen. I'm not sure how to prove that.
>> Here's my attempt. This program below shows all bytes it reads from
>> stdin. C:\tmp>cat show-c.c #include <stdio.h> int main() { int c;
>> while ( (c = getchar()) != EOF) { printf("%d", c); } printf("\n"); }
>> C:\tmp>show-c.exe < empty.txt 10 So empty.txt must contain at least
>> byte 10. But if Windows were fixing my line-terminations, it should
>> have added a byte 13 (on my back).
>
> This is backwards - by default Windows (well, VC++ compiler at least)
> assumes text lines end CR LF (decimal values 13, 10). The default
> text mode will convert CR LF to just LF, which you are seeing above -
> presumably empty.txt has just a single empty line terminated by CR LF
> ?? If you set the stdin mode to binary you should then expect output
> "1310".

You're right. The Windows situation is reversed when we deal with
stdin. If I input \r\n, it replaces to \n if in _O_TEXT. I totally
missed that indeed because --- well, it's so confusing. Thank you.

By the way, because I used write() and saw the translations taking
place, I conclude the kernel is doing these translations, not the local
C library.

Re: ot: on stdin, stdout, stderr and crlf on windows

<87tufneqg5.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19273&group=comp.lang.c#19273

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Sat, 04 Dec 2021 18:27:38 -0800
Organization: None to speak of
Lines: 40
Message-ID: <87tufneqg5.fsf@nosuchdomain.example.com>
References: <86fsr8uf6a.fsf@levado.to>
<-56dnQtxBsW3mTH8nZ2dnUU78RnNnZ2d@brightview.co.uk>
<86zgpfsszj.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="191039e3b5f31276b5881eab1e06ee6f";
logging-data="16360"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UvIMyKQ7HqmOqUK03AFdN"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:bvQZsDL8b8yAJlghbtViMUOH16E=
sha1:Um2U5uYLVOO/qTldLJjsj3pwIMY=
 by: Keith Thompson - Sun, 5 Dec 2021 02:27 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:
[...]
> You're right. The Windows situation is reversed when we deal with
> stdin. If I input \r\n, it replaces to \n if in _O_TEXT. I totally
> missed that indeed because --- well, it's so confusing. Thank you.

It's not too confusing once you understand it.

On UNIX, C's original home, text files use LF (ASCII 0x0a), and only
LF, to mark the end of a line in a text file. So you can read raw
data from a text file and assume that an LF character always marks
the end of a line, and write raw data to a text file and be sure
that each LF written will mark the end of a line.

Other systems use different conventions. MS-DOS and Windows use
a CR-LF pair, and other systems use other character combinations
or more complicated schemes. C's <stdio.h> is designed to map all
those variations to a single scheme of using '\n'. So on input,
the OS's end-of-line marker, whatever it is, is tranlated to '\n',
and on output '\n' is translated to the OS's end-of-line marker.

stdin, stdout, and stderr are all text streams, so operations on them
all perform this mapping, one way or the other.

> By the way, because I used write() and saw the translations taking
> place, I conclude the kernel is doing these translations, not the local
> C library.

I wouldn't assume that. On Linux/Unix systems, write is usually a
system call implemented by the kernel. (POSIX just says it's a
function, but it happens to be implemented as a system call on most
Unix-like systems). On Windows, the write() function is probably
implemented on top of lower-level Windows calls. On systems where
write() is a system call, it doesn't transform end-of-line markers
because it doesn't need to.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: ot: on stdin, stdout, stderr and crlf on windows

<sohbtp$s2p$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19274&group=comp.lang.c#19274

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!CC3uK9WYEoa7s1kzH7komw.user.46.165.242.75.POSTED!not-for-mail
From: news.dea...@darjeeling.plus.com (Mike Terry)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Sun, 5 Dec 2021 03:33:12 +0000
Organization: Aioe.org NNTP Server
Message-ID: <sohbtp$s2p$1@gioia.aioe.org>
References: <86fsr8uf6a.fsf@levado.to>
<-56dnQtxBsW3mTH8nZ2dnUU78RnNnZ2d@brightview.co.uk>
<86zgpfsszj.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="28761"; posting-host="CC3uK9WYEoa7s1kzH7komw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101
Firefox/60.0 SeaMonkey/2.53.7.1
X-Notice: Filtered by postfilter v. 0.9.2
 by: Mike Terry - Sun, 5 Dec 2021 03:33 UTC

On 05/12/2021 02:09, Meredith Montgomery wrote:
> Mike Terry <news.dead.person.stones@darjeeling.plus.com> writes:
>
>> On 04/12/2021 23:24, Meredith Montgomery wrote:
>>> I know this isn't C. I'm not aware of any group like
>>> comp.windows.programmer. If there is one, I'd appreciate if you set the
>>> follow-up-to header. Thank you.
>>> Windows provides me _setmode(), with which I can put stdout on
>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>> that Windows does not do any such replacements on stdin and stderr.
>
> Sorry. It does happen on stderr. (And now I understand what I missed
> about stdin. See below.) And thank you, Mike Terry.
>
>>> I looked for a confirmation of this apparent fact and could not find
>>> it. Can you advise? I don't see the replacements taking place; only
>>> on stdout it seems to happen. I'm not sure how to prove that.
>>> Here's my attempt. This program below shows all bytes it reads from
>>> stdin. C:\tmp>cat show-c.c #include <stdio.h> int main() { int c;
>>> while ( (c = getchar()) != EOF) { printf("%d", c); } printf("\n"); }
>>> C:\tmp>show-c.exe < empty.txt 10 So empty.txt must contain at least
>>> byte 10. But if Windows were fixing my line-terminations, it should
>>> have added a byte 13 (on my back).
>>
>> This is backwards - by default Windows (well, VC++ compiler at least)
>> assumes text lines end CR LF (decimal values 13, 10). The default
>> text mode will convert CR LF to just LF, which you are seeing above -
>> presumably empty.txt has just a single empty line terminated by CR LF
>> ?? If you set the stdin mode to binary you should then expect output
>> "1310".
>
> You're right. The Windows situation is reversed when we deal with
> stdin. If I input \r\n, it replaces to \n if in _O_TEXT. I totally
> missed that indeed because --- well, it's so confusing. Thank you.
>
> By the way, because I used write() and saw the translations taking
> place, I conclude the kernel is doing these translations, not the local
> C library.

On Windows the low level OS APIs for file IO are ReadFile[Ex] and
WriteFile[Ex]. These do not know about line endings, or whether the
files are ANSI/Unicode etc., they just read/write a block of data.
Functions like read() write() are part of the CRT, and will internally
end up calling ReadFile/WriteFile or one of their variants.

Regards,
Mike.

>

Re: ot: on stdin, stdout, stderr and crlf on windows

<86ee6rs0tl.fsf@levado.to>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19275&group=comp.lang.c#19275

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!jc5As+G8VRX/g1ebGCnpVw.user.46.165.242.75.POSTED!not-for-mail
From: mmontgom...@levado.to (Meredith Montgomery)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Sun, 05 Dec 2021 09:17:26 -0300
Organization: Aioe.org NNTP Server
Message-ID: <86ee6rs0tl.fsf@levado.to>
References: <86fsr8uf6a.fsf@levado.to>
<-56dnQtxBsW3mTH8nZ2dnUU78RnNnZ2d@brightview.co.uk>
<86zgpfsszj.fsf@levado.to> <sohbtp$s2p$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: gioia.aioe.org; logging-data="34119"; posting-host="jc5As+G8VRX/g1ebGCnpVw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
X-Notice: Filtered by postfilter v. 0.9.2
Cancel-Lock: sha1:W3CF7qex/P4gJmikuvr4utZU3iM=
 by: Meredith Montgomery - Sun, 5 Dec 2021 12:17 UTC

Mike Terry <news.dead.person.stones@darjeeling.plus.com> writes:

[...]

>>>> I looked for a confirmation of this apparent fact and could not find
>>>> it. Can you advise? I don't see the replacements taking place; only
>>>> on stdout it seems to happen. I'm not sure how to prove that.
>>>> Here's my attempt. This program below shows all bytes it reads from
>>>> stdin. C:\tmp>cat show-c.c #include <stdio.h> int main() { int c;
>>>> while ( (c = getchar()) != EOF) { printf("%d", c); } printf("\n"); }
>>>> C:\tmp>show-c.exe < empty.txt 10 So empty.txt must contain at least
>>>> byte 10. But if Windows were fixing my line-terminations, it should
>>>> have added a byte 13 (on my back).
>>>
>>> This is backwards - by default Windows (well, VC++ compiler at least)
>>> assumes text lines end CR LF (decimal values 13, 10). The default
>>> text mode will convert CR LF to just LF, which you are seeing above -
>>> presumably empty.txt has just a single empty line terminated by CR LF
>>> ?? If you set the stdin mode to binary you should then expect output
>>> "1310".
>> You're right. The Windows situation is reversed when we deal with
>> stdin. If I input \r\n, it replaces to \n if in _O_TEXT. I totally
>> missed that indeed because --- well, it's so confusing. Thank you.
>> By the way, because I used write() and saw the translations taking
>> place, I conclude the kernel is doing these translations, not the local
>> C library.
>
> On Windows the low level OS APIs for file IO are ReadFile[Ex] and
> WriteFile[Ex]. These do not know about line endings, or whether the
> files are ANSI/Unicode etc., they just read/write a block of
> data. Functions like read() write() are part of the CRT, and will
> internally end up calling ReadFile/WriteFile or one of their variants.

Interesting info. Thanks so much.

Re: ot: on stdin, stdout, stderr and crlf on windows

<soigsp$7dd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19276&group=comp.lang.c#19276

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Sun, 5 Dec 2021 15:04:09 +0100
Organization: A noiseless patient Spider
Lines: 4
Message-ID: <soigsp$7dd$1@dont-email.me>
References: <86fsr8uf6a.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 5 Dec 2021 14:04:09 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="51d59cdcc3e92f362e003a3793866a86";
logging-data="7597"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TbCBSV6Si4QGgLm7u84xU89Vy4YqIqaI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:PBMVT9eJQ1Dv5BnMvp7UEWFCWDQ=
In-Reply-To: <86fsr8uf6a.fsf@levado.to>
Content-Language: de-DE
 by: Bonita Montero - Sun, 5 Dec 2021 14:04 UTC

Eh,
_setmode( _fileno( stdin ), _O_BINARY );
/ _setmode( _fileno( stderr ), _O_BINARY );

Re: ot: on stdin, stdout, stderr and crlf on windows

<soiheo$jo9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19277&group=comp.lang.c#19277

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Sun, 5 Dec 2021 15:13:44 +0100
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <soiheo$jo9$1@dont-email.me>
References: <86fsr8uf6a.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 5 Dec 2021 14:13:44 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="51d59cdcc3e92f362e003a3793866a86";
logging-data="20233"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+dbFay1RGkP3xzErqdCdzK6d8mEuZ8Uto="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:y0uLaOBWv3rOvP0qzRA4FbzT/4Y=
In-Reply-To: <86fsr8uf6a.fsf@levado.to>
Content-Language: de-DE
 by: Bonita Montero - Sun, 5 Dec 2021 14:13 UTC

Am 05.12.2021 um 00:24 schrieb Meredith Montgomery:
> I know this isn't C. I'm not aware of any group like
> comp.windows.programmer. If there is one, I'd appreciate if you set the
> follow-up-to header. Thank you.
>
> Windows provides me _setmode(), with which I can put stdout on
> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
> that Windows does not do any such replacements on stdin and stderr. I
> looked for a confirmation of this apparent fact and could not find it.
>
> Can you advise? I don't see the replacements taking place; only on
> stdout it seems to happen.
>
> I'm not sure how to prove that. Here's my attempt. This program below
> shows all bytes it reads from stdin.
>
> C:\tmp>cat show-c.c
> #include <stdio.h>
>
> int main() {
> int c;
> while ( (c = getchar()) != EOF) {
> printf("%d", c);
> }
> printf("\n");
> }
>
> C:\tmp>show-c.exe < empty.txt
> 10
>
> So empty.txt must contain at least byte 10. But if Windows were fixing
> my line-terminations, it should have added a byte 13 (on my back).
>
> Perhaps I just proved that Windows is not replacing anything on my
> stdin.
>
> (*) Not sure of the relevance of this
>
> C:\tmp>file show-c
> show-c: PE32+ executable (console) x86-64, for MS Windows
>
> Thank you so much.

Check the output of this in your hex-editor:

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

int main( int argc, char **argv )
{ if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
return EXIT_FAILURE;
fprintf( stderr, "it works !\n" );
}

Without a commandline-parameter you've 0x0D, 0x0A
as a line-separator, with you've got only 0x0A.

Re: ot: on stdin, stdout, stderr and crlf on windows

<sokh4l$8l2$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19280&group=comp.lang.c#19280

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: fork...@panix.com (John Forkosh)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 6 Dec 2021 08:20:37 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <sokh4l$8l2$1@reader1.panix.com>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
Injection-Date: Mon, 6 Dec 2021 08:20:37 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="8866"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: John Forkosh - Mon, 6 Dec 2021 08:20 UTC

Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Meredith Montgomery wrote:
>>
>> Windows provides me _setmode(), with which I can put stdout on
>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>> that Windows does not do any such replacements on stdin and stderr. I
>> looked for a confirmation of this apparent fact and could not find it.
<<snip>>
>
> Check the output of this in your hex-editor:
>
> #include <stdio.h>
> #include <fcntl.h>
> #include <io.h>
> #include <stdlib.h>
>
> int main( int argc, char **argv )
> {
> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
> return EXIT_FAILURE;
> fprintf( stderr, "it works !\n" );
> }
>
> Without a commandline-parameter you've 0x0D, 0x0A
> as a line-separator, with you've got only 0x0A.

Yeah, that's more or less what I've been doing, but is there
maybe a portable way to do it, i.e., for programs intended to
run both under windows and linux? I asked that on stackexchange
some five years ago,
https://stackoverflow.com/questions/40609260/
but still no solution.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )

Re: ot: on stdin, stdout, stderr and crlf on windows

<sokijm$795$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19281&group=comp.lang.c#19281

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 6 Dec 2021 09:45:43 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <sokijm$795$1@dont-email.me>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Dec 2021 08:45:42 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="19c0caf469a91c3a8af60ec482c0e07a";
logging-data="7461"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185feqrgWwfIat3T8BZwCG6NIg6+v4Yrd0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:gx6FxpqB171Bk/vRWuRLDmwcgLA=
In-Reply-To: <sokh4l$8l2$1@reader1.panix.com>
Content-Language: de-DE
 by: Bonita Montero - Mon, 6 Dec 2021 08:45 UTC

Am 06.12.2021 um 09:20 schrieb John Forkosh:
> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Meredith Montgomery wrote:
>>>
>>> Windows provides me _setmode(), with which I can put stdout on
>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>> that Windows does not do any such replacements on stdin and stderr. I
>>> looked for a confirmation of this apparent fact and could not find it.
> <<snip>>
>>
>> Check the output of this in your hex-editor:
>>
>> #include <stdio.h>
>> #include <fcntl.h>
>> #include <io.h>
>> #include <stdlib.h>
>>
>> int main( int argc, char **argv )
>> {
>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
>> return EXIT_FAILURE;
>> fprintf( stderr, "it works !\n" );
>> }
>>
>> Without a commandline-parameter you've 0x0D, 0x0A
>> as a line-separator, with you've got only 0x0A.
>
> Yeah, that's more or less what I've been doing, but is there
> maybe a portable way to do it, i.e., for programs intended to
> run both under windows and linux?

#include <stdio.h>
#if define(_MSC_VER)
#include <fcntl.h>
#include <io.h>
#include <stdlib.h>
#endif

int main( int argc, char **argv )
{ #if define(_MSC_VER)
if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
return EXIT_FAILURE;
#endif
fprintf( stderr, "it works !\n" );
}

Re: ot: on stdin, stdout, stderr and crlf on windows

<87zgpem34j.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19283&group=comp.lang.c#19283

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 06 Dec 2021 10:36:28 +0000
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <87zgpem34j.fsf@bsb.me.uk>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="4f9e95ff65a4c37ff67b979ed04cb5bb";
logging-data="15614"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iCoYnORtasiss0dAo7XjW1idB9mtkXYg="
Cancel-Lock: sha1:MAqNswATrT2f/xQLlFMFQa6j0g0=
sha1:9af6RHtjApCRAR8oOl52e1d3LQY=
X-BSB-Auth: 1.9e9945180af469ad5cbf.20211206103628GMT.87zgpem34j.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 6 Dec 2021 10:36 UTC

John Forkosh <forkosh@panix.com> writes:

> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Meredith Montgomery wrote:
>>>
>>> Windows provides me _setmode(), with which I can put stdout on
>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>> that Windows does not do any such replacements on stdin and stderr. I
>>> looked for a confirmation of this apparent fact and could not find it.
> <<snip>>
>>
>> Check the output of this in your hex-editor:
>>
>> #include <stdio.h>
>> #include <fcntl.h>
>> #include <io.h>
>> #include <stdlib.h>
>>
>> int main( int argc, char **argv )
>> {
>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
>> return EXIT_FAILURE;
>> fprintf( stderr, "it works !\n" );
>> }
>>
>> Without a commandline-parameter you've 0x0D, 0x0A
>> as a line-separator, with you've got only 0x0A.

Summary: making stdout binary.

> Yeah, that's more or less what I've been doing, but is there
> maybe a portable way to do it, i.e., for programs intended to
> run both under windows and linux?

There's a standard function that /could/ do it, but it is allowed to be
no-op. I don't have access to a Windows programming environment, so I
can't check it:

freopen(NULL, "ab", stdout);

(or maybe "wb", it's the b you want of course).

--
Ben.

Re: ot: on stdin, stdout, stderr and crlf on windows

<soku6k$oo4$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19286&group=comp.lang.c#19286

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 6 Dec 2021 13:03:32 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <soku6k$oo4$1@dont-email.me>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 6 Dec 2021 12:03:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="19c0caf469a91c3a8af60ec482c0e07a";
logging-data="25348"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zekVPlGHH+Mhjjggjybtajscij27XYTM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:60IfFI+t2G+lj4+Vr9mkNYMUZeQ=
In-Reply-To: <87zgpem34j.fsf@bsb.me.uk>
Content-Language: de-DE
 by: Bonita Montero - Mon, 6 Dec 2021 12:03 UTC

Am 06.12.2021 um 11:36 schrieb Ben Bacarisse:
> John Forkosh <forkosh@panix.com> writes:
>
>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>> Meredith Montgomery wrote:
>>>>
>>>> Windows provides me _setmode(), with which I can put stdout on
>>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>>> that Windows does not do any such replacements on stdin and stderr. I
>>>> looked for a confirmation of this apparent fact and could not find it.
>> <<snip>>
>>>
>>> Check the output of this in your hex-editor:
>>>
>>> #include <stdio.h>
>>> #include <fcntl.h>
>>> #include <io.h>
>>> #include <stdlib.h>
>>>
>>> int main( int argc, char **argv )
>>> {
>>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY )
== -1 )
>>> return EXIT_FAILURE;
>>> fprintf( stderr, "it works !\n" );
>>> }
>>>
>>> Without a commandline-parameter you've 0x0D, 0x0A
>>> as a line-separator, with you've got only 0x0A.
>
> Summary: making stdout binary.
>
>> Yeah, that's more or less what I've been doing, but is there
>> maybe a portable way to do it, i.e., for programs intended to
>> run both under windows and linux?
>
> There's a standard function that /could/ do it, but it is allowed to be
> no-op. I don't have access to a Windows programming environment, so I
> can't check it:
>
> freopen(NULL, "ab", stdout);
>
> (or maybe "wb", it's the b you want of course).
Doesn't work with either wb or ab:

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

int main( int argc, char **argv )
{ if( argc < 2 )
return EXIT_FAILURE;
FILE *pfErr = freopen( NULL, argv[1], stderr);
printf( "%p", (void *)pfErr );
}

en.cppreference.com says:

"Microsoft CRT version of std::freopen does not support any mode
changes when filename is a null pointer and treats this as an
error (see documentation). A possible workaround is the non
-standard function _setmode()."

Re: ot: on stdin, stdout, stderr and crlf on windows

<87o85tnc8v.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19287&group=comp.lang.c#19287

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 06 Dec 2021 12:34:08 +0000
Organization: A noiseless patient Spider
Lines: 73
Message-ID: <87o85tnc8v.fsf@bsb.me.uk>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk>
<soku6k$oo4$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="4f9e95ff65a4c37ff67b979ed04cb5bb";
logging-data="3965"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pGgiNTA0anyM8vdzkJsHR9/Wb/TkQBbk="
Cancel-Lock: sha1:324I1aE6Ojdtvk52y8sakJ4k8AU=
sha1:QGvtaTek4jfcaU40OpmLbPI7N2Q=
X-BSB-Auth: 1.c1a947a2abb8f2fab729.20211206123408GMT.87o85tnc8v.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 6 Dec 2021 12:34 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:

> Am 06.12.2021 um 11:36 schrieb Ben Bacarisse:
>> John Forkosh <forkosh@panix.com> writes:
>>
>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>> Meredith Montgomery wrote:
>>>>>
>>>>> Windows provides me _setmode(), with which I can put stdout on
>>>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>>>> that Windows does not do any such replacements on stdin and stderr. I
>>>>> looked for a confirmation of this apparent fact and could not find it.
>>> <<snip>>
>>>>
>>>> Check the output of this in your hex-editor:
>>>>
>>>> #include <stdio.h>
>>>> #include <fcntl.h>
>>>> #include <io.h>
>>>> #include <stdlib.h>
>>>>
>>>> int main( int argc, char **argv )
>>>> {
>>>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
>>>> return EXIT_FAILURE;
>>>> fprintf( stderr, "it works !\n" );
>>>> }
>>>>
>>>> Without a commandline-parameter you've 0x0D, 0x0A
>>>> as a line-separator, with you've got only 0x0A.
>>
>> Summary: making stdout binary.
>>
>>> Yeah, that's more or less what I've been doing, but is there
>>> maybe a portable way to do it, i.e., for programs intended to
>>> run both under windows and linux?
>>
>> There's a standard function that /could/ do it, but it is allowed to be
>> no-op. I don't have access to a Windows programming environment, so I
>> can't check it:
>>
>> freopen(NULL, "ab", stdout);
>>
>> (or maybe "wb", it's the b you want of course).
> Doesn't work with either wb or ab:
>
> #include <stdio.h>
> #include <stdlib.h>
>
> int main( int argc, char **argv )
> {
> if( argc < 2 )
> return EXIT_FAILURE;
> FILE *pfErr = freopen( NULL, argv[1], stderr);
> printf( "%p", (void *)pfErr );
> }
>
> en.cppreference.com says:
>
> "Microsoft CRT version of std::freopen does not support any mode
> changes when filename is a null pointer and treats this as an
> error (see documentation). A possible workaround is the non
> -standard function _setmode()."

I feared this would be the case. It was many years ago when this last
came up. Maybe some alternative C library has made what appears to be
the trivial modification to make it work?

Anyway, if the most widely used C library does not support it, it's not
portable in any useful way.

--
Ben.

Re: ot: on stdin, stdout, stderr and crlf on windows

<sol3o2$1kov$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19288&group=comp.lang.c#19288

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 6 Dec 2021 14:38:09 +0100
Organization: Aioe.org NNTP Server
Message-ID: <sol3o2$1kov$1@gioia.aioe.org>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk>
<soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="54047"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Mon, 6 Dec 2021 13:38 UTC

On 12/6/2021 1:34 PM, Ben Bacarisse wrote:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 06.12.2021 um 11:36 schrieb Ben Bacarisse:
>>> John Forkosh <forkosh@panix.com> writes:
>>>
>>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>>> Meredith Montgomery wrote:
>>>>>>
>>>>>> Windows provides me _setmode(), with which I can put stdout on
>>>>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>>>>> that Windows does not do any such replacements on stdin and stderr. I
>>>>>> looked for a confirmation of this apparent fact and could not find it.
>>>> <<snip>>
>>>>>
>>>>> Check the output of this in your hex-editor:
>>>>>
>>>>> #include <stdio.h>
>>>>> #include <fcntl.h>
>>>>> #include <io.h>
>>>>> #include <stdlib.h>
>>>>>
>>>>> int main( int argc, char **argv )
>>>>> {
>>>>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
>>>>> return EXIT_FAILURE;
>>>>> fprintf( stderr, "it works !\n" );
>>>>> }
>>>>>
>>>>> Without a commandline-parameter you've 0x0D, 0x0A
>>>>> as a line-separator, with you've got only 0x0A.
>>>
>>> Summary: making stdout binary.
>>>
>>>> Yeah, that's more or less what I've been doing, but is there
>>>> maybe a portable way to do it, i.e., for programs intended to
>>>> run both under windows and linux?
>>>
>>> There's a standard function that /could/ do it, but it is allowed to be
>>> no-op. I don't have access to a Windows programming environment, so I
>>> can't check it:
>>>
>>> freopen(NULL, "ab", stdout);
>>>
>>> (or maybe "wb", it's the b you want of course).
>> Doesn't work with either wb or ab:
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main( int argc, char **argv )
>> {
>> if( argc < 2 )
>> return EXIT_FAILURE;
>> FILE *pfErr = freopen( NULL, argv[1], stderr);
>> printf( "%p", (void *)pfErr );
>> }
>>
>> en.cppreference.com says:
>>
>> "Microsoft CRT version of std::freopen does not support any mode
>> changes when filename is a null pointer and treats this as an
>> error (see documentation). A possible workaround is the non
>> -standard function _setmode()."
>
> I feared this would be the case. It was many years ago when this last
> came up. Maybe some alternative C library has made what appears to be
> the trivial modification to make it work?
>
> Anyway, if the most widely used C library does not support it, it's not
> portable in any useful way.
>

I'm not sure the Microsoft CRT is the most widely used library (I'd say
it is on Windows, in general I think it isn't), but it's used widely
enough to make portability an issue, sure.

Re: ot: on stdin, stdout, stderr and crlf on windows

<ac67bf85-effc-4ac4-870f-955d7657cddan@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19289&group=comp.lang.c#19289

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:d84:: with SMTP id e4mr38410520qve.128.1638799216606;
Mon, 06 Dec 2021 06:00:16 -0800 (PST)
X-Received: by 2002:a37:67ca:: with SMTP id b193mr33679127qkc.282.1638799216419;
Mon, 06 Dec 2021 06:00:16 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 6 Dec 2021 06:00:16 -0800 (PST)
In-Reply-To: <sol3o2$1kov$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:2419:8868:3418:d612;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:2419:8868:3418:d612
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk>
<soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk> <sol3o2$1kov$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ac67bf85-effc-4ac4-870f-955d7657cddan@googlegroups.com>
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Mon, 06 Dec 2021 14:00:16 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 79
 by: Malcolm McLean - Mon, 6 Dec 2021 14:00 UTC

On Monday, 6 December 2021 at 13:38:21 UTC, Manfred wrote:
> On 12/6/2021 1:34 PM, Ben Bacarisse wrote:
> > Bonita Montero <Bonita....@gmail.com> writes:
> >
> >> Am 06.12.2021 um 11:36 schrieb Ben Bacarisse:
> >>> John Forkosh <for...@panix.com> writes:
> >>>
> >>>> Bonita Montero <Bonita....@gmail.com> wrote:
> >>>>> Meredith Montgomery wrote:
> >>>>>>
> >>>>>> Windows provides me _setmode(), with which I can put stdout on
> >>>>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
> >>>>>> that Windows does not do any such replacements on stdin and stderr. I
> >>>>>> looked for a confirmation of this apparent fact and could not find it.
> >>>> <<snip>>
> >>>>>
> >>>>> Check the output of this in your hex-editor:
> >>>>>
> >>>>> #include <stdio.h>
> >>>>> #include <fcntl.h>
> >>>>> #include <io.h>
> >>>>> #include <stdlib.h>
> >>>>>
> >>>>> int main( int argc, char **argv )
> >>>>> {
> >>>>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
> >>>>> return EXIT_FAILURE;
> >>>>> fprintf( stderr, "it works !\n" );
> >>>>> }
> >>>>>
> >>>>> Without a commandline-parameter you've 0x0D, 0x0A
> >>>>> as a line-separator, with you've got only 0x0A.
> >>>
> >>> Summary: making stdout binary.
> >>>
> >>>> Yeah, that's more or less what I've been doing, but is there
> >>>> maybe a portable way to do it, i.e., for programs intended to
> >>>> run both under windows and linux?
> >>>
> >>> There's a standard function that /could/ do it, but it is allowed to be
> >>> no-op. I don't have access to a Windows programming environment, so I
> >>> can't check it:
> >>>
> >>> freopen(NULL, "ab", stdout);
> >>>
> >>> (or maybe "wb", it's the b you want of course).
> >> Doesn't work with either wb or ab:
> >>
> >> #include <stdio.h>
> >> #include <stdlib.h>
> >>
> >> int main( int argc, char **argv )
> >> {
> >> if( argc < 2 )
> >> return EXIT_FAILURE;
> >> FILE *pfErr = freopen( NULL, argv[1], stderr);
> >> printf( "%p", (void *)pfErr );
> >> }
> >>
> >> en.cppreference.com says:
> >>
> >> "Microsoft CRT version of std::freopen does not support any mode
> >> changes when filename is a null pointer and treats this as an
> >> error (see documentation). A possible workaround is the non
> >> -standard function _setmode()."
> >
> > I feared this would be the case. It was many years ago when this last
> > came up. Maybe some alternative C library has made what appears to be
> > the trivial modification to make it work?
> >
> > Anyway, if the most widely used C library does not support it, it's not
> > portable in any useful way.
> >
> I'm not sure the Microsoft CRT is the most widely used library (I'd say
> it is on Windows, in general I think it isn't), but it's used widely
> enough to make portability an issue, sure.
>
The days when everyone used Windows except for a few types who worked in
universities or big research companies and had Unix are gone. I'm typing
this on an Apple.

Re: ot: on stdin, stdout, stderr and crlf on windows

<87ilw1mzj9.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19291&group=comp.lang.c#19291

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 06 Dec 2021 17:08:42 +0000
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <87ilw1mzj9.fsf@bsb.me.uk>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk>
<soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk>
<sol3o2$1kov$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="4f9e95ff65a4c37ff67b979ed04cb5bb";
logging-data="31383"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/bh3vdlt8gwTPg6LMStRHR5URXCD9nmi4="
Cancel-Lock: sha1:x+26giZJWjuJcEKw0WKExVx7aUk=
sha1:JD6X4nKW4rkHSavybM7k5LkFrto=
X-BSB-Auth: 1.72f337b606d81527944f.20211206170842GMT.87ilw1mzj9.fsf@bsb.me.uk
 by: Ben Bacarisse - Mon, 6 Dec 2021 17:08 UTC

Manfred <noname@add.invalid> writes:

> On 12/6/2021 1:34 PM, Ben Bacarisse wrote:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>
>>> Am 06.12.2021 um 11:36 schrieb Ben Bacarisse:
>>>> John Forkosh <forkosh@panix.com> writes:
>>>>
>>>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>>>> Meredith Montgomery wrote:
>>>>>>>
>>>>>>> Windows provides me _setmode(), with which I can put stdout on
>>>>>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>>>>>> that Windows does not do any such replacements on stdin and stderr. I
>>>>>>> looked for a confirmation of this apparent fact and could not find it.
>>>>> <<snip>>
>>>>>>
>>>>>> Check the output of this in your hex-editor:
>>>>>>
>>>>>> #include <stdio.h>
>>>>>> #include <fcntl.h>
>>>>>> #include <io.h>
>>>>>> #include <stdlib.h>
>>>>>>
>>>>>> int main( int argc, char **argv )
>>>>>> {
>>>>>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
>>>>>> return EXIT_FAILURE;
>>>>>> fprintf( stderr, "it works !\n" );
>>>>>> }
>>>>>>
>>>>>> Without a commandline-parameter you've 0x0D, 0x0A
>>>>>> as a line-separator, with you've got only 0x0A.
>>>>
>>>> Summary: making stdout binary.
>>>>
>>>>> Yeah, that's more or less what I've been doing, but is there
>>>>> maybe a portable way to do it, i.e., for programs intended to
>>>>> run both under windows and linux?
>>>>
>>>> There's a standard function that /could/ do it, but it is allowed to be
>>>> no-op. I don't have access to a Windows programming environment, so I
>>>> can't check it:
>>>>
>>>> freopen(NULL, "ab", stdout);
>>>>
>>>> (or maybe "wb", it's the b you want of course).
>>> Doesn't work with either wb or ab:
>>>
>>> #include <stdio.h>
>>> #include <stdlib.h>
>>>
>>> int main( int argc, char **argv )
>>> {
>>> if( argc < 2 )
>>> return EXIT_FAILURE;
>>> FILE *pfErr = freopen( NULL, argv[1], stderr);
>>> printf( "%p", (void *)pfErr );
>>> }
>>>
>>> en.cppreference.com says:
>>>
>>> "Microsoft CRT version of std::freopen does not support any mode
>>> changes when filename is a null pointer and treats this as an
>>> error (see documentation). A possible workaround is the non
>>> -standard function _setmode()."
>> I feared this would be the case. It was many years ago when this last
>> came up. Maybe some alternative C library has made what appears to be
>> the trivial modification to make it work?
>> Anyway, if the most widely used C library does not support it, it's not
>> portable in any useful way.
>
> I'm not sure the Microsoft CRT is the most widely used library (I'd
> say it is on Windows, in general I think it isn't), but it's used
> widely enough to make portability an issue, sure.

I meant "on Windows". On, say, Linux, I would think it does not matter
if freopen(NULL, "wb", stdout) fails, since streams are already binary.

--
Ben.

Re: ot: on stdin, stdout, stderr and crlf on windows

<IBrrJ.89628$aF1.54113@fx98.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19292&group=comp.lang.c#19292

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx98.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Newsgroups: comp.lang.c
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me> <sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk> <soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk> <sol3o2$1kov$1@gioia.aioe.org> <87ilw1mzj9.fsf@bsb.me.uk>
Lines: 15
Message-ID: <IBrrJ.89628$aF1.54113@fx98.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Mon, 06 Dec 2021 17:18:32 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Mon, 06 Dec 2021 17:18:32 GMT
X-Received-Bytes: 1428
 by: Scott Lurndal - Mon, 6 Dec 2021 17:18 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>Manfred <noname@add.invalid> writes:

>> I'm not sure the Microsoft CRT is the most widely used library (I'd
>> say it is on Windows, in general I think it isn't), but it's used
>> widely enough to make portability an issue, sure.
>
>I meant "on Windows". On, say, Linux, I would think it does not matter
>if freopen(NULL, "wb", stdout) fails, since streams are already binary.
>

On Unix and POSIX systems:

"The character 'b' shall have no effect, but is allowed for ISO C standard conformance"

Re: ot: on stdin, stdout, stderr and crlf on windows

<solj23$11b$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19293&group=comp.lang.c#19293

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!Puiiztk9lHEEQC0y3uUjRA.user.46.165.242.75.POSTED!not-for-mail
From: non...@add.invalid (Manfred)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Mon, 6 Dec 2021 18:59:30 +0100
Organization: Aioe.org NNTP Server
Message-ID: <solj23$11b$1@gioia.aioe.org>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk>
<soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk>
<sol3o2$1kov$1@gioia.aioe.org>
<ac67bf85-effc-4ac4-870f-955d7657cddan@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="1067"; posting-host="Puiiztk9lHEEQC0y3uUjRA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Manfred - Mon, 6 Dec 2021 17:59 UTC

On 12/6/2021 3:00 PM, Malcolm McLean wrote:
> On Monday, 6 December 2021 at 13:38:21 UTC, Manfred wrote:
>> On 12/6/2021 1:34 PM, Ben Bacarisse wrote:
>>> Bonita Montero <Bonita....@gmail.com> writes:
[...]
>>>> en.cppreference.com says:
>>>>
>>>> "Microsoft CRT version of std::freopen does not support any mode
>>>> changes when filename is a null pointer and treats this as an
>>>> error (see documentation). A possible workaround is the non
>>>> -standard function _setmode()."
>>>
>>> I feared this would be the case. It was many years ago when this last
>>> came up. Maybe some alternative C library has made what appears to be
>>> the trivial modification to make it work?
>>>
>>> Anyway, if the most widely used C library does not support it, it's not
>>> portable in any useful way.
>>>
>> I'm not sure the Microsoft CRT is the most widely used library (I'd say
>> it is on Windows, in general I think it isn't), but it's used widely
>> enough to make portability an issue, sure.
>>
> The days when everyone used Windows except for a few types who worked in
> universities or big research companies and had Unix are gone. I'm typing
> this on an Apple.
>

There is also the fact about how much the CRT library is actually used
on Windows.
Yes, it is used, but Microsoft puts very little effort on C, more on
C++, and both languages get much less attention from them than other
frameworks, like the Windows API or .NET nowadays.
In other words, I believe there's a lot of Windows apps being developed
that do not use the CRT, at least as of recent.
On the other hand, virtually all of *nix code relies on (g)libc, and the
same is probably true for the embedded world (I have no idea about iOS)

Re: ot: on stdin, stdout, stderr and crlf on windows

<somcbq$frv$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19299&group=comp.lang.c#19299

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: fork...@panix.com (John Forkosh)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Tue, 7 Dec 2021 01:11:22 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <somcbq$frv$1@reader1.panix.com>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me> <sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk> <soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk>
Injection-Date: Tue, 7 Dec 2021 01:11:22 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="16255"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: John Forkosh - Tue, 7 Dec 2021 01:11 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 06.12.2021 um 11:36 schrieb Ben Bacarisse:
>>> John Forkosh <forkosh@panix.com> writes:
>>>
>>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>>> Meredith Montgomery wrote:
>>>>>>
>>>>>> Windows provides me _setmode(), with which I can put stdout on
>>>>>> _O_BINARY. It then stops replacing \n with \r\n. However, it seems
>>>>>> that Windows does not do any such replacements on stdin and stderr. I
>>>>>> looked for a confirmation of this apparent fact and could not find it.
>>>> <<snip>>
>>>>>
>>>>> Check the output of this in your hex-editor:
>>>>>
>>>>> #include <stdio.h>
>>>>> #include <fcntl.h>
>>>>> #include <io.h>
>>>>> #include <stdlib.h>
>>>>>
>>>>> int main( int argc, char **argv )
>>>>> {
>>>>> if( argc >= 2 && _setmode( _fileno( stderr ), _O_BINARY ) == -1 )
>>>>> return EXIT_FAILURE;
>>>>> fprintf( stderr, "it works !\n" );
>>>>> }
>>>>>
>>>>> Without a commandline-parameter you've 0x0D, 0x0A
>>>>> as a line-separator, with you've got only 0x0A.
>>>
>>> Summary: making stdout binary.
>>>
>>>> Yeah, that's more or less what I've been doing, but is there
>>>> maybe a portable way to do it, i.e., for programs intended to
>>>> run both under windows and linux?
>>>
>>> There's a standard function that /could/ do it, but it is allowed to be
>>> no-op. I don't have access to a Windows programming environment, so I
>>> can't check it:
>>>
>>> freopen(NULL, "ab", stdout);
>>>
>>> (or maybe "wb", it's the b you want of course).
>> Doesn't work with either wb or ab:
>>
>> #include <stdio.h>
>> #include <stdlib.h>
>>
>> int main( int argc, char **argv )
>> {
>> if( argc < 2 )
>> return EXIT_FAILURE;
>> FILE *pfErr = freopen( NULL, argv[1], stderr);
>> printf( "%p", (void *)pfErr );
>> }
>>
>> en.cppreference.com says:
>>
>> "Microsoft CRT version of std::freopen does not support any mode
>> changes when filename is a null pointer and treats this as an
>> error (see documentation). A possible workaround is the non
>> -standard function _setmode()."
>
> I feared this would be the case. It was many years ago when this last
> came up. Maybe some alternative C library has made what appears to be
> the trivial modification to make it work?
>
> Anyway, if the most widely used C library does not support it, it's not
> portable in any useful way.

Thanks, Ben and Bonita (and Malcom and Manfred), yeah I also "feared
this would be the case", i.e., no portable solution like freopen(),
which would be syntactically identical on all platforms and "just work",
whether needed (windows) or not (linux).

By the way, at least at the time when I wrote that stackexchange post,
some windows C compilers used _setmode(_fileno(stderr),_O_BINARY)
like Bonita said, but some others used setmode(fileno(stderr),O_BINARY).
So additional #ifdefs needed to resolve that. And I'm also not sure
that _MSC_VER always identifies all windows C compilers. The elaborate
#ifdefs illustrated on that stackexchange post were what I ended up
with to accommodate all the variations I'd encountered at the time
I wrote it. So I was hoping to find some less elaborate and fewer
lines of gobbledy-gook code, if not entirely 100% portable, to identify
and handle all possible windows situations.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )

Re: ot: on stdin, stdout, stderr and crlf on windows

<sonb3f$dp0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19300&group=comp.lang.c#19300

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Tue, 7 Dec 2021 09:56:00 +0000
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <sonb3f$dp0$1@dont-email.me>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me>
<sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk>
<soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk>
<somcbq$frv$1@reader1.panix.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 7 Dec 2021 09:56:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4beda930f8359b56ce403c0344afa7fa";
logging-data="14112"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9GLksAvLYkJA8OQrBWVm1eeNNo7jjUao="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:3lwZUHSV1Ggn/bAV/xRxQ9ugdNo=
In-Reply-To: <somcbq$frv$1@reader1.panix.com>
 by: Bart - Tue, 7 Dec 2021 09:56 UTC

On 07/12/2021 01:11, John Forkosh wrote:
> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:

>> Anyway, if the most widely used C library does not support it, it's not
>> portable in any useful way.
>
> Thanks, Ben and Bonita (and Malcom and Manfred), yeah I also "feared
> this would be the case", i.e., no portable solution like freopen(),
> which would be syntactically identical on all platforms and "just work",
> whether needed (windows) or not (linux).
>
> By the way, at least at the time when I wrote that stackexchange post,
> some windows C compilers used _setmode(_fileno(stderr),_O_BINARY)
> like Bonita said, but some others used setmode(fileno(stderr),O_BINARY).
> So additional #ifdefs needed to resolve that. And I'm also not sure
> that _MSC_VER always identifies all windows C compilers. The elaborate
> #ifdefs illustrated on that stackexchange post were what I ended up
> with to accommodate all the variations I'd encountered at the time
> I wrote it. So I was hoping to find some less elaborate and fewer
> lines of gobbledy-gook code, if not entirely 100% portable, to identify
> and handle all possible windows situations.
>

Every Windows system comes with a C library called msvcrt.dll. And
msvcrt.dll (usually located in C:\windows\system32) defines _setmode.

That means I can reliably call that function even from a script language
as follows:

importdll msvcrt=
clang function _setmode(int32,int32)int32
end

println _setmode(1,32768) # 1=stdout, 32768=O_BINARY

Ironically, this appears difficult to do from C!

First because it's hard to pinpoint that function in that specific
library. But also because it needs to be the same library that is used
by your *printf and other functions, otherwise you're setting the mode
of the wrong library.

You would need, somehow, to specifically link with this library, but
even then, there might be shortcomings: some parts of it might too slow;
some other functions could be missing.

(With my script, the call works both for native 'print' which eventually
calls 'printf' of the C library dynamically linked to the interpreter
executable, and for direct 'printf' calls within that msvcrt loaded by
the script (printf declaration and use not shown).

I expected there to be two instances of msvcrt, but presumably the OS
sees them as both invoked by the same program so they must share data.)

Re: ot: on stdin, stdout, stderr and crlf on windows

<soppeu$hq9$1@reader1.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19302&group=comp.lang.c#19302

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.panix3.panix.com!not-for-mail
From: fork...@panix.com (John Forkosh)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Wed, 8 Dec 2021 08:13:18 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <soppeu$hq9$1@reader1.panix.com>
References: <86fsr8uf6a.fsf@levado.to> <soiheo$jo9$1@dont-email.me> <sokh4l$8l2$1@reader1.panix.com> <87zgpem34j.fsf@bsb.me.uk> <soku6k$oo4$1@dont-email.me> <87o85tnc8v.fsf@bsb.me.uk> <somcbq$frv$1@reader1.panix.com> <sonb3f$dp0$1@dont-email.me>
Injection-Date: Wed, 8 Dec 2021 08:13:18 -0000 (UTC)
Injection-Info: reader1.panix.com; posting-host="panix3.panix.com:166.84.1.3";
logging-data="18249"; mail-complaints-to="abuse@panix.com"
User-Agent: tin/2.6.0-20210823 ("Coleburn") (NetBSD/9.2 (amd64))
 by: John Forkosh - Wed, 8 Dec 2021 08:13 UTC

Bart <bc@freeuk.com> wrote:
> John Forkosh wrote:
>> Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:
>
>>> Anyway, if the most widely used C library does not support it, it's not
>>> portable in any useful way.
>>
>> Thanks, Ben and Bonita (and Malcom and Manfred), yeah I also "feared
>> this would be the case", i.e., no portable solution like freopen(),
>> which would be syntactically identical on all platforms and "just work",
>> whether needed (windows) or not (linux).
>>
>> By the way, at least at the time when I wrote that stackexchange post,
>> some windows C compilers used _setmode(_fileno(stderr),_O_BINARY)
>> like Bonita said, but some others used setmode(fileno(stderr),O_BINARY).
>> So additional #ifdefs needed to resolve that. And I'm also not sure
>> that _MSC_VER always identifies all windows C compilers. The elaborate
>> #ifdefs illustrated on that stackexchange post were what I ended up
>> with to accommodate all the variations I'd encountered at the time
>> I wrote it. So I was hoping to find some less elaborate and fewer
>> lines of gobbledy-gook code, if not entirely 100% portable, to identify
>> and handle all possible windows situations.
>>
>
> Every Windows system comes with a C library called msvcrt.dll. And
> msvcrt.dll (usually located in C:\windows\system32) defines _setmode.
>
> That means I can reliably call that function even from a script language
> as follows:
>
> importdll msvcrt=
> clang function _setmode(int32,int32)int32
> end
>
> println _setmode(1,32768) # 1=stdout, 32768=O_BINARY
>
> Ironically, this appears difficult to do from C!
>
> First because it's hard to pinpoint that function in that specific
> library. But also because it needs to be the same library that is used
> by your *printf and other functions, otherwise you're setting the mode
> of the wrong library.
>
> You would need, somehow, to specifically link with this library, but
> even then, there might be shortcomings: some parts of it might too slow;
> some other functions could be missing.
>
> (With my script, the call works both for native 'print' which eventually
> calls 'printf' of the C library dynamically linked to the interpreter
> executable, and for direct 'printf' calls within that msvcrt loaded by
> the script (printf declaration and use not shown).
>
> I expected there to be two instances of msvcrt, but presumably the OS
> sees them as both invoked by the same program so they must share data.)

Thanks, Bart. I'll try that approach next time I take a look at
that code, though probably not soon (I only posted the followup
question since the op was already barking up the very same tree).
In any case, seems like there's no way around an overly-elaborate
solution to what should be a completely trivial task (i.e., the
one-line freopen() ought to "just work"). So if/when I do take
another look, I'll almost-certainly encapsulate the inevitable
gobbledy-gook #ifdefs/code/whatever into its own little function,
so it doesn't interrupt main()'s more straightforward logical flow.
--
John Forkosh ( mailto: j@f.com where j=john and f=forkosh )

Re: ot: on stdin, stdout, stderr and crlf on windows

<867dcc966s.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19327&group=comp.lang.c#19327

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Fri, 10 Dec 2021 01:10:03 -0800
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <867dcc966s.fsf@linuxsc.com>
References: <86fsr8uf6a.fsf@levado.to>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="94ee63d76223a75d29f96ac519efdd3f";
logging-data="29186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vcc6f+eAfHAT5TFTqxe9eFDspsvm7AJw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:KRaXtLHQrzDKPU8XjTV8YHvik3g=
sha1:3q1A/+da2TNCTH9rL23YGs97vi0=
 by: Tim Rentsch - Fri, 10 Dec 2021 09:10 UTC

Meredith Montgomery <mmontgomery@levado.to> writes:

> I know this isn't C. I'm not aware of any group like
> comp.windows.programmer. [...]

I suggest you try stackoverflow.

Re: ot: on stdin, stdout, stderr and crlf on windows

<sovc1a$1m9jm$1@news.xmission.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19334&group=comp.lang.c#19334

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: ot: on stdin, stdout, stderr and crlf on windows
Date: Fri, 10 Dec 2021 11:00:58 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sovc1a$1m9jm$1@news.xmission.com>
References: <86fsr8uf6a.fsf@levado.to> <867dcc966s.fsf@linuxsc.com>
Injection-Date: Fri, 10 Dec 2021 11:00:58 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1779318"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 10 Dec 2021 11:00 UTC

In article <867dcc966s.fsf@linuxsc.com>,
Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>Meredith Montgomery <mmontgomery@levado.to> writes:
>
>> I know this isn't C. I'm not aware of any group like
>> comp.windows.programmer. [...]
>
>I suggest you try stackoverflow.

Or get a better newsserver...

$ grep windows.progr GROUPS.news
comp.os.ms-windows.programmer.controls 0000037091 0000037092 y
comp.os.ms-windows.programmer.graphics 0000040642 0000040643 y
comp.os.ms-windows.programmer.memory 0000013480 0000013481 y
comp.os.ms-windows.programmer.misc 0000008003 0000008001 y
comp.os.ms-windows.programmer.multimedia 0000027043 0000027044 y
comp.os.ms-windows.programmer.networks 0000022813 0000022814 y
comp.os.ms-windows.programmer.nt.kernel-mode 0000077071 0000077071 y
comp.os.ms-windows.programmer.ole 0000023431 0000023432 y
comp.os.ms-windows.programmer.tools.mfc 0000110469 0000110470 y
comp.os.ms-windows.programmer.tools.misc 0000017120 0000017121 y
comp.os.ms-windows.programmer.tools.owl 0000023129 0000023130 y
comp.os.ms-windows.programmer.tools.winsock 0000019735 0000019736 y
comp.os.ms-windows.programmer.vxd 0000034719 0000034720 y
comp.os.ms-windows.programmer.win32 0000282373 0000282105 y
comp.os.ms-windows.programmer.winhelp 0000028693 0000028694 y
de.comp.os.ms-windows.programmer 0000041069 0000041068 y
es.comp.os.ms-windows.programacion 0000011998 0000011999 y
fj.os.ms-windows.programming 0000013012 0000013013 y
fr.comp.os.ms-windows.programmation 0000072256 0000072234 y
$

Note that the file mentioned above is a file that I maintain on my system
so I can lookup things like this. It is created by a script that telnets
into my newsserver and then records the results.

--
Just like Donald Trump today, Jesus Christ had a Messiah complex.

And, in fact, the similarities between the two figures are quite striking.
For example, both have a ragtag band of followers, whose faith cannot be shaken.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor