]> git.saurik.com Git - wxWidgets.git/blobdiff - src/unix/fswatcher_kqueue.cpp
Fix configure check for gcc atomics on 32-bit x86.
[wxWidgets.git] / src / unix / fswatcher_kqueue.cpp
index e1046e2ea4b3749b61913428c62fad910879d92c..2bc1634dfc26281b697e0863a44c9c676517898c 100644 (file)
@@ -3,7 +3,6 @@
 // Purpose:     kqueue-based wxFileSystemWatcher implementation
 // Author:      Bartosz Bekier
 // Created:     2009-05-26
-// RCS-ID:      $Id$
 // Copyright:   (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -115,8 +114,7 @@ public:
             wxLogSysError(_("Error closing kqueue instance"));
         }
 
-        delete m_source;
-        m_source = NULL;
+        wxDELETE(m_source);
     }
 
     virtual bool DoAdd(wxSharedPtr<wxFSWatchEntryKq> watch)
@@ -150,8 +148,7 @@ public:
         // TODO more error conditions according to man
         // XXX closing file descriptor removes the watch. The logic resides in
         // the watch which is not nice, but effective and simple
-        bool ret = watch->Close();
-        if (ret == -1)
+        if ( !watch->Close() )
         {
             wxLogSysError(_("Unable to remove kqueue watch"));
             return false;
@@ -298,7 +295,8 @@ protected:
         while ( nflags )
         {
             // when monitoring dir, this means create/delete
-            if ( nflags & NOTE_WRITE && wxDirExists(w.GetPath()) )
+            const wxString basepath = w.GetPath();
+            if ( nflags & NOTE_WRITE && wxDirExists(basepath) )
             {
                 // NOTE_LINK is set when the dir was created, but we
                 // don't care - we look for new names in directory
@@ -309,19 +307,17 @@ protected:
                 wxArrayString changedFiles;
                 wxArrayInt changedFlags;
                 FindChanges(w, changedFiles, changedFlags);
+
                 wxArrayString::iterator it = changedFiles.begin();
                 wxArrayInt::iterator changeType = changedFlags.begin();
                 for ( ; it != changedFiles.end(); ++it, ++changeType )
                 {
-                    wxFileName path;
-                    if ( wxDirExists(*it) )
-                    {
-                        path = wxFileName::DirName(w.GetPath() + *it);
-                    }
-                    else
-                    {
-                        path = wxFileName::FileName(w.GetPath() + *it);
-                    }
+                    const wxString fullpath = w.GetPath() +
+                                                wxFileName::GetPathSeparator() +
+                                                  *it;
+                    const wxFileName path(wxDirExists(fullpath)
+                                            ? wxFileName::DirName(fullpath)
+                                            : wxFileName::FileName(fullpath));
 
                     wxFileSystemWatcherEvent event(*changeType, path, path);
                     SendEvent(event);
@@ -334,28 +330,28 @@ protected:
                 // still we couldn't be sure we have the right name...
                 nflags &= ~NOTE_RENAME;
                 wxFileSystemWatcherEvent event(wxFSW_EVENT_RENAME,
-                                        w.GetPath(), wxFileName());
+                                        basepath, wxFileName());
                 SendEvent(event);
             }
             else if ( nflags & NOTE_WRITE || nflags & NOTE_EXTEND )
             {
                 nflags &= ~(NOTE_WRITE | NOTE_EXTEND);
                 wxFileSystemWatcherEvent event(wxFSW_EVENT_MODIFY,
-                                        w.GetPath(), w.GetPath());
+                                        basepath, basepath);
                 SendEvent(event);
             }
             else if ( nflags & NOTE_DELETE )
             {
                 nflags &= ~(NOTE_DELETE);
                 wxFileSystemWatcherEvent event(wxFSW_EVENT_DELETE,
-                                        w.GetPath(), w.GetPath());
+                                        basepath, basepath);
                 SendEvent(event);
             }
             else if ( nflags & NOTE_ATTRIB )
             {
                 nflags &= ~(NOTE_ATTRIB);
                 wxFileSystemWatcherEvent event(wxFSW_EVENT_ACCESS,
-                                        w.GetPath(), w.GetPath());
+                                        basepath, basepath);
                 SendEvent(event);
             }
 
@@ -419,11 +415,7 @@ wxKqueueFileSystemWatcher::wxKqueueFileSystemWatcher(const wxFileName& path,
 {
     if (!Init())
     {
-        if (m_service)
-        {
-            delete m_service;
-            m_service = NULL;
-        }
+        wxDELETE(m_service);
         return;
     }