nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* GIO - GLib Input, Output and Streaming Library |
2 | * |
||
3 | * Copyright (C) 2006-2007 Red Hat, 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 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: Alexander Larsson <alexl@redhat.com> |
||
19 | */ |
||
20 | |||
21 | #include "config.h" |
||
22 | #include "giomodule.h" |
||
23 | |||
24 | #include <gstdio.h> |
||
25 | #include <errno.h> |
||
26 | |||
27 | static gboolean |
||
28 | is_valid_module_name (const gchar *basename) |
||
29 | { |
||
30 | #if !defined(G_OS_WIN32) && !defined(G_WITH_CYGWIN) |
||
31 | return |
||
32 | g_str_has_prefix (basename, "lib") && |
||
33 | g_str_has_suffix (basename, ".so"); |
||
34 | #else |
||
35 | return g_str_has_suffix (basename, ".dll"); |
||
36 | #endif |
||
37 | } |
||
38 | |||
39 | static void |
||
40 | query_dir (const char *dirname) |
||
41 | { |
||
42 | GString *data; |
||
43 | GDir *dir; |
||
44 | const char *name; |
||
45 | char *cachename; |
||
46 | char **(* query) (void); |
||
47 | GError *error; |
||
48 | int i; |
||
49 | |||
50 | if (!g_module_supported ()) |
||
51 | return; |
||
52 | |||
53 | error = NULL; |
||
54 | dir = g_dir_open (dirname, 0, &error); |
||
55 | if (!dir) |
||
56 | { |
||
57 | g_printerr ("Unable to open directory %s: %s\n", dirname, error->message); |
||
58 | g_error_free (error); |
||
59 | return; |
||
60 | } |
||
61 | |||
62 | data = g_string_new (""); |
||
63 | |||
64 | while ((name = g_dir_read_name (dir))) |
||
65 | { |
||
66 | GModule *module; |
||
67 | gchar *path; |
||
68 | char **extension_points; |
||
69 | |||
70 | if (!is_valid_module_name (name)) |
||
71 | continue; |
||
72 | |||
73 | path = g_build_filename (dirname, name, NULL); |
||
74 | module = g_module_open (path, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); |
||
75 | g_free (path); |
||
76 | |||
77 | if (module) |
||
78 | { |
||
79 | g_module_symbol (module, "g_io_module_query", (gpointer) &query); |
||
80 | |||
81 | if (query) |
||
82 | { |
||
83 | extension_points = query (); |
||
84 | |||
85 | if (extension_points) |
||
86 | { |
||
87 | g_string_append_printf (data, "%s: ", name); |
||
88 | |||
89 | for (i = 0; extension_points[i] != NULL; i++) |
||
90 | g_string_append_printf (data, "%s%s", i == 0 ? "" : ",", extension_points[i]); |
||
91 | |||
92 | g_string_append (data, "\n"); |
||
93 | g_strfreev (extension_points); |
||
94 | } |
||
95 | } |
||
96 | |||
97 | g_module_close (module); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | g_dir_close (dir); |
||
102 | |||
103 | cachename = g_build_filename (dirname, "giomodule.cache", NULL); |
||
104 | |||
105 | if (data->len > 0) |
||
106 | { |
||
107 | error = NULL; |
||
108 | |||
109 | if (!g_file_set_contents (cachename, data->str, data->len, &error)) |
||
110 | { |
||
111 | g_printerr ("Unable to create %s: %s\n", cachename, error->message); |
||
112 | g_error_free (error); |
||
113 | } |
||
114 | } |
||
115 | else |
||
116 | { |
||
117 | if (g_unlink (cachename) != 0 && errno != ENOENT) |
||
118 | g_printerr ("Unable to unlink %s: %s\n", cachename, g_strerror (errno)); |
||
119 | } |
||
120 | |||
121 | g_string_free (data, TRUE); |
||
122 | } |
||
123 | |||
124 | int |
||
125 | main (gint argc, |
||
126 | gchar *argv[]) |
||
127 | { |
||
128 | int i; |
||
129 | |||
130 | if (argc == 1) |
||
131 | { |
||
132 | g_print ("Usage: gio-querymodules <directory1> [<directory2> ...]\n"); |
||
133 | g_print ("Will update giomodule.cache in the listed directories\n"); |
||
134 | return 1; |
||
135 | } |
||
136 | |||
137 | /* Be defensive and ensure we're linked to GObject */ |
||
138 | g_type_ensure (G_TYPE_OBJECT); |
||
139 | |||
140 | for (i = 1; i < argc; i++) |
||
141 | query_dir (argv[i]); |
||
142 | |||
143 | return 0; |
||
144 | } |