decompose_rpath (const char *rpath, struct link_map *l, const char *what)
{
  /* Make a copy we can work with.  */
  const char *where = l->l_name;
  char *copy;
  char *cp;
  struct r_search_path_elem **result;
  size_t nelems;

  /* First see whether we must forget the RUNPATH and RPATH from this
     object.  */
  if (_dl_inhibit_rpath != NULL && !__libc_enable_secure)
    {
      const char *found = strstr (_dl_inhibit_rpath, where);
      if (found != NULL)
	{
	  size_t len = strlen (where);
	  if ((found == _dl_inhibit_rpath || found[-1] == ':')
	      && (found[len] == '\0' || found[len] == ':'))
	    {
	      /* This object is on the list of objects for which the
		 RUNPATH and RPATH must not be used.  */
	      result = (struct r_search_path_elem **)
		malloc (sizeof (*result));
	      if (result == NULL)
		_dl_signal_error (ENOMEM, NULL,
				  "cannot create cache for search path");
	      result[0] = NULL;

	      return result;
	    }
	}
    }

  /* Make a writable copy.  At the same time expand possible dynamic
     string tokens.  */
  copy = expand_dynamic_string_token (l, rpath);
  if (copy == NULL)
    _dl_signal_error (ENOMEM, NULL, "cannot create RUNPATH/RPATH copy");

  /* Count the number of necessary elements in the result array.  */
  nelems = 0;
  for (cp = copy; *cp != '\0'; ++cp)
    if (*cp == ':')
      ++nelems;

  /* Allocate room for the result.  NELEMS + 1 is an upper limit for the
     number of necessary entries.  */
  result = (struct r_search_path_elem **) malloc ((nelems + 1 + 1)
						  * sizeof (*result));
  if (result == NULL)
    _dl_signal_error (ENOMEM, NULL, "cannot create cache for search path");

  return fillin_rpath (copy, result, ":", 0, what, where);
}
decompose_rpath (const char *rpath, struct link_map *l, const char *what)
{
   
  const char *where = l->l_name;
  char *copy;
  char *cp;
  struct r_search_path_elem **result;
  size_t nelems;

   
  if (_dl_inhibit_rpath != NULL && !__libc_enable_secure)
    {
      const char *found = strstr (_dl_inhibit_rpath, where);
      if (found != NULL)
	{
	  size_t len = strlen (where);
	  if ((found == _dl_inhibit_rpath || found[-1] == ':')
	      && (found[len] == '\0' || found[len] == ':'))
	    {
	       
	      result = (struct r_search_path_elem **)
		malloc (sizeof (*result));
	      if (result == NULL)
		_dl_signal_error (ENOMEM, NULL,
				  "cannot create cache for search path");
	      result[0] = NULL;

	      return result;
	    }
	}
    }

   
  copy = expand_dynamic_string_token (l, rpath);
  if (copy == NULL)
    _dl_signal_error (ENOMEM, NULL, "cannot create RUNPATH/RPATH copy");

   
  nelems = 0;
  for (cp = copy; *cp != '\0'; ++cp)
    if (*cp == ':')
      ++nelems;

   
  result = (struct r_search_path_elem **) malloc ((nelems + 1 + 1)
						  * sizeof (*result));
  if (result == NULL)
    _dl_signal_error (ENOMEM, NULL, "cannot create cache for search path");

  return fillin_rpath (copy, result, ":", 0, what, where);
}