Nick Ing-Simmons wrote:
Steve Hay <[EMAIL PROTECTED]> writes:One further question on this subject:
Hi,PerlSIO_fclose(fp);
I have an XS function that gets a FILE * back from a library function that it calls and then tries to PerlIO_importFILE() that into a PerlIO *. Just for completeness my code checks for the (presumably rather unlikely) event that this could fail, and in this case it tidies up by fclose()'ing the now-useless FILE *. Something like this:
FILE *fp;
PerlIO *pfp;
fp = my_library_fn();
if (fp != Null(FILE *)) {
pfp = PerlIO_importFILE(fp, mode);
if (pfp != Nullfp) {
# Good. Do some stuff...
}
else {
# Oh dear. Clean up...
fclose(fp);
# Return failure.You need to use PerlSIO_fxxxxx() for Standard IO under PERL_IMPLICIT_SYS.
}
}
else {
# Oh dear.
# Return failure.
}
I also a have corresponding function that works with low-level i/o routines. It gets an int file descriptor back from a library function that it calls and then tries to PerlIO_fdopen() that to get a PerlIO *.
As in the above code, it tidies up in the case of PerlIO_fdopen() failing my close()ing the now-useless fd.
My question is: are there any circumstances under which the close(fd) should be PerlLIO_close(fd)?
Compiling under Perl 5.8.0 with PERL_IMPLICIT_SYS does not appear to cause any problem with close() like it did with fclose(), but are there other are situations that I need to be aware of?
Thanks,
Steve
