/src/glib/gio/inotify/inotify-sub.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */ |
2 | | |
3 | | /* inotify-sub.c - GVFS Monitor based on inotify. |
4 | | |
5 | | Copyright (C) 2006 John McCutchan |
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 Public License |
18 | | along with this library; if not, see <http://www.gnu.org/licenses/>. |
19 | | |
20 | | Authors: |
21 | | John McCutchan <john@johnmccutchan.com> |
22 | | */ |
23 | | |
24 | | #include "config.h" |
25 | | #include <string.h> |
26 | | #include <glib.h> |
27 | | |
28 | | #include "inotify-sub.h" |
29 | | |
30 | | static gboolean is_debug_enabled = FALSE; |
31 | 0 | #define IS_W if (is_debug_enabled) g_warning |
32 | | |
33 | | static gchar* |
34 | | dup_dirname (const gchar *dirname) |
35 | 0 | { |
36 | 0 | gchar *d_dirname = g_strdup (dirname); |
37 | 0 | size_t len = strlen (d_dirname); |
38 | | |
39 | 0 | if (d_dirname[len - 1] == '/') |
40 | 0 | d_dirname[len - 1] = '\0'; |
41 | | |
42 | 0 | return d_dirname; |
43 | 0 | } |
44 | | |
45 | | inotify_sub* |
46 | | _ih_sub_new (const gchar *dirname, |
47 | | const gchar *basename, |
48 | | const gchar *filename, |
49 | | gpointer user_data) |
50 | 0 | { |
51 | 0 | inotify_sub *sub = NULL; |
52 | | |
53 | 0 | sub = g_new0 (inotify_sub, 1); |
54 | |
|
55 | 0 | if (filename) |
56 | 0 | { |
57 | 0 | sub->dirname = g_path_get_dirname (filename); |
58 | 0 | sub->filename = g_path_get_basename (filename); |
59 | 0 | sub->hardlinks = TRUE; |
60 | 0 | } |
61 | 0 | else |
62 | 0 | { |
63 | 0 | sub->dirname = dup_dirname (dirname); |
64 | 0 | sub->filename = g_strdup (basename); |
65 | 0 | sub->hardlinks = FALSE; |
66 | 0 | } |
67 | |
|
68 | 0 | sub->user_data = user_data; |
69 | |
|
70 | 0 | IS_W ("new subscription for %s being setup\n", sub->dirname); |
71 | | |
72 | 0 | return sub; |
73 | 0 | } |
74 | | |
75 | | void |
76 | | _ih_sub_free (inotify_sub *sub) |
77 | 0 | { |
78 | 0 | g_free (sub->dirname); |
79 | 0 | g_free (sub->filename); |
80 | 0 | g_free (sub); |
81 | 0 | } |