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>
22 #include "giomodule.h"
23 #include "giomodule-priv.h"
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
38 _g_io_module_extract_name (const char *filename
)
42 gsize prefix_len
, len
;
45 bname
= g_path_get_basename (filename
);
46 for (i
= 0; bname
[i
]; ++i
)
52 if (g_str_has_prefix (bname
, "libgio"))
54 else if (g_str_has_prefix (bname
, "lib"))
57 prefix_len
= 0; /* use whole name (minus suffix) as plugin name */
59 dot
= strchr (bname
, '.');
61 len
= dot
- bname
- prefix_len
;
63 len
= strlen (bname
+ prefix_len
);
65 name
= g_strndup (bname
+ prefix_len
, len
);