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