X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=ext%2FCwd%2FCwd.xs;h=b6f27b8d094c2e68d40196d027734cc2c025c2e1;hb=894237640a8731055a749592e01318892443c38d;hp=6935155a40820e83fdf268a2728aef04be937f9b;hpb=e3d944f4dd784cff30477bcd6cf567adfcabc9ba;p=p5sagit%2Fp5-mst-13.2.git diff --git a/ext/Cwd/Cwd.xs b/ext/Cwd/Cwd.xs index 6935155..b6f27b8 100644 --- a/ext/Cwd/Cwd.xs +++ b/ext/Cwd/Cwd.xs @@ -2,6 +2,10 @@ #include "perl.h" #include "XSUB.h" +#ifdef I_UNISTD +# include +#endif + /* The realpath() implementation from OpenBSD 2.9 (realpath.c 1.4) * Renamed here to bsd_realpath() to avoid library conflicts. * --jhi 2000-06-20 */ @@ -179,12 +183,22 @@ 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; +#ifdef HAS_FCHDIR (void)fchdir(fd); -err2: (void)close(fd); +#else + (void)chdir(wd); +#endif + +err2: +#ifdef HAS_FCHDIR + (void)close(fd); +#endif errno = serrno; return (NULL); #endif @@ -199,7 +213,7 @@ fastcwd() PPCODE: { dXSTARG; - sv_getcwd(TARG); + getcwd_sv(TARG); XSprePUSH; PUSHTARG; } @@ -211,29 +225,21 @@ PPCODE: dXSTARG; char *path; STRLEN len; - char *buf; - - New(0, buf, MAXPATHLEN, char); - if (buf) { - buf[MAXPATHLEN] = 0; - if (pathsv) - path = SvPV(pathsv, len); - else { - path = "."; - len = 1; - } + char buf[MAXPATHLEN]; - if (bsd_realpath(path, buf)) { - sv_setpvn(TARG, buf, strlen(buf)); - SvPOK_only(TARG); - } - else - sv_setsv(TARG, &PL_sv_undef); + if (pathsv) + path = SvPV(pathsv, len); + else { + path = "."; + len = 1; + } - Safefree(buf); + if (bsd_realpath(path, buf)) { + sv_setpvn(TARG, buf, strlen(buf)); + SvPOK_only(TARG); } else - sv_setsv(TARG, &PL_sv_undef); + sv_setsv(TARG, &PL_sv_undef); XSprePUSH; PUSHTARG; }