#include <dirent.h>
#include "apue.h"
static int loop(const char* pathname);
int main(int argc, char* argv[])
{
struct stat buf;
if (lstat(argv[1], &buf) < 0) {
err_ret("lstat error");
continue;
}
else
loop(argv[1]);
printf("%s", argv[1]);
exit(0);
}
static int loop(const char* pathname)
{
struct dirent* dirp;
DIR* dp;
if ((dp = opendir(pathname)) == NULL)
err_sys("can't opendir %s", pathname);
if ((dirp = readdir(dp)) != NULL) {
if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)
continue;
loop(dirp);
strcpy(pathname, dirp->d_name);
printf("%s", dirp->d_name);
}
if (closedir(dp) < 0)
err_ret("can't close directory %s", pathname);
return(0);
}