From: Jarkko Hietaniemi Date: Thu, 21 Jun 2001 19:03:48 +0000 (+0000) Subject: Protect the fchdir() and lstat() with ifdefs. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e3d944f4dd784cff30477bcd6cf567adfcabc9ba;p=p5sagit%2Fp5-mst-13.2.git Protect the fchdir() and lstat() with ifdefs. fchdir() needs a Configure probe. p4raw-id: //depot/perl@10795 --- diff --git a/ext/Cwd/Cwd.xs b/ext/Cwd/Cwd.xs index 2d03278..6935155 100644 --- a/ext/Cwd/Cwd.xs +++ b/ext/Cwd/Cwd.xs @@ -65,17 +65,28 @@ bsd_realpath(path, resolved) const char *path; char *resolved; { -#ifndef VMS +#ifdef VMS + return Perl_rmsexpand((char*)path, resolved, NULL, 0); +#else struct stat sb; int fd, n, rootd, serrno; char *p, *q, wbuf[MAXPATHLEN]; int symlinks = 0; /* Save the starting point. */ +#ifdef HAS_FCHDIR if ((fd = open(".", O_RDONLY)) < 0) { (void)strcpy(resolved, "."); return (NULL); } +#else + char wd[MAXPATHLEN]; + + if (getcwd(wd, MAXPATHLEN - 1) == NULL) { + (void)strcpy(resolved, "."); + return (NULL); + } +#endif /* * Find the dirname and basename from the path to be resolved. @@ -105,6 +116,7 @@ loop: } else p = resolved; +#ifdef HAS_LSTAT /* Deal with the last component. */ if (lstat(p, &sb) == 0) { if (S_ISLNK(sb.st_mode)) { @@ -124,6 +136,7 @@ loop: p = ""; } } +#endif /* * Save the last component name and get the full pathname of @@ -153,10 +166,17 @@ loop: } /* Go back to where we came from. */ +#ifdef HAS_FCHDIR if (fchdir(fd) < 0) { serrno = errno; goto err2; } +#else + if (chdir(wd) < 0) { + serrno = errno; + goto err2; + } +#endif /* It's okay if the close fails, what's an fd more or less? */ (void)close(fd); @@ -167,12 +187,7 @@ err1: serrno = errno; err2: (void)close(fd); errno = serrno; return (NULL); - -#else /* it's VMS */ - - return Perl_rmsexpand((char*)path, resolved, NULL, 0); - -#endif /* ifndef VMS */ +#endif } MODULE = Cwd PACKAGE = Cwd