]> code.delx.au - gnu-emacs/blobdiff - src/w32notify.c
Update copyright year to 2016
[gnu-emacs] / src / w32notify.c
index ab6cd12ab938e6305e811aadf3fe43609f76e4b4..576cf844dab03e78f75afc35ad40197e19f443b0 100644 (file)
@@ -1,5 +1,5 @@
 /* Filesystem notifications support for GNU Emacs on the Microsoft Windows API.
-   Copyright (C) 2012-2015 Free Software Foundation, Inc.
+   Copyright (C) 2012-2016 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -525,11 +525,11 @@ generate notifications correctly, though.  */)
 
   /* The underlying features are available only since XP.  */
   if (os_subtype == OS_9X
-      || (w32_major_version == 5 && w32_major_version < 1))
+      || (w32_major_version == 5 && w32_minor_version < 1))
     {
       errno = ENOSYS;
-      report_file_error ("Watching filesystem events is not supported",
-                        Qnil);
+      report_file_notify_error ("Watching filesystem events is not supported",
+                               Qnil);
     }
 
   /* filenotify.el always passes us a directory, either the parent
@@ -573,11 +573,11 @@ generate notifications correctly, though.  */)
                                              Vlocale_coding_system, 0);
          else
            lisp_errstr = build_string (errstr);
-         report_file_error ("Cannot watch file",
-                            Fcons (lisp_errstr, Fcons (file, Qnil)));
+         report_file_notify_error ("Cannot watch file",
+                                   Fcons (lisp_errstr, Fcons (file, Qnil)));
        }
       else
-       report_file_error ("Cannot watch file", Fcons (file, Qnil));
+       report_file_notify_error ("Cannot watch file", Fcons (file, Qnil));
     }
   /* Store watch object in watch list. */
   watch_descriptor = make_pointer_integer (dirwatch);
@@ -611,8 +611,8 @@ WATCH-DESCRIPTOR should be an object returned by `w32notify-add-watch'.  */)
     }
 
   if (status == -1)
-    report_file_error ("Invalid watch descriptor", Fcons (watch_descriptor,
-                                                         Qnil));
+    report_file_notify_error ("Invalid watch descriptor",
+                             Fcons (watch_descriptor, Qnil));
 
   return Qnil;
 }
@@ -628,6 +628,30 @@ w32_get_watch_object (void *desc)
   return NILP (watch_list) ? Qnil : assoc_no_quit (descriptor, watch_list);
 }
 
+DEFUN ("w32notify-valid-p", Fw32notify_valid_p, Sw32notify_valid_p, 1, 1, 0,
+       doc: /* "Check a watch specified by its WATCH-DESCRIPTOR for validity.
+
+WATCH-DESCRIPTOR should be an object returned by `w32notify-add-watch'.
+
+A watch can become invalid if the directory it watches is deleted, or if
+the watcher thread exits abnormally for any other reason.  Removing the
+watch by calling `w32notify-rm-watch' also makes it invalid.  */)
+     (Lisp_Object watch_descriptor)
+{
+  Lisp_Object watch_object = Fassoc (watch_descriptor, watch_list);
+
+  if (!NILP (watch_object))
+    {
+      struct notification *dirwatch =
+       (struct notification *)XINTPTR (watch_descriptor);
+      if (w32_valid_pointer_p (dirwatch, sizeof(struct notification))
+         && dirwatch->dir != NULL)
+       return Qt;
+    }
+
+  return Qnil;
+}
+
 void
 globals_of_w32notify (void)
 {
@@ -648,6 +672,7 @@ syms_of_w32notify (void)
 
   defsubr (&Sw32notify_add_watch);
   defsubr (&Sw32notify_rm_watch);
+  defsubr (&Sw32notify_valid_p);
 
   staticpro (&watch_list);