Hi!

I've only been on this list a short while (since about January) and have
never made a post until today since you guys may my best bet for help. For
my Linux/Unix class my teacher wants us to do a simple rewrite of ls (mine
I'm calling els since my name is Eric). So far everything is working
correctly except when i try to use it giving it two command line arguments
(ex".$:./els -l ~") instead of giving a detailed list of my home directory
it gives a shorter detailed list of current directory and I'm not sure why.
Here's the section that handles two arguments and a paste bin of it for
better viewing. Thanks.

http://pastebin.com/gRnDpsmR

<code>
else if(argc == 3)
{
if((currentDirectory = opendir(argv[2]))!=NULL){
 printf("Why does this directory not work???: %s\n",argv[2]);
while(entry = readdir(currentDirectory)) {
 // printf("%s\n", entry->d_name);


if(stat(entry->d_name, &statbuf) ==-1)
continue;


// printf("%10.10s", sperm (statbuf.st_mode));
printf("%d", statbuf.st_nlink);

// printf("lol wut\n");

if((pwd = getpwuid(statbuf.st_uid))!=NULL)
printf(" %s", pwd->pw_name);
else
printf(" %d", statbuf.st_uid);

printf(" %9jd", (intmax_t)statbuf.st_size);
tm = localtime(&statbuf.st_mtime);
 strftime(datestring, sizeof(datestring), nl_langinfo(D_T_FMT),tm);
 printf(" %s %s\n", datestring, entry->d_name);
}
closedir(currentDirectory);
}
else {
printf("Error");
}
}
</code>

-- 
-Eric

Reply via email to