if (IoIFP(io)) {
return (PL_laststatval = PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache));
} else if (IoDIRP(io)) {
-#ifdef HAS_DIRFD
- return (PL_laststatval = PerlLIO_fstat(dirfd(IoDIRP(io)), &PL_statcache));
-#else
- Perl_die(aTHX_ PL_no_func, "dirfd");
- /* NOT REACHED */
- return 0;
- /* Can't use NORETURN_FUNCTION_END because Perl_die is not
- * __attribute__noreturn__
- * Can't use DIE because that does not return an integer
- */
-#endif
+ return (PL_laststatval = PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache));
} else {
if (ckWARN2(WARN_UNOPENED,WARN_CLOSED))
report_evil_fh(gv, io, PL_op->op_type);
Apd |void |sv_copypv |NN SV* dsv|NN SV* ssv
Ap |char* |my_atof2 |NN const char *s|NN NV* value
Apn |int |my_socketpair |int family|int type|int protocol|int fd[2]
+Apn |int |my_dirfd |NULLOK DIR* dir
#ifdef PERL_OLD_COPY_ON_WRITE
pMXE |SV* |sv_setsv_cow |NN SV* dsv|NN SV* ssv
#endif
#define sv_copypv Perl_sv_copypv
#define my_atof2 Perl_my_atof2
#define my_socketpair Perl_my_socketpair
+#define my_dirfd Perl_my_dirfd
#ifdef PERL_OLD_COPY_ON_WRITE
#if defined(PERL_CORE) || defined(PERL_EXT)
#define sv_setsv_cow Perl_sv_setsv_cow
#define sv_copypv(a,b) Perl_sv_copypv(aTHX_ a,b)
#define my_atof2(a,b) Perl_my_atof2(aTHX_ a,b)
#define my_socketpair Perl_my_socketpair
+#define my_dirfd Perl_my_dirfd
#ifdef PERL_OLD_COPY_ON_WRITE
#if defined(PERL_CORE) || defined(PERL_EXT)
#define sv_setsv_cow(a,b) Perl_sv_setsv_cow(aTHX_ a,b)
Perl_sv_copypv
Perl_my_atof2
Perl_my_socketpair
+Perl_my_dirfd
Perl_sv_setsv_cow
Perl_PerlIO_context_layers
Perl_PerlIO_close
#endif
/* HMB H.Merijn Brand - a placeholder for preparing Configure patches */
-#if defined(HAS_MALLOC_SIZE) && defined(LOCALTIME_R_NEEDS_TZSET) && defined(HAS_DIR_DD_FD) && defined(HAS_PSEUDOFORK)
+#if defined(HAS_MALLOC_SIZE) && defined(LOCALTIME_R_NEEDS_TZSET) && defined(HAS_PSEUDOFORK)
/* Not (yet) used at top level, but mention them for metaconfig */
#endif
PL_laststatval =
PerlLIO_fstat(PerlIO_fileno(IoIFP(io)), &PL_statcache);
} else if (IoDIRP(io)) {
-#ifdef HAS_DIRFD
PL_laststatval =
- PerlLIO_fstat(dirfd(IoDIRP(io)), &PL_statcache);
-#else
- DIE(aTHX_ PL_no_func, "dirfd");
-#endif
+ PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache);
} else {
PL_laststatval = -1;
}
IO* const io = GvIO(gv);
if (io) {
if (IoDIRP(io)) {
-#ifdef HAS_DIRFD
- PUSHi(fchdir(dirfd(IoDIRP(io))) >= 0);
-#else
- DIE(aTHX_ PL_no_func, "dirfd");
-#endif
+ PUSHi(fchdir(my_dirfd(IoDIRP(io))) >= 0);
} else if (IoIFP(io)) {
PUSHi(fchdir(PerlIO_fileno(IoIFP(io))) >= 0);
}
__attribute__nonnull__(pTHX_2);
PERL_CALLCONV int Perl_my_socketpair(int family, int type, int protocol, int fd[2]);
+PERL_CALLCONV int Perl_my_dirfd(DIR* dir);
#ifdef PERL_OLD_COPY_ON_WRITE
PERL_CALLCONV SV* Perl_sv_setsv_cow(pTHX_ SV* dsv, SV* ssv)
__attribute__nonnull__(pTHX_1)
}
SKIP: {
- skip "No dirfd()", 9 unless $Config{d_dirfd};
+ skip "No dirfd()", 9 unless $Config{d_dirfd} || $Config{d_dir_dd_fd};
ok(opendir(DIR, "."), 'Can open "." dir') || diag "Can't open '.': $!";
ok(stat(DIR), "stat() on dirhandle works");
ok(-d -r _ , "chained -x's on dirhandle");
#PVIO's hold dirhandle information, so let's test them too.
SKIP: {
- skip "No dirfd()", 9 unless $Config{d_dirfd};
+ skip "No dirfd()", 9 unless $Config{d_dirfd} || $Config{d_dir_dd_fd};
ok(opendir(DIR, "."), 'Can open "." dir') || diag "Can't open '.': $!";
ok(stat(*DIR{IO}), "stat() on *DIR{IO} works");
ok(-d _ , "The special file handle _ is set correctly");
}
}
+int
+Perl_my_dirfd(DIR * dir) {
+
+ /* Most dirfd implementations have problems when passed NULL. */
+ if(!dir)
+ return -1;
+#ifdef HAS_DIRFD
+ return dirfd(dir);
+#elif defined(HAS_DIR_DD_FD)
+ return dir->dd_fd;
+#else
+ Perl_die(aTHX_ PL_no_func, "dirfd");
+ /* NOT REACHED */
+ return 0;
+#endif
+}
+
/*
* Local variables:
* c-indentation-style: bsd