Author: gonzalo
Date: 2006-08-28 02:29:20 -0400 (Mon, 28 Aug 2006)
New Revision: 64459

Added:
   trunk/mono/eglib/src/gdir.c
   trunk/mono/eglib/test/dir.c
Modified:
   trunk/mono/eglib/ChangeLog
   trunk/mono/eglib/TODO
   trunk/mono/eglib/src/Makefile.am
   trunk/mono/eglib/src/gfile.c
   trunk/mono/eglib/src/glib.h
   trunk/mono/eglib/test/Makefile.am
   trunk/mono/eglib/test/pattern.c
   trunk/mono/eglib/test/tests.h
Log:
2006-08-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>

        * TODO: Modified file.
        * test/tests.h:
        * test/pattern.c:
        * test/dir.c:
        * test/Makefile.am:
        * src/Makefile.am:
        * src/glib.h:
        * src/gdir.c:
        * src/gfile.c: implemented g_dir_*, unix version.



Modified: trunk/mono/eglib/ChangeLog
===================================================================
--- trunk/mono/eglib/ChangeLog  2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/ChangeLog  2006-08-28 06:29:20 UTC (rev 64459)
@@ -1,3 +1,15 @@
+2006-08-28 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+       * TODO: Modified file.
+       * test/tests.h:
+       * test/pattern.c:
+       * test/dir.c:
+       * test/Makefile.am:
+       * src/Makefile.am:
+       * src/glib.h:
+       * src/gdir.c:
+       * src/gfile.c: implemented g_dir_*, unix version.
+
 2006-08-27 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
        * src/glib.h:

Modified: trunk/mono/eglib/TODO
===================================================================
--- trunk/mono/eglib/TODO       2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/TODO       2006-08-28 06:29:20 UTC (rev 64459)
@@ -3,14 +3,10 @@
 
   Directory, File manipulation:
 
-       g_dir_open, g_dir_close, g_dir_read_name,
-       G_FILE_ERROR_*
+       g_dir_open, g_dir_close, g_dir_read_name
 
-       These will be replaced in io-layer with direct Unix calls.
+       We're missing a native windows implementation. The unix one is in place.
 
-       These will be replaced in metadata with two code paths, native
-       Unix and native Windows.
-
   Locking:
 
       5 G_LOCK
@@ -69,10 +65,8 @@
              1 g_log_set_handler
 
 Macros:
-      7 G_FILE_TEST_IS_DIR
       6 G_UNLIKELY
       4 G_LIKELY
-      4 G_FILE_TEST_IS_REGULAR
       2 G_USEC_PER_SEC
       2 G_STRLOC
       1 G_SPAWN_SEARCH_PATH

Modified: trunk/mono/eglib/src/Makefile.am
===================================================================
--- trunk/mono/eglib/src/Makefile.am    2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/src/Makefile.am    2006-08-28 06:29:20 UTC (rev 64459)
@@ -23,7 +23,8 @@
        gtimer.c        \
        gdate.c         \
        gfile.c         \
-       gpattern.c
+       gpattern.c      \
+       gdir.c
 
 libeglib_la_CFLAGS = -Wall -Werror -D_FORTIFY_SOURCE=2
 

Added: trunk/mono/eglib/src/gdir.c
===================================================================
--- trunk/mono/eglib/src/gdir.c 2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/src/gdir.c 2006-08-28 06:29:20 UTC (rev 64459)
@@ -0,0 +1,106 @@
+/*
+ * Directory utility functions.
+ *
+ * Author:
+ *   Gonzalo Paniagua Javier ([EMAIL PROTECTED])
+ *
+ * (C) 2006 Novell, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+struct _GDir {
+#ifdef G_OS_WIN32
+#else
+       DIR *dir;
+#endif
+};
+
+GDir *
+g_dir_open (const gchar *path, guint flags, GError **error)
+{
+#ifdef G_OS_WIN32
+       return NULL;
+#else
+       GDir *dir;
+
+       g_return_val_if_fail (path != NULL, NULL);
+       g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+       (void) flags; /* this is not used */
+       dir = g_new (GDir, 1);
+       dir->dir = opendir (path);
+       if (dir->dir == NULL) {
+               if (error) {
+                       gint err = errno;
+                       *error = g_error_new (G_LOG_DOMAIN, 
g_file_error_from_errno (err), strerror (err));
+               }
+               g_free (dir);
+               return NULL;
+       }
+       return dir;
+#endif
+}
+
+const gchar *
+g_dir_read_name (GDir *dir)
+{
+#ifdef G_OS_WIN32
+       return NULL;
+#else
+       struct dirent *entry;
+
+       g_return_val_if_fail (dir != NULL && dir->dir != NULL, NULL);
+       entry = readdir (dir->dir);
+       if (entry == NULL)
+               return NULL;
+
+       return entry->d_name;
+}
+
+void
+g_dir_rewind (GDir *dir)
+{
+#ifdef G_OS_WIN32
+#else
+       g_return_if_fail (dir != NULL && dir->dir != NULL);
+       rewinddir (dir->dir);
+}
+
+void
+g_dir_close (GDir *dir)
+{
+#ifdef G_OS_WIN32
+#else
+       g_return_if_fail (dir != NULL && dir->dir != NULL);
+       closedir (dir->dir);
+       dir->dir = NULL;
+       g_free (dir);
+#endif
+}
+


Property changes on: trunk/mono/eglib/src/gdir.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/mono/eglib/src/gfile.c
===================================================================
--- trunk/mono/eglib/src/gfile.c        2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/src/gfile.c        2006-08-28 06:29:20 UTC (rev 64459)
@@ -2,7 +2,7 @@
  * File utility functions.
  *
  * Author:
- *   Gonzalo Paniagua Javier ([EMAIL PROTECTED]
+ *   Gonzalo Paniagua Javier ([EMAIL PROTECTED])
  *
  * (C) 2006 Novell, Inc.
  *
@@ -210,6 +210,8 @@
                return FALSE;
 
        have_stat = FALSE;
+#ifdef G_OS_WIN32
+#else
        if ((test & G_FILE_TEST_EXISTS) != 0) {
                if (access (filename, F_OK) == 0)
                        return TRUE;
@@ -219,12 +221,12 @@
                if (access (filename, X_OK) == 0)
                        return TRUE;
        }
-
        if ((test & G_FILE_TEST_IS_SYMLINK) != 0) {
                have_stat = (lstat (filename, &st) == 0);
                if (have_stat && S_ISLNK (st.st_mode))
                        return TRUE;
        }
+#endif
 
        if ((test & G_FILE_TEST_IS_REGULAR) != 0) {
                if (!have_stat)

Modified: trunk/mono/eglib/src/glib.h
===================================================================
--- trunk/mono/eglib/src/glib.h 2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/src/glib.h 2006-08-28 06:29:20 UTC (rev 64459)
@@ -535,5 +535,13 @@
 void           g_pattern_spec_free (GPatternSpec *pspec);
 gboolean       g_pattern_match_string (GPatternSpec *pspec, const gchar 
*string);
 
+/*
+ * Directory
+ */
+typedef struct _GDir GDir;
+GDir        *g_dir_open (const gchar *path, guint flags, GError **error);
+const gchar *g_dir_read_name (GDir *dir);
+void         g_dir_rewind (GDir *dir);
+void         g_dir_close (GDir *dir);
 #endif
 

Modified: trunk/mono/eglib/test/Makefile.am
===================================================================
--- trunk/mono/eglib/test/Makefile.am   2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/test/Makefile.am   2006-08-28 06:29:20 UTC (rev 64459)
@@ -20,7 +20,8 @@
        spawn.c         \
        timer.c         \
        file.c          \
-       pattern.c
+       pattern.c       \
+       dir.c
 
 test_eglib_SOURCES = $(SOURCES)
 test_glib_SOURCES = $(SOURCES)

Added: trunk/mono/eglib/test/dir.c
===================================================================
--- trunk/mono/eglib/test/dir.c 2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/test/dir.c 2006-08-28 06:29:20 UTC (rev 64459)
@@ -0,0 +1,55 @@
+#include <glib.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
+#include "test.h"
+
+/* This test is just to be used with valgrind */
+RESULT
+test_dir ()
+{
+       GDir *dir;
+       GError *error;
+       const gchar *name;
+
+       /*
+       dir = g_dir_open (NULL, 0, NULL);
+       */
+       dir = g_dir_open ("", 0, NULL);
+       if (dir != NULL)
+               return FAILED ("1 Should be an error");
+
+       dir = g_dir_open ("", 9, NULL);
+       if (dir != NULL)
+               return FAILED ("2 Should be an error");
+
+       error = NULL;
+       dir = g_dir_open (".ljasdslakjd", 9, &error);
+       if (dir != NULL)
+               return FAILED ("3 opendir should fail");
+       if (error == NULL)
+               return FAILED ("4 got no error");
+       g_error_free (error);
+       error = NULL;
+       dir = g_dir_open (g_get_tmp_dir (), 9, &error);
+       if (dir == NULL)
+               return FAILED ("5 opendir should succeed");
+       if (error != NULL)
+               return FAILED ("6 got an error");
+
+       name = NULL;
+       name = g_dir_read_name (dir);
+       if (name == NULL)
+               return FAILED ("7 didn't read a file name");
+       g_dir_close (dir);
+       return OK;
+}
+
+static Test dir_tests [] = {
+       {"g_dir_*", test_dir},
+       {NULL, NULL}
+};
+
+DEFINE_TEST_GROUP_INIT(dir_tests_init, dir_tests)
+


Property changes on: trunk/mono/eglib/test/dir.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: trunk/mono/eglib/test/pattern.c
===================================================================
--- trunk/mono/eglib/test/pattern.c     2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/test/pattern.c     2006-08-28 06:29:20 UTC (rev 64459)
@@ -22,7 +22,6 @@
        gboolean res;
 
        /* spec = g_pattern_spec_new (NULL); */
-       printf ("%s\n", g_get_home_dir ());
        TEST_MATCH ("*", "hola", 1);
        TEST_MATCH ("hola", "hola", 2);
        TEST_MATCH ("????", "hola", 3);

Modified: trunk/mono/eglib/test/tests.h
===================================================================
--- trunk/mono/eglib/test/tests.h       2006-08-28 02:26:39 UTC (rev 64458)
+++ trunk/mono/eglib/test/tests.h       2006-08-28 06:29:20 UTC (rev 64459)
@@ -16,6 +16,7 @@
 DEFINE_TEST_GROUP_INIT_H(timer_tests_init);
 DEFINE_TEST_GROUP_INIT_H(file_tests_init);
 DEFINE_TEST_GROUP_INIT_H(pattern_tests_init);
+DEFINE_TEST_GROUP_INIT_H(dir_tests_init);
 
 static Group test_groups [] = {        
        {"string",    string_tests_init}, 
@@ -34,6 +35,7 @@
        {"timer",     timer_tests_init},
        {"file",      file_tests_init},
        {"pattern",   pattern_tests_init},
+       {"dir",       dir_tests_init},
        {NULL, NULL}
 };
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to