/src/glib/gio/giomodule-priv.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* GIO - GLib Input, Output and Streaming Library |
2 | | * |
3 | | * Copyright (C) 2017 Collabora Inc. |
4 | | * |
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. |
9 | | * |
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. |
14 | | * |
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/>. |
17 | | * |
18 | | * Author: Xavier Claessens <xavier.claessens@collabora.com> |
19 | | */ |
20 | | |
21 | | #include "config.h" |
22 | | #include "giomodule.h" |
23 | | #include "giomodule-priv.h" |
24 | | |
25 | | #include <string.h> |
26 | | |
27 | | /** |
28 | | * _g_io_module_extract_name: |
29 | | * @filename: filename of a GIOModule |
30 | | * |
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". |
34 | | * |
35 | | * Returns: (transfer full): the module's name |
36 | | */ |
37 | | gchar * |
38 | | _g_io_module_extract_name (const char *filename) |
39 | 0 | { |
40 | 0 | gchar *bname, *name; |
41 | 0 | const gchar *dot; |
42 | 0 | gsize prefix_len, len; |
43 | 0 | gsize i; |
44 | |
|
45 | 0 | bname = g_path_get_basename (filename); |
46 | 0 | for (i = 0; bname[i]; ++i) |
47 | 0 | { |
48 | 0 | if (bname[i] == '-') |
49 | 0 | bname[i] = '_'; |
50 | 0 | } |
51 | |
|
52 | 0 | if (g_str_has_prefix (bname, "libgio")) |
53 | 0 | prefix_len = 6; |
54 | | /* DLLs built with MSVC generally do not have the 'lib' prefix */ |
55 | 0 | else if (g_str_has_prefix (bname, "lib") || g_str_has_prefix (bname, "gio")) |
56 | 0 | prefix_len = 3; |
57 | 0 | else |
58 | 0 | prefix_len = 0; /* use whole name (minus suffix) as plugin name */ |
59 | |
|
60 | 0 | dot = strchr (bname, '.'); |
61 | 0 | if (dot != NULL) |
62 | 0 | len = dot - bname - prefix_len; |
63 | 0 | else |
64 | 0 | len = strlen (bname + prefix_len); |
65 | |
|
66 | 0 | name = g_strndup (bname + prefix_len, len); |
67 | 0 | g_free (bname); |
68 | |
|
69 | 0 | return name; |
70 | 0 | } |