Imported Upstream version 2.48.0
[platform/upstream/glib.git] / gio / inotify / inotify-sub.c
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    The Gnome Library is free software; you can redistribute it and/or
8    modify it under the terms of the GNU Library General Public License as
9    published by the Free Software Foundation; either version 2 of the
10    License, or (at your option) any later version.
11
12    The Gnome 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    Library General Public License for more details.
16
17    You should have received a copy of the GNU Library General Public
18    License along with the Gnome Library; see the file COPYING.LIB.  If not,
19    see <http://www.gnu.org/licenses/>.
20
21    Authors: 
22                  John McCutchan <john@johnmccutchan.com>
23 */
24
25 #include "config.h"
26 #include <string.h>
27 #include <glib.h>
28
29 #include "inotify-sub.h"
30
31 static gboolean is_debug_enabled = FALSE;
32 #define IS_W if (is_debug_enabled) g_warning
33
34 static gchar*
35 dup_dirname (const gchar *dirname)
36 {
37   gchar *d_dirname = g_strdup (dirname);
38   size_t len = strlen (d_dirname);
39   
40   if (d_dirname[len - 1] == '/')
41     d_dirname[len - 1] = '\0';
42   
43   return d_dirname;
44 }
45
46 inotify_sub*
47 _ih_sub_new (const gchar *dirname, 
48              const gchar *filename,
49              gboolean     watch_hardlinks,
50              gpointer     user_data)
51 {
52   inotify_sub *sub = NULL;
53   
54   sub = g_new0 (inotify_sub, 1);
55   sub->dirname = dup_dirname (dirname);
56   sub->filename = g_strdup (filename);
57   sub->hardlinks = watch_hardlinks;
58   sub->user_data = user_data;
59
60   IS_W ("new subscription for %s being setup\n", sub->dirname);
61   
62   return sub;
63 }
64
65 void
66 _ih_sub_free (inotify_sub *sub)
67 {
68   g_free (sub->dirname);
69   g_free (sub->filename);
70   g_free (sub);
71 }