NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Is use of 'binary' mode necessary to open files on NetBSD?



On Sat, Dec 02, 2023 at 09:18:56AM +0530, Mayuresh wrote:
I am using gcc 12.1 on NetBSD 9.3 amd64 in a c++ application that complies
using standard std20.

There is this c++ standard library class ifstream. Using method
ifstream::open files are opened.

So far I was under an impression that on BSDs / Linux / Unix like systems
there is no need to explicitly pass the "b" option ( ifstream::binary in
case of above API ) and that such option is required only on DOS / Windows
systems.

Correct, it is due to how DOS Type Systems formats Text Files.

UNIX type systems use a \n at the end of the line.

DOS Type systems ends each line with a \r\n and upon read,
DOS type systems strips out the \r if 'b' is not supplied
when reading text files.

But I found that without this option, on above setup, the things were not
working (weird results you'd expect with implicit character conversions).
Using above option solves the problem.

On NetBSD, the fopen man page clearly says 'b' is ignored. So wonder if
gcc layer introduces the need to use it in above usage pattern.

A bit surprised by this behavior. Comments please.

I do not understand the behavior you are referring to.  I do
not know c++, but in c, 'b' is not needed on any UNIX type
system.  But for portability you can keep it for compile on
DOS Type systems.

I wonder if you are running into some specific c++ thing.

--
Mayuresh



Home | Main Index | Thread Index | Old Index