Home | History | Annotate | Download | only in inotify
      1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
      2 
      3 /* inotify-sub.c - GMonitor 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    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
     20    Boston, MA 02111-1307, USA.
     21 
     22    Authors:
     23 		 John McCutchan <john (at) johnmccutchan.com>
     24 */
     25 
     26 #include "config.h"
     27 #include <string.h>
     28 #include <glib.h>
     29 
     30 #include "inotify-sub.h"
     31 
     32 static gboolean is_debug_enabled = FALSE;
     33 #define IS_W if (is_debug_enabled) g_warning
     34 
     35 static gchar*
     36 dup_dirname (const gchar *dirname)
     37 {
     38   gchar *d_dirname = g_strdup (dirname);
     39   size_t len = strlen (d_dirname);
     40 
     41   if (d_dirname[len - 1] == '/')
     42     d_dirname[len - 1] = '\0';
     43 
     44   return d_dirname;
     45 }
     46 
     47 inotify_sub*
     48 _ih_sub_new (const gchar *dirname,
     49              const gchar *filename,
     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->user_data = user_data;
     58 
     59   IS_W ("new subscription for %s being setup\n", sub->dirname);
     60 
     61   return sub;
     62 }
     63 
     64 void
     65 _ih_sub_free (inotify_sub *sub)
     66 {
     67   g_free (sub->dirname);
     68   g_free (sub->filename);
     69   g_free (sub);
     70 }
     71