>From what I can tell from the man page of readdir it doesn't set errno,
so checking for non-zero errno isn't necessary.
Starting with what Nathan had I end up with:
int setupDirectoryPad(WINDOW ** pad, const char * dirName)
{
DIR * dir = NULL;
struct dirent * entry = NULL;
size_t width = 0;
size_t height = 0;
*pad = NULL;
int retval = -1;
if (dir = opendir(dirName))
{
while (entry = readdir(dir))
{
width = max(strlen(entry->d_name), width);
++height;
}
rewinddir(dir);
if (*pad = newpad())
{
while (entry = readdir(dir))
;
retval = 0;
}
else
perror("Error creating directory pad");
}
else
perror("Failed to open directory");
if (dir) closedir(dir);
return retval;
}
--------------------
BYU Unix Users Group
http://uug.byu.edu/
The opinions expressed in this message are the responsibility of their
author. They are not endorsed by BYU, the BYU CS Department or BYU-UUG.
___________________________________________________________________
List Info (unsubscribe here): http://uug.byu.edu/mailman/listinfo/uug-list