X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FCwd%2FCwd.xs;h=f53f6ee19e408064a24338c133d2c11cc006dd0c;hb=91f3b821ca3eaa8b7d74bb338729ba51b7b68a90;hp=82b89ac16bec50e7b310e3addec5e1e346c8e5e2;hpb=c70498c117875832199c38c377c90989d6837b1a;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Cwd/Cwd.xs b/ext/Cwd/Cwd.xs index 82b89ac..f53f6ee 100644 --- a/ext/Cwd/Cwd.xs +++ b/ext/Cwd/Cwd.xs @@ -70,15 +70,17 @@ bsd_realpath(path, resolved) char *resolved; { #ifdef VMS - return Perl_rmsexpand((char*)path, resolved, NULL, 0); + dTHX; + return Perl_rmsexpand(aTHX_ (char*)path, resolved, NULL, 0); #else - struct stat sb; - int fd, n, rootd, serrno; + int rootd, serrno; char *p, *q, wbuf[MAXPATHLEN]; int symlinks = 0; /* Save the starting point. */ #ifdef HAS_FCHDIR + int fd; + if ((fd = open(".", O_RDONLY)) < 0) { (void)strcpy(resolved, "."); return (NULL); @@ -120,10 +122,13 @@ loop: } else p = resolved; -#ifdef HAS_LSTAT +#if defined(HAS_LSTAT) && defined(HAS_READLINK) && defined(HAS_SYMLINK) + { + struct stat sb; /* Deal with the last component. */ if (lstat(p, &sb) == 0) { if (S_ISLNK(sb.st_mode)) { + int n; if (++symlinks > MAXSYMLINKS) { errno = ELOOP; goto err1; @@ -140,6 +145,7 @@ loop: p = ""; } } + } #endif /* @@ -183,7 +189,9 @@ loop: #endif /* It's okay if the close fails, what's an fd more or less? */ +#ifdef HAS_FCHDIR (void)close(fd); +#endif return (resolved); err1: serrno = errno; @@ -192,7 +200,11 @@ err1: serrno = errno; #else (void)chdir(wd); #endif -err2: (void)close(fd); + +err2: +#ifdef HAS_FCHDIR + (void)close(fd); +#endif errno = serrno; return (NULL); #endif @@ -204,10 +216,11 @@ PROTOTYPES: ENABLE void fastcwd() +PROTOTYPE: DISABLE PPCODE: { dXSTARG; - sv_getcwd(TARG); + getcwd_sv(TARG); XSprePUSH; PUSHTARG; } @@ -218,22 +231,20 @@ PPCODE: { dXSTARG; char *path; - STRLEN len; char buf[MAXPATHLEN]; - if (pathsv) - path = SvPV(pathsv, len); - else { - path = "."; - len = 1; - } + path = pathsv ? SvPV_nolen(pathsv) : "."; if (bsd_realpath(path, buf)) { sv_setpvn(TARG, buf, strlen(buf)); SvPOK_only(TARG); + SvTAINTED_on(TARG); } else - sv_setsv(TARG, &PL_sv_undef); + sv_setsv(TARG, &PL_sv_undef); XSprePUSH; PUSHTARG; +#ifndef INCOMPLETE_TAINTS + SvTAINTED_on(TARG); +#endif }