summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorGisle Aas <gisle@aas.no>2005-07-14 19:32:50 -0700
committerH.Merijn Brand <h.m.brand@xs4all.nl>2005-07-16 08:07:44 +0000
commitc4aca7d03737ddcac23de1ad6d597e98be679214 (patch)
tree0a3a2c3042bba6da8246cf336e1c4d10f6aa61d1 /pp_sys.c
parentaec46f14fac1bc74bf8ad4054a6f9674b324f8d2 (diff)
downloadperl-c4aca7d03737ddcac23de1ad6d597e98be679214.tar.gz
Re: fchmod, fchown, fchdir
Message-ID: <lrwtnse7nh.fsf@caliper.activestate.com> + Schwern's ok -> like changes p4raw-id: //depot/perl@25157
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c49
1 files changed, 42 insertions, 7 deletions
diff --git a/pp_sys.c b/pp_sys.c
index 2d1752bf1b..4430789dfe 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -3542,15 +3542,24 @@ PP(pp_ftbinary)
PP(pp_chdir)
{
dSP; dTARGET;
- const char *tmps;
+ const char *tmps = 0;
+ GV *gv = 0;
SV **svp;
- if( MAXARG == 1 )
- tmps = POPpconstx;
- else
- tmps = 0;
+ if( MAXARG == 1 ) {
+ SV *sv = POPs;
+ if (SvTYPE(sv) == SVt_PVGV) {
+ gv = (GV*)sv;
+ }
+ else if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PVGV) {
+ gv = (GV*)SvRV(sv);
+ }
+ else {
+ tmps = SvPVx_nolen_const(sv);
+ }
+ }
- if( !tmps || !*tmps ) {
+ if( !gv && (!tmps || !*tmps) ) {
if ( (svp = hv_fetch(GvHVn(PL_envgv), "HOME", 4, FALSE))
|| (svp = hv_fetch(GvHVn(PL_envgv), "LOGDIR", 6, FALSE))
#ifdef VMS
@@ -3570,7 +3579,33 @@ PP(pp_chdir)
}
TAINT_PROPER("chdir");
- PUSHi( PerlDir_chdir(tmps) >= 0 );
+ if (gv) {
+#ifdef HAS_FCHDIR
+ IO* io = GvIO(gv);
+ if (io) {
+ if (IoIFP(io)) {
+ PUSHi(fchdir(PerlIO_fileno(IoIFP(io))) >= 0);
+ }
+ else if (IoDIRP(io)) {
+#ifdef HAS_DIRFD
+ PUSHi(fchdir(dirfd(IoDIRP(io))) >= 0);
+#else
+ DIE(aTHX PL_no_func, "dirfd");
+#endif
+ }
+ else {
+ PUSHi(0);
+ }
+ }
+ else {
+ PUSHi(0);
+ }
+#else
+ DIE(aTHX_ PL_no_func, "fchdir");
+#endif
+ }
+ else
+ PUSHi( PerlDir_chdir(tmps) >= 0 );
#ifdef VMS
/* Clear the DEFAULT element of ENV so we'll get the new value
* in the future. */