if (lstat (buf, &stat_buf)) { error (0, errno, _("Can't lstat %s"), buf); continue; } else if (S_ISDIR (stat_buf.st_mode) && is_hwcap (direntry->d_name))
search_dir (const struct dir_entry *entry){  DIR *dir;  struct dirent *direntry;  char buf [PATH_MAX];  char *soname;  struct dlib_entry *dlibs;  struct dlib_entry *dlib_ptr;  int nchars;  struct stat stat_buf;  int is_link;  unsigned long int hwcap = path_hwcap (entry->path);  dlibs = NULL;  if (opt_verbose)    {      if (hwcap != 0)	printf ("%s: (hwcap: 0x%lx)\n", entry->path, hwcap);      else	printf ("%s:\n", entry->path);    }  dir = opendir (entry->path);  if (dir == NULL)    {      if (opt_verbose)	error (0, errno, _("Can't open directory %s"), entry->path);      return;    }  while ((direntry = readdir (dir)) != NULL)    {      int flag;#ifdef _DIRENT_HAVE_D_TYPE      /* We only look at links and regular files.  */      if (direntry->d_type != DT_UNKNOWN	  && direntry->d_type != DT_LNK	  && direntry->d_type != DT_REG	  && direntry->d_type != DT_DIR)	continue;#endif /* _DIRENT_HAVE_D_TYPE  */      /* Does this file look like a shared library or is it a hwcap	 subdirectory?  The dynamic linker is also considered as	 shared library.  */      if (((strncmp (direntry->d_name, "lib", 3) != 0	    && strncmp (direntry->d_name, "ld-", 3) != 0)	   || strstr (direntry->d_name, ".so") == NULL)	  && !is_hwcap (direntry->d_name))	continue;      nchars = snprintf (buf, sizeof (buf), "%s/%s", entry->path,			 direntry->d_name);      /* Check for overflow.  */      if (nchars >= (int) sizeof (buf))	{	  error (0, 0, _("buffer for snprintf too small for %s/%s--file is ignored\n"),		 entry->path, direntry->d_name);	  continue;	}      if (lstat (buf, &stat_buf))	{	  error (0, errno, _("Can't lstat %s"), buf);	  continue;	}      else if (S_ISDIR (stat_buf.st_mode) && is_hwcap (direntry->d_name))	{	  /* Handle subdirectory also, make a recursive call.  */	  struct dir_entry new_entry;	  new_entry.path = buf;	  new_entry.flag = entry->flag;	  new_entry.next = NULL;	  search_dir (&new_entry);	  continue;	}      else if (!S_ISREG (stat_buf.st_mode) && !S_ISLNK (stat_buf.st_mode))	continue;      is_link = S_ISLNK (stat_buf.st_mode);      if (process_file (buf, direntry->d_name, &flag, &soname, is_link))	continue;      /* Links will just point to itself.  */      if (is_link)	{	  free (soname);	  soname = xstrdup (direntry->d_name);	}      if (flag == FLAG_ELF	  && (entry->flag == FLAG_ELF_LIBC5	      || entry->flag == FLAG_ELF_LIBC6))	flag = entry->flag;      /* Some sanity checks to print warnings.  */      if (opt_verbose)	{	  if (flag == FLAG_ELF_LIBC5 && entry->flag != FLAG_ELF_LIBC5	      && entry->flag != FLAG_ANY)	    error (0, 0, _("libc5 library %s in wrong directory"), buf);	  if (flag == FLAG_ELF_LIBC6 && entry->flag != FLAG_ELF_LIBC6	      && entry->flag != FLAG_ANY)	    error (0, 0, _("libc6 library %s in wrong directory"), buf);	  if (flag == FLAG_LIBC4 && entry->flag != FLAG_LIBC4	      && entry->flag != FLAG_ANY)	    error (0, 0, _("libc4 library %s in wrong directory"), buf);	}      /* Add library to list.  */      for (dlib_ptr = dlibs; dlib_ptr != NULL; dlib_ptr = dlib_ptr->next)	{	  /* Is soname already in list?  */	  if (strcmp (dlib_ptr->soname, soname) == 0)	    {	      /* Prefer a file to a link, otherwise check which one		 is newer.  */	      if ((!is_link && dlib_ptr->is_link)		  || (is_link == dlib_ptr->is_link		      && _dl_cache_libcmp (dlib_ptr->name, direntry->d_name) < 0))		{		  /* It's newer - add it.  */		  /* Flag should be the same - sanity check.  */		  if (dlib_ptr->flag != flag)		    {		      if (dlib_ptr->flag == FLAG_ELF			  && (flag == FLAG_ELF_LIBC5 || flag == FLAG_ELF_LIBC6))			dlib_ptr->flag = flag;		      else if ((dlib_ptr->flag == FLAG_ELF_LIBC5				|| dlib_ptr->flag == FLAG_ELF_LIBC6)			       && flag == FLAG_ELF)			dlib_ptr->flag = flag;		      else			error (0, 0, _("libraries %s and %s in directory %s have same soname but different type."),			       dlib_ptr->name, direntry->d_name, entry->path);		    }		  free (dlib_ptr->name);		  dlib_ptr->name = xstrdup (direntry->d_name);		  dlib_ptr->is_link = is_link;		}	      /* Don't add this library, abort loop.  */	      /* Also free soname, since it's dynamically allocated.  */	      free (soname);	      break;	    }	}      /* Add the library if it's not already in.  */      if (dlib_ptr == NULL)	{	  dlib_ptr = (struct dlib_entry *)xmalloc (sizeof (struct dlib_entry));	  dlib_ptr->name = xstrdup (direntry->d_name);	  dlib_ptr->flag = flag;	  dlib_ptr->soname = soname;	  dlib_ptr->is_link = is_link;	  /* Add at head of list.  */	  dlib_ptr->next = dlibs;	  dlibs = dlib_ptr;	}    }  closedir (dir);  /* Now dlibs contains a list of all libs - add those to the cache     and created all symbolic links.  */  for (dlib_ptr = dlibs; dlib_ptr != NULL; dlib_ptr = dlib_ptr->next)    {      /* Don't create links to links.  */      if (dlib_ptr->is_link == 0)	create_links (entry->path, dlib_ptr->name, dlib_ptr->soname);      if (opt_build_cache)	add_to_cache (entry->path, dlib_ptr->soname, dlib_ptr->flag, hwcap);    }  /* Free all resources.  */  while (dlibs)    {      dlib_ptr = dlibs;      free (dlib_ptr->soname);      free (dlib_ptr->name);      dlibs = dlibs->next;      free (dlib_ptr);    }}