Initialize variable
[glib.git] / gio / giomodule-priv.c
blob41afa54a053ee443c740666e5ed280d74d6a52cc
1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2017 Collabora Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 * Author: Xavier Claessens <xavier.claessens@collabora.com>
21 #include "config.h"
22 #include "giomodule.h"
23 #include "giomodule-priv.h"
25 #include <string.h>
27 /**
28 * _g_io_module_extract_name:
29 * @filename: filename of a GIOModule
31 * Extract the plugin name from its filename. It removes optional "lib" or
32 * "libgio" prefix, and removes everything after the first dot. For example:
33 * "libgiognutls.so" -> "gnutls".
35 * Returns: (transfer full): the module's name
37 gchar *
38 _g_io_module_extract_name (const char *filename)
40 gchar *bname, *name;
41 const gchar *dot;
42 gsize prefix_len, len;
43 gsize i;
45 bname = g_path_get_basename (filename);
46 for (i = 0; bname[i]; ++i)
48 if (bname[i] == '-')
49 bname[i] = '_';
52 if (g_str_has_prefix (bname, "libgio"))
53 prefix_len = 6;
54 else if (g_str_has_prefix (bname, "lib"))
55 prefix_len = 3;
56 else
57 prefix_len = 0; /* use whole name (minus suffix) as plugin name */
59 dot = strchr (bname, '.');
60 if (dot != NULL)
61 len = dot - bname - prefix_len;
62 else
63 len = strlen (bname + prefix_len);
65 name = g_strndup (bname + prefix_len, len);
66 g_free (bname);
68 return name;