Mail Archives: cygwin/2009/03/18/06:09:06
On 2009-03-18 09:43Z, Corinna Vinschen wrote:
> On Mar 17 21:15, Charles Wilson wrote:
>> Is there a cygwin analogue to the msvc _set_fmode()? That is, a function
>> that sets the default mode of fopen, even if you don't explicitly
>> specify it "rb" or whatever.
>>
>> Obviously, there's "use binary (or text) mounts". Less obviously, you
>> can link against /usr/lib/binary.o (or -lbinmode), or text.o (or
>> automode.o or textreadmode.o and the similar .a's). But I'm looking for
>> an actual function call to replace the following code in libarchive:
>>
>> +#if defined(_WIN32) && !defined(__CYGWIN__)
>
> The !defined(__CYGWIN__) is not necessary because gcc for Cygwin doesn't
> define _WIN32.
>
>> /* Make sure open() function will be used with a binary mode. */
>> /* on cygwin, we need something similar, but instead link against */
>> /* a special startup object, binmode.o */
>> _set_fmode(_O_BINARY);
>> #endif
>>
>> I'm using binmode.o at present, but I'd prefer to just make a func call
>> at the same place the WIN32-specific code does. (FWIW, you can't call
>> the w32api _set_fmode() function and expect it to work; the msvc runtime
>> and cygwin maintain different default _fmode variables).
>
> Cygwin has no such function call except for the per-descriptor function
> setmode (fd, mode). IMHO using binmode.o is much more elegant. The
> only other choice you have is this:
>
> extern int _fmode;
> _fmode = O_BINARY;
>
> _fmode is defined in crt0.o so you can simply access it if you like.
> But anyway, using binmode.o is much more elegant, IMHO. I don't see
> what speaks against using it.
If a drop-in replacement for _set_fmode() is nonetheless still wanted,
then _mingw32_init_fmode() here:
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/mingw/crt1.c?cvsroot=src
might provide ideas for implementing it (or reasons to avoid it: for
example, standard streams would already have been opened before such a
function could be called).
An alternative that keeps all toolchains working the same way is to
link with 'binmode.o' for Cygwin, and 'Binmode.obj' for msvc:
http://msdn.microsoft.com/en-us/library/ee2849wt(VS.80).aspx
if it's acceptable to change the upstream package.
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
- Raw text -