On Fri, 22 Jun 2001, Tye McQueen wrote:
> Excerpts from the mail message of Steve Hay:
> )
> ) Alas, I'm not writing the C library. I'm writing a Perl module to wrap a
> ) (Microsoft C) Win32 file open function called _fsopen(),
>
> You might want to look at Win32API::File which already provides
> such functionality and more.
Or you might also want to take a look at VMS::Stdio::vmsopen() which
provides a wrapper around VMS's fopen() which is prototyped as:
FILE * fopen(const char *file_spec, const char *mode, ...);
that is, with a variable number of extra arguments. The extra stuff has
to do with indexed files and other such matters and is documented in the
pod for VMS::Stdio.pm. The vmsopen() routine in XS boils down to:
FILE *fp;
fp = fopen(spec,mode,
args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
if (fp != Null(FILE*)) {
pio_fp = PerlIO_importFILE(fp,0);
SV *fh = newFH(pio_fp,
(mode[1] ? '+' : (mode[0] == 'r' ? '<' :
(mode[0] == 'a' ? 'a' : '>'))));
ST(0) = (fh ? sv_2mortal(fh) : &PL_sv_undef);
}
else { ST(0) = &PL_sv_undef; }
The important bit being the SV *newFH(PerlIO *fp, char type) function that
is written in XS macro-ized C near the top of Stdio.xs. Note that you'd
need to use a different stash package name than "VMS::" for your purposes
should you want to use (although it sounds like Win32API::File will
actually help you).
Note too that I stole that code to put into OS390::Stdio available on CPAN
(although mine is a bit older and uses FILE * pointers rather than PerlIO
* pointers). In the case of OS/390 we needed for perl to access fopen()ed
FILE * pointers with no intervention via fileno(). Also OS/390's fopen()
(as opposed to creat() or open()) allows access to MVS data sets, there
too via an extension of the ANSI/ISO/XPG specs for fopen() although it
only takes two arguments (in line with the ANSI and other specs).
HTH.
Peter Prymmer