Typo
[mono.git] / mono / metadata / filewatcher.c
index 9a7ef70cad1ed07ea1b7e38bee106559642d7530..b16ccc8a8ca203725fe25cb891af3f79a6106a2a 100644 (file)
@@ -4,7 +4,7 @@
  * Authors:
  *     Gonzalo Paniagua Javier (gonzalo@ximian.com)
  *
- * (C) 2004,2005,2006 Novell, Inc. (http://www.novell.com)
+ * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
  */
 
 #ifdef HAVE_CONFIG_H
@@ -14,8 +14,9 @@
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/exception.h>
 #include <mono/metadata/filewatcher.h>
-
-#if (defined (PLATFORM_WIN32) && WINVER >= 0x0400)
+#include <mono/metadata/marshal.h>
+#include <mono/utils/mono-dl.h>
+#ifdef HOST_WIN32
 
 /*
  * TODO:
@@ -27,63 +28,6 @@ ves_icall_System_IO_FSW_SupportsFSW (void)
        return 1;
 }
 
-gpointer
-ves_icall_System_IO_FSW_OpenDirectory (MonoString *path, gpointer reserved)
-{
-       return NULL;
-       /*
-       gpointer dir;
-       gchar *utf8path;
-
-       MONO_ARCH_SAVE_REGS;
-
-       dir = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE,
-                         NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
-
-       return dir;
-       */
-}
-
-gboolean
-ves_icall_System_IO_FSW_CloseDirectory (gpointer handle)
-{
-       return FALSE;
-       /*
-       MONO_ARCH_SAVE_REGS;
-
-       return CloseHandle (handle);
-       */
-}
-
-gboolean
-ves_icall_System_IO_FSW_ReadDirectoryChanges (gpointer handle,
-                                             MonoArray *buffer,
-                                             gboolean includeSubdirs,
-                                             gint filters,
-                                             gpointer overlap,
-                                             gpointer callback)
-{
-       return FALSE;
-       /*
-       gpointer dest;
-       gint size;
-       MonoObject *delegate = (MonoObject *) callback;
-       MonoMethod *im;
-       LPOVERLAPPED_COMPLETION_ROUTINE func;
-
-       MONO_ARCH_SAVE_REGS;
-
-       size = mono_array_length (buffer);
-       dest = mono_array_addr_with_size (buffer, 1, 0);
-
-       im = mono_get_delegate_invoke (mono_object_get_class (delegate));
-       func = mono_compile_method (im);
-       return FALSE;
-       * return ReadDirectoryChanges (handle, dest, size, includeSubdirs, filters,
-                                    NULL, (LPOVERLAPPED) overlap,
-                                    func); */
-}
-
 gboolean
 ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn,
                                               MonoString **filename,
@@ -103,10 +47,11 @@ ves_icall_System_IO_FSW_SupportsFSW (void)
 #if HAVE_KQUEUE
        return 3;
 #else
-       GModule *fam_module;
-       gchar *filename;
+       MonoDl *fam_module;
        int lib_used = 4; /* gamin */
        int inotify_instance;
+       void *iter;
+       char *err;
 
        MONO_ARCH_SAVE_REGS;
 
@@ -116,20 +61,19 @@ ves_icall_System_IO_FSW_SupportsFSW (void)
                return 5; /* inotify */
        }
 
-       filename = g_module_build_path (NULL, "libgamin-1.so.0");
-       fam_module = g_module_open (filename, G_MODULE_BIND_LAZY);
-       g_free (filename);
+       iter = NULL;
+       fam_module = mono_dl_open ("libgamin-1.so", MONO_DL_LAZY, NULL);
        if (fam_module == NULL) {
                lib_used = 2; /* FAM */
-               filename = g_module_build_path (NULL, "libfam.so.0");
-               fam_module = g_module_open (filename, G_MODULE_BIND_LAZY);
-               g_free (filename);
+               iter = NULL;
+               fam_module = mono_dl_open ("libfam.so", MONO_DL_LAZY, NULL);
        }
 
        if (fam_module == NULL)
                return 0;
 
-       g_module_symbol (fam_module, "FAMNextEvent", (gpointer *) &FAMNextEvent);
+       err = mono_dl_symbol (fam_module, "FAMNextEvent", (gpointer *) &FAMNextEvent);
+       g_free (err);
        if (FAMNextEvent == NULL)
                return 0;
 
@@ -137,29 +81,6 @@ ves_icall_System_IO_FSW_SupportsFSW (void)
 #endif
 }
 
-gpointer
-ves_icall_System_IO_FSW_OpenDirectory (MonoString *path, gpointer reserved)
-{
-       return NULL;
-}
-
-gboolean
-ves_icall_System_IO_FSW_CloseDirectory (gpointer handle)
-{
-       return FALSE;
-}
-
-gboolean
-ves_icall_System_IO_FSW_ReadDirectoryChanges (gpointer handle,
-                                             MonoArray *buffer,
-                                             gboolean includeSubdirs,
-                                             gint filters,
-                                             gpointer overlap,
-                                             gpointer callback)
-{
-       return FALSE;
-}
-
 /* Almost copied from fam.h. Weird, I know */
 typedef struct {
        gint reqnum;
@@ -195,7 +116,7 @@ ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn,
 }
 #endif
 
-#ifdef __linux__ && defined(HAVE_SYS_SYSCALL_H) && !defined(__NR_inotify_init)
+#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H) && !defined(__NR_inotify_init)
 #  if defined(__i386__)
 #     define __NR_inotify_init         291
 #  elif defined(__x86_64__)
@@ -214,8 +135,12 @@ ves_icall_System_IO_FAMW_InternalFAMNextEvent (gpointer conn,
 #     define __NR_inotify_init         444
 #  endif
 #ifdef __NR_inotify_init
-#  define __NR_inotify_add_watch (__NR_inotify_init + 1)
-#  define __NR_inotify_rm_watch (__NR_inotify_init + 2)
+#  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
 
@@ -230,7 +155,7 @@ 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;
 }
@@ -259,27 +184,28 @@ ves_icall_System_IO_InotifyWatcher_AddWatch (int fd, MonoString *name, gint32 ma
        if (retval < 0) {
                switch (errno) {
                case EACCES:
-                       SetLastError (ERROR_ACCESS_DENIED);
+                       errno = ERROR_ACCESS_DENIED;
                        break;
                case EBADF:
-                       SetLastError (ERROR_INVALID_HANDLE);
+                       errno = ERROR_INVALID_HANDLE;
                        break;
                case EFAULT:
-                       SetLastError (ERROR_INVALID_ACCESS);
+                       errno = ERROR_INVALID_ACCESS;
                        break;
                case EINVAL:
-                       SetLastError (ERROR_INVALID_DATA);
+                       errno = ERROR_INVALID_DATA;
                        break;
                case ENOMEM:
-                       SetLastError (ERROR_NOT_ENOUGH_MEMORY);
+                       errno = ERROR_NOT_ENOUGH_MEMORY;
                        break;
                case ENOSPC:
-                       SetLastError (ERROR_TOO_MANY_OPEN_FILES);
+                       errno = ERROR_TOO_MANY_OPEN_FILES;
                        break;
                default:
-                       SetLastError (ERROR_GEN_FAILURE);
+                       errno = ERROR_GEN_FAILURE;
                        break;
                }
+               mono_marshal_set_last_error ();
        }
        g_free (str);
        return retval;