Coverage Report

Created: 2025-06-13 06:55

/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
 * 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
_g_io_module_extract_name (const char *filename)
43
0
{
44
0
  gchar *bname, *name;
45
0
  const gchar *dot;
46
0
  gsize prefix_len, len;
47
0
  gsize i;
48
49
0
  bname = g_path_get_basename (filename);
50
0
  for (i = 0; bname[i]; ++i)
51
0
    {
52
0
      if (bname[i] == '-')
53
0
        bname[i] = '_';
54
0
    }
55
56
0
  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
0
  else if (g_str_has_prefix (bname, "lib") || g_str_has_prefix (bname, "gio"))
60
0
    prefix_len = 3;
61
0
  else
62
0
    prefix_len = 0; /* use whole name (minus suffix) as plugin name */
63
64
0
  dot = strchr (bname, '.');
65
0
  if (dot != NULL)
66
0
    len = dot - bname - prefix_len;
67
0
  else
68
0
    len = strlen (bname + prefix_len);
69
70
0
  name = g_strndup (bname + prefix_len, len);
71
0
  g_free (bname);
72
73
0
  return name;
74
0
}