ptg10805159
Section 18.9 Te rminal Identification 697
if ((ddp->d_name = strdup(dirname)) == NULL) {
free(ddp);
return;
}
ddp->d_next = NULL;
if (tail == NULL) {
head = ddp;
tail = ddp;
}else {
tail->d_next = ddp;
tail = ddp;
}
}
static void
cleanup(void)
{
struct devdir *ddp, *nddp;
ddp = head;
while (ddp != NULL) {
nddp = ddp->d_next;
free(ddp->d_name);
free(ddp);
ddp = nddp;
}
head = NULL;
tail = NULL;
}
static char *
searchdir(char *dirname, struct stat *fdstatp)
{
struct stat devstat;
DIR *dp;
int devlen;
struct dirent *dirp;
strcpy(pathname, dirname);
if ((dp = opendir(dirname)) == NULL)
return(NULL);
strcat(pathname, "/");
devlen = strlen(pathname);
while ((dirp = readdir(dp)) != NULL) {
strncpy(pathname + devlen, dirp->d_name,
_POSIX_PATH_MAX - devlen);
/*
*Skip aliases.
*/
if (strcmp(pathname, "/dev/stdin") == 0 ||