/* Returns: a newly-allocated string containing all of the strings joined together, with @separator between them  */
gchar* g_strjoinv(const gchar *separator, gchar **str_array)
/* Returns: a newly-allocated string containing all of the strings joined together, with @separator between them  */
gchar* g_strjoinv(const gchar *separator, gchar **str_array)
{
  gchar *string;
  gchar *ptr;
  g_return_val_if_fail (str_array != NULL, NULL);
  if (separator == NULL)
    separator = "";
  if (*str_array)
    {
      gint i;
      gsize len;
      gsize separator_len;
      separator_len = strlen (separator);
      len = 1 + strlen (str_array[0]);
      for (i = 1; str_array[i] != NULL; i++)
        len += strlen (str_array[i]);
      len += separator_len * (i - 1);
      string = g_new (gchar, len);
      ptr = g_stpcpy (string, *str_array);
      for (i = 1; str_array[i] != NULL; i++)
        {
          ptr = g_stpcpy (ptr, separator);
          ptr = g_stpcpy (ptr, str_array[i]);
        }
      }
  else
    string = g_strdup ("");
  return string;
}