/* ECP: FILEname=fig13_7.c */ /* 1*/ void /* 2*/ Pwd1( const char *DirName, const struct stat *Dot ) /* 3*/ { /* 4*/ struct stat DotDot, Buf; /* 5*/ char FileName[ MAXPATHLEN ], Parent[ MAXPATHLEN ]; /* 6*/ DIR *ParentDir; /* 7*/ struct dirent *Slot; /* 8*/ if( IsMatch( Dot, &Slash ) ) /* Base Case */ /* 9*/ return; /* We Are At Slash */ /*10*/ /* First, Recursively Print Up To The Parent */ /*11*/ sprintf( Parent, "%s/..", DirName ); /*12*/ if( lstat( Parent, &DotDot ) < 0 ) /*13*/ { /*14*/ perror( Parent ); /*15*/ return; /*16*/ } /*17*/ Pwd1( Parent, &DotDot ); /*18*/ /* Now, Print Last Component Of The Pathname */ /*19*/ if( ( ParentDir = opendir( Parent ) ) == NULL ) /*20*/ { /*21*/ perror( Parent ); /*22*/ return; /*23*/ } /*24*/ while( ( Slot = readdir( ParentDir ) ) != NULL ) /*25*/ { /*26*/ sprintf( FileName, "%s/%s", Parent, Slot->d_name ); /*27*/ if( !lstat( FileName, &Buf ) && IsMatch( &Buf, Dot ) ) /*28*/ { /*29*/ printf( "/%s", Slot->d_name ); /*30*/ closedir( ParentDir ); /*31*/ return; /*32*/ } /*33*/ } /*34*/ printf( "/???" ); /* This Should Never Occur */ /*35*/ }