#!/afs/athena/contrib/perl/perl

require "stat.pl";

# prototype pwd that does not chdir

&Stat('/');

$root_dev = $st_dev;
$root_ino = $st_ino;

$wd = '.';

$big = 20;

while ( --$big > 0 ) {

	&Stat( $wd );
	$save_dev = $st_dev;
	$save_ino = $st_ino;

	if ( $root_dev == $save_dev && $root_ino == $save_ino ) {
		print '/' . join( '/', @pwd ) . "\n";
		exit( 0 );
	}

	$wd .= '/..';

	opendir( DIR, $wd ) || die "Can't open $wd";
	@filenames = readdir( DIR );
	closedir( DIR );

	for (@filenames) {
		next if $_ eq '.';
		next if $_ eq '..';
		&Stat( $wd . '/' . $_ );
		if ( $st_dev == $save_dev && $st_ino == $save_ino ) {
			unshift( @pwd, $_ );
			last;
		}
	}
}

die "Got stuck.";
