Blame gio/giomodule-priv.c

Packit ae235b
/* GIO - GLib Input, Output and Streaming Library
Packit ae235b
 *
Packit ae235b
 * Copyright (C) 2017 Collabora Inc.
Packit ae235b
 *
Packit ae235b
 * This library is free software; you can redistribute it and/or
Packit ae235b
 * modify it under the terms of the GNU Lesser General Public
Packit ae235b
 * License as published by the Free Software Foundation; either
Packit ae235b
 * version 2.1 of the License, or (at your option) any later version.
Packit ae235b
 *
Packit ae235b
 * This library is distributed in the hope that it will be useful,
Packit ae235b
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit ae235b
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit ae235b
 * Lesser General Public License for more details.
Packit ae235b
 *
Packit ae235b
 * You should have received a copy of the GNU Lesser General
Packit ae235b
 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
Packit ae235b
 *
Packit ae235b
 * Author: Xavier Claessens <xavier.claessens@collabora.com>
Packit ae235b
 */
Packit ae235b
Packit ae235b
#include "config.h"
Packit ae235b
#include "giomodule.h"
Packit ae235b
#include "giomodule-priv.h"
Packit ae235b
Packit ae235b
#include <string.h>
Packit ae235b
Packit ae235b
/**
Packit ae235b
 * _g_io_module_extract_name:
Packit ae235b
 * @filename: filename of a GIOModule
Packit ae235b
 *
Packit ae235b
 * Extract the plugin name from its filename. It removes optional "lib" or
Packit ae235b
 * "libgio" prefix, and removes everything after the first dot. For example:
Packit ae235b
 * "libgiognutls.so" -> "gnutls".
Packit ae235b
 *
Packit ae235b
 * Returns: (transfer full): the module's name
Packit ae235b
 */
Packit ae235b
gchar *
Packit ae235b
_g_io_module_extract_name (const char *filename)
Packit ae235b
{
Packit ae235b
  gchar *bname, *name;
Packit ae235b
  const gchar *dot;
Packit ae235b
  gsize prefix_len, len;
Packit ae235b
  gsize i;
Packit ae235b
Packit ae235b
  bname = g_path_get_basename (filename);
Packit ae235b
  for (i = 0; bname[i]; ++i)
Packit ae235b
    {
Packit ae235b
      if (bname[i] == '-')
Packit ae235b
        bname[i] = '_';
Packit ae235b
    }
Packit ae235b
Packit ae235b
  if (g_str_has_prefix (bname, "libgio"))
Packit ae235b
    prefix_len = 6;
Packit ae235b
  else if (g_str_has_prefix (bname, "lib"))
Packit ae235b
    prefix_len = 3;
Packit ae235b
  else
Packit ae235b
    prefix_len = 0; /* use whole name (minus suffix) as plugin name */
Packit ae235b
Packit ae235b
  dot = strchr (bname, '.');
Packit ae235b
  if (dot != NULL)
Packit ae235b
    len = dot - bname - prefix_len;
Packit ae235b
  else
Packit ae235b
    len = strlen (bname + prefix_len);
Packit ae235b
Packit ae235b
  name = g_strndup (bname + prefix_len, len);
Packit ae235b
  g_free (bname);
Packit ae235b
Packit ae235b
  return name;
Packit ae235b
}