2004-05-09 Gonzalo Paniagua Javier <gonzalo@ximian.com>
authorGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 9 May 2004 03:47:59 +0000 (03:47 -0000)
committerGonzalo Paniagua Javier <gonzalo.mono@gmail.com>
Sun, 9 May 2004 03:47:59 +0000 (03:47 -0000)
* io.c: translate from GFileError to errno codes and don't free
variables right after calling mono_io_scandir, as we may overwrite
errno value.

svn path=/trunk/mono/; revision=26979

mono/io-layer/ChangeLog
mono/io-layer/io.c

index 2988c786789828c796ae2c5418791f9aab530995..100f96b370e048850bc95da563c7ae81a74f943c 100644 (file)
@@ -1,3 +1,9 @@
+2004-05-09  Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+       * io.c: translate from GFileError to errno codes and don't free
+       variables right after calling mono_io_scandir, as we may overwrite
+       errno value.
+
 2004-05-08  Gonzalo Paniagua Javier <gonzalo@ximian.com>
 
        * io.c: g_dir_open return ENOENT for directories on which we don't have
index a23d497956270a6e7cbe2cd81c8204884d611999..21f1b95397dc9658a6a0508cab3f6dc5182736ba 100644 (file)
@@ -2364,6 +2364,123 @@ file_compare (gconstpointer a, gconstpointer b)
        return strcmp (astr, bstr);
 }
 
+static gint
+get_errno_from_g_file_error (gint error)
+{
+       switch (error) {
+#ifdef EACCESS
+       case G_FILE_ERROR_ACCES:
+               error = EACCES;
+               break;
+#endif
+#ifdef ENAMETOOLONG
+       case G_FILE_ERROR_NAMETOOLONG:
+               error = ENAMETOOLONG;
+               break;
+#endif
+#ifdef ENOENT
+       case G_FILE_ERROR_NOENT:
+               error = ENOENT;
+               break;
+#endif
+#ifdef ENOTDIR
+       case G_FILE_ERROR_NOTDIR:
+               error = ENOTDIR;
+               break;
+#endif
+#ifdef ENXIO
+       case G_FILE_ERROR_NXIO:
+               error = ENXIO;
+               break;
+#endif
+#ifdef ENODEV
+       case G_FILE_ERROR_NODEV:
+               error = ENODEV;
+               break;
+#endif
+#ifdef EROFS
+       case G_FILE_ERROR_ROFS:
+               error = EROFS;
+               break;
+#endif
+#ifdef ETXTBSY
+       case G_FILE_ERROR_TXTBSY:
+               error = ETXTBSY;
+               break;
+#endif
+#ifdef EFAULT
+       case G_FILE_ERROR_FAULT:
+               error = EFAULT;
+               break;
+#endif
+#ifdef ELOOP
+       case G_FILE_ERROR_LOOP:
+               error = ELOOP;
+               break;
+#endif
+#ifdef ENOSPC
+       case G_FILE_ERROR_NOSPC:
+               error = ENOSPC;
+               break;
+#endif
+#ifdef ENOMEM
+       case G_FILE_ERROR_NOMEM:
+               error = ENOMEM;
+               break;
+#endif
+#ifdef EMFILE
+       case G_FILE_ERROR_MFILE:
+               error = EMFILE;
+               break;
+#endif
+#ifdef ENFILE
+       case G_FILE_ERROR_NFILE:
+               error = ENFILE;
+               break;
+#endif
+#ifdef EBADF
+       case G_FILE_ERROR_BADF:
+               error = EBADF;
+               break;
+#endif
+#ifdef EINVAL
+       case G_FILE_ERROR_INVAL:
+               error = EINVAL;
+               break;
+#endif
+#ifdef EPIPE
+       case G_FILE_ERROR_PIPE:
+               error = EPIPE;
+               break;
+#endif
+#ifdef EAGAIN
+       case G_FILE_ERROR_AGAIN:
+               error = EAGAIN;
+               break;
+#endif
+#ifdef EINTR
+       case G_FILE_ERROR_INTR:
+               error = EINTR;
+               break;
+#endif
+#ifdef EWIO
+       case G_FILE_ERROR_IO:
+               error = EIO;
+               break;
+#endif
+#ifdef EPERM
+       case G_FILE_ERROR_PERM:
+               error = EPERM;
+               break;
+#endif
+       case G_FILE_ERROR_FAILED:
+               error = ERROR_INVALID_PARAMETER;
+               break;
+       }
+
+       return error;
+}
+
 /* scandir using glib */
 static gint
 mono_io_scandir (const gchar *dirname, const gchar *pattern, gchar ***namelist)
@@ -2379,10 +2496,12 @@ mono_io_scandir (const gchar *dirname, const gchar *pattern, gchar ***namelist)
        if (dir == NULL) {
                /* g_dir_open returns ENOENT on directories on which we don't
                 * have read/x permission */
-               if (error->code == ENOENT && g_file_test (dirname, G_FILE_TEST_IS_DIR))
-                       error->code = EPERM;
-               errno = error->code;
+               gint errnum = get_errno_from_g_file_error (error->code);
                g_error_free (error);
+               if (errnum == ENOENT && g_file_test (dirname, G_FILE_TEST_IS_DIR))
+                       errnum = EACCES;
+
+               errno = errnum;
                return -1;
        }
 
@@ -2510,8 +2629,6 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data)
         */
 
        result = mono_io_scandir (dir_part, entry_part, &find_handle->namelist);
-       g_free (utf8_pattern);
-       g_free (entry_part);
        
        if (result < 0) {
 #ifdef DEBUG
@@ -2521,10 +2638,15 @@ gpointer FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data)
 #ifdef DEBUG
                g_message (G_GNUC_PRETTY_FUNCTION ": scandir error: %s", g_strerror (errnum));
 #endif
+               g_free (utf8_pattern);
+               g_free (entry_part);
                g_free (dir_part);
                unref = TRUE;
                goto cleanup;
        }
+
+       g_free (utf8_pattern);
+       g_free (entry_part);
        
 #ifdef DEBUG
        g_message (G_GNUC_PRETTY_FUNCTION ": Got %d matches", result);