[sgen] Separate concurrent M&S object operations into start, concurrent, finish.
[mono.git] / mono / metadata / filewatcher.c
index 68251af45c07dcfdef989e162b541ffe3ee236fe..108540654798a3e2051a3200840ab07264ab8ee5 100644 (file)
@@ -16,7 +16,8 @@
 #include <mono/metadata/filewatcher.h>
 #include <mono/metadata/marshal.h>
 #include <mono/utils/mono-dl.h>
-#ifdef PLATFORM_WIN32
+#include <mono/utils/mono-io-portability.h>
+#ifdef HOST_WIN32
 
 /*
  * TODO:
@@ -50,22 +51,17 @@ ves_icall_System_IO_FSW_SupportsFSW (void)
        MonoDl *fam_module;
        int lib_used = 4; /* gamin */
        int inotify_instance;
-       void *iter;
        char *err;
 
-       MONO_ARCH_SAVE_REGS;
-
        inotify_instance = ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ();
        if (inotify_instance != -1) {
                close (inotify_instance);
                return 5; /* inotify */
        }
 
-       iter = NULL;
        fam_module = mono_dl_open ("libgamin-1.so", MONO_DL_LAZY, NULL);
        if (fam_module == NULL) {
                lib_used = 2; /* FAM */
-               iter = NULL;
                fam_module = mono_dl_open ("libfam.so", MONO_DL_LAZY, NULL);
        }
 
@@ -103,8 +99,6 @@ ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn,
 {
        FAMEvent ev;
 
-       MONO_ARCH_SAVE_REGS;
-
        if (FAMNextEvent (conn, &ev) == 1) {
                *filename = mono_string_new (mono_domain_get (), ev.filename);
                *code = ev.code;
@@ -116,35 +110,7 @@ ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn,
 }
 #endif
 
-#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H) && !defined(__NR_inotify_init)
-#  if defined(__i386__)
-#     define __NR_inotify_init         291
-#  elif defined(__x86_64__)
-#     define __NR_inotify_init         253
-#  elif defined(__ppc__) || defined(__powerpc__) || defined(__powerpc64__)
-#     define __NR_inotify_init         275
-#  elif defined (__s390__) || defined (__s390x__)
-#     define __NR_inotify_init         284
-#  elif defined(__sparc__) || defined (__sparc64__)
-#     define __NR_inotify_init         151
-#  elif defined (__ia64__)
-#     define __NR_inotify_init         1277
-#  elif defined (__arm__)
-#     define __NR_inotify_init         316
-#  elif defined(__alpha__)
-#     define __NR_inotify_init         444
-#  endif
-#ifdef __NR_inotify_init
-#  ifndef __NR_inotify_add_watch
-#    define __NR_inotify_add_watch (__NR_inotify_init + 1)
-#  endif
-#  ifndef __NR_inotify_rm_watch
-#    define __NR_inotify_rm_watch (__NR_inotify_init + 2)
-#  endif
-#endif
-#endif
-
-#if !defined(__linux__) || !defined(__NR_inotify_init)
+#ifndef HAVE_SYS_INOTIFY_H
 int ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ()
 {
        return -1;
@@ -155,32 +121,35 @@ int ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *directory,
        return -1;
 }
 
-int ves_icall_System_IO_InotifyWatcher_RemoveWatch (int fd, int watch_descriptor)
+int ves_icall_System_IO_InotifyWatcher_RemoveWatch (int fd, gint32 watch_descriptor)
 {
        return -1;
 }
 #else
+#include <sys/inotify.h>
 #include <errno.h>
 
 int
 ves_icall_System_IO_InotifyWatcher_GetInotifyInstance ()
 {
-       return syscall (__NR_inotify_init);
+       return inotify_init ();
 }
 
 int
 ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 mask)
 {
-       char *str;
+       char *str, *path;
        int retval;
 
-       MONO_ARCH_SAVE_REGS;
-
        if (name == NULL)
                return -1;
 
        str = mono_string_to_utf8 (name);
-       retval = syscall (__NR_inotify_add_watch, fd, str, mask);
+       path = mono_portability_find_file (str, TRUE);
+       if (!path)
+               path = str;
+
+       retval = inotify_add_watch (fd, path, mask);
        if (retval < 0) {
                switch (errno) {
                case EACCES:
@@ -207,6 +176,8 @@ ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 ma
                }
                mono_marshal_set_last_error ();
        }
+       if (path != str)
+               g_free (path);
        g_free (str);
        return retval;
 }
@@ -214,7 +185,7 @@ ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 ma
 int
 ves_icall_System_IO_InotifyWatcher_RemoveWatch (int fd, gint32 watch_descriptor)
 {
-       return syscall (__NR_inotify_rm_watch, fd, watch_descriptor);
+       return inotify_rm_watch (fd, watch_descriptor);
 }
 #endif