On 14 Jul 2005 15:27:04 -0700, Gisle Aas <[EMAIL PROTECTED]> wrote:

> I would like to be able to pass file handles to chmod(), chown() and
> chdir() and have perl call the corresponding fxxx() function.  This is
> similar to how perl treats the argument of stat() or truncate().
> 
> Below is an implementation that make perl call fchmod().  If there are
> no objections to this approach, I'll complete a patch that includes
> the other 2 functions and comes with tests and documentation.
> Configure already probes for the availability of these functions.

I'm all ears :)
I'll just wait for the full patch, which I presume also has several test
cases along with it.

> --- doio.c.orig       2005-07-14 23:52:24.000000000 +0200
> +++ doio.c    2005-07-15 00:06:48.000000000 +0200
> @@ -1677,10 +1677,33 @@
>           APPLY_TAINT_PROPER();
>           tot = sp - mark;
>           while (++mark <= sp) {
> -             const char *name = SvPV_nolen_const(*mark);
> -             APPLY_TAINT_PROPER();
> -             if (PerlLIO_chmod(name, val))
> -                 tot--;
> +                GV* gv;
> +                if (SvTYPE(*mark) == SVt_PVGV) {
> +                    gv = (GV*)*mark;
> +             do_fchmod:
> +#ifdef HAS_FCHMOD
> +                 if (GvIO(gv) && IoIFP(GvIOp(gv))) {
> +                     APPLY_TAINT_PROPER();
> +                     if (fchmod(PerlIO_fileno(IoIFP(GvIOn(gv))), val))
> +                         tot--;
> +#else
> +                     DIE(aTHX_ PL_no_func, "fchmod");
> +#endif
> +                 }
> +                 else {
> +                     tot--;
> +                 }
> +             }
> +             else if (SvROK(*mark) && SvTYPE(SvRV(*mark)) == SVt_PVGV) {
> +                 gv = (GV*)SvRV(*mark);
> +                 goto do_fchmod;
> +             }
> +             else {
> +                 const char *name = SvPV_nolen_const(*mark);
> +                 APPLY_TAINT_PROPER();
> +                 if (PerlLIO_chmod(name, val))
> +                     tot--;
> +             }
>           }
>       }
>       break;
> 


-- 
H.Merijn Brand        Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using Perl 5.6.2, 5.8.0, 5.8.5, & 5.9.2  on HP-UX 10.20, 11.00 & 11.11,
 AIX 4.3 & 5.2, SuSE 9.2 & 9.3, and Cygwin. http://www.cmve.net/~merijn
Smoking perl: http://www.test-smoke.org,    perl QA: http://qa.perl.org
 reports  to: [EMAIL PROTECTED],                perl-qa@perl.org

Reply via email to