Hi,

I'm having trouble trying to use the PerlIO_binmode() function in my XS code. I'm working on Windows (XP), so this function is not a no-op.

A file is opened in "text mode" by a library function that returns a FILE *. I call PerlIO_importFILE() to get a PerlIO *, then call:

PerlIO_binmode(p, type, O_BINARY, Nullch)

to put the file handle into "binary mode", and then call PerlIO_printf() and PerlIO_close(). The data printed to this file handle was "Hello, world.\n", but when I look at the file that has been created it ends with "\r\n" -- i.e. "text mode" translation has been performed on the data. This was not what I expected. Have I mis-interpreted what the PerlIO_binmode() call is supposed to do, or is this broken?

As an experiment, I tried changing the above PerlIO_binmode() call to the following:

PerlIO_binmode(p, type, O_TEXT, ":crlf")

I thought this would be a no-op, putting the file handle into "text mode" when it already is, but I found that the file created now ends with "\r\r\n" -- i.e. two rounds of "text mode" translation now appear to have been performed.

Is this all something to do with the new PerlIO "layers"? Am I simply adding more layers to the existing "text mode" layer? If so, then how do I remove that existing layer so that the file handle is (just) "binary mode"?

The above all relates to a Perl that I've built myself (without PERL_IMPLICIT_SYS). If I try and use ActivePerl instead (which has PERL_IMPLICIT_SYS) then the module won't even build:

warning C4047: 'function' : 'struct interpreter *' differs in levels of indirection from 'struct _PerlIO ** '
warning C4024: 'PerlIO_binmode' : different types for formal and actual parameter 1
warning C4047: 'function' : 'struct _PerlIO ** ' differs in levelsof indirection from 'char '
warning C4024: 'PerlIO_binmode' : different types for formal and actual parameter 2
warning C4047: 'function' : 'int ' differs in levels of indirection from 'char *'
warning C4024: 'PerlIO_binmode' : different types for formal and actual parameter 4
error C2198: 'PerlIO_binmode' : too few actual parameters

Why is this?

Thanks,

Steve

Reply via email to