Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.lang.perl Subject: Re: pwd in perl Message-ID: Date: 10 Aug 90 15:20:18 GMT References: <1141@etnibsd.UUCP> <1990Aug9.225658.11586@NCoast.ORG> Sender: news@OSF.ORG Followup-To: comp.lang.perl Organization: Open Software Foundation Lines: 36 In-reply-to: allbery@NCoast.ORG's message of 9 Aug 90 22:56:58 GMT In article <1990Aug9.225658.11586@NCoast.ORG> allbery@NCoast.ORG (Brandon S. Allbery KB8JRR/KT) writes: | As quoted from <1141@etnibsd.UUCP> by vsh@etnibsd.UUCP (Steve Harris): | +--------------- | | while ($f = readdir(D)) { | | next if $f eq '..'; # skip '..' | | next if -l $f; # skip links (but do lstat!) | | next unless -d _; # skip non-dirs | | ($d,$i) = stat(_); # get dev, ino for dir | | next unless ($d == $dc && $i == $ic); # match? | | last outerloop if ($f eq '.'); # root dir? | | unshift(@path,$f); # add dir to path | | ($dc,$ic) = ($dp,$ip); # parent becomes next child | | last; # exit readdir loop | | } | +--------------- | | How about mount points? I'm almost *never* in the root file system. | You should also provide a way to get back where you were before you started; | preferably, opendir() a string which is built incrementally ("../../.."...). | | I just use chop($cwd = `pwd`); myself. If it ever bothers me, I'll port Doug | Gwyn's getcwd() to Perl. | | ++Brandon Another thing that I don't think has been mentioned, is that you might be in a directory whose parent directory you have no access to. In this case reading ..'s files until you find . will not work. This is why pwd must be setuid root, so that it can do the appropriate checks. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142 Do apple growers tell their kids money doesn't grow on bushes?