Author: gonzalo
Date: 2006-08-26 19:32:25 -0400 (Sat, 26 Aug 2006)
New Revision: 64419
Modified:
trunk/mono/eglib/ChangeLog
trunk/mono/eglib/src/
trunk/mono/eglib/src/gfile.c
trunk/mono/eglib/src/glib.h
trunk/mono/eglib/test/
trunk/mono/eglib/test/file.c
Log:
2006-08-26 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
* test/file.c:
* src/glib.h:
* src/gfile.c: implemented g_file_test. Changed the default mask to
.XXXXXX. Add tests.
Modified: trunk/mono/eglib/ChangeLog
===================================================================
--- trunk/mono/eglib/ChangeLog 2006-08-26 22:42:37 UTC (rev 64418)
+++ trunk/mono/eglib/ChangeLog 2006-08-26 23:32:25 UTC (rev 64419)
@@ -1,3 +1,10 @@
+2006-08-26 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
+
+ * test/file.c:
+ * src/glib.h:
+ * src/gfile.c: implemented g_file_test. Changed the default mask to
+ .XXXXXX. Add tests.
+
2006-08-26 Raja R Harinath <[EMAIL PROTECTED]>
* src/sort.frag.h (digit): Declare here based on externally
Property changes on: trunk/mono/eglib/src
___________________________________________________________________
Name: svn:ignore
-
Makefile
Makefile.in
.libs
.deps
+
Makefile
Makefile.in
.libs
.deps
eglib-config.h
Modified: trunk/mono/eglib/src/gfile.c
===================================================================
--- trunk/mono/eglib/src/gfile.c 2006-08-26 22:42:37 UTC (rev 64418)
+++ trunk/mono/eglib/src/gfile.c 2006-08-26 23:32:25 UTC (rev 64419)
@@ -156,7 +156,7 @@
gint
g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError **error)
{
- const static gchar *default_tmpl = "file-g-XXXXXX";
+ const static gchar *default_tmpl = ".XXXXXX";
gchar *t;
gint fd;
gint len;
@@ -200,3 +200,44 @@
return fd;
}
+gboolean
+g_file_test (const gchar *filename, GFileTest test)
+{
+ struct stat st;
+ gboolean have_stat;
+
+ if (filename == NULL || test == 0)
+ return FALSE;
+
+ have_stat = FALSE;
+ if ((test & G_FILE_TEST_EXISTS) != 0) {
+ if (access (filename, F_OK) == 0)
+ return TRUE;
+ }
+
+ if ((test & G_FILE_TEST_IS_EXECUTABLE) != 0) {
+ 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;
+ }
+
+ if ((test & G_FILE_TEST_IS_REGULAR) != 0) {
+ if (!have_stat)
+ have_stat = (stat (filename, &st) == 0);
+ if (have_stat && S_ISREG (st.st_mode))
+ return TRUE;
+ }
+ if ((test & G_FILE_TEST_IS_DIR) != 0) {
+ if (!have_stat)
+ have_stat = (stat (filename, &st) == 0);
+ if (have_stat && S_ISDIR (st.st_mode))
+ return TRUE;
+ }
+ return FALSE;
+}
+
Modified: trunk/mono/eglib/src/glib.h
===================================================================
--- trunk/mono/eglib/src/glib.h 2006-08-26 22:42:37 UTC (rev 64418)
+++ trunk/mono/eglib/src/glib.h 2006-08-26 23:32:25 UTC (rev 64419)
@@ -513,8 +513,20 @@
G_FILE_ERROR_FAILED
} GFileError;
+typedef enum {
+ G_FILE_TEST_IS_REGULAR = 1 << 0,
+ G_FILE_TEST_IS_SYMLINK = 1 << 1,
+ G_FILE_TEST_IS_DIR = 1 << 2,
+ G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
+ G_FILE_TEST_EXISTS = 1 << 4
+} GFileTest;
+
+
gboolean g_file_get_contents (const gchar *filename, gchar **contents, gsize
*length, GError **error);
GFileError g_file_error_from_errno (gint err_no);
gint g_file_open_tmp (const gchar *tmpl, gchar **name_used, GError
**error);
+gboolean g_file_test (const gchar *filename, GFileTest test);
+
+
#endif
Property changes on: trunk/mono/eglib/test
___________________________________________________________________
Name: svn:ignore
-
Makefile.in
configure
libtool
aclocal.m4
Makefile
config.h
config.h.in
config.status
stamp-h1
autom4te.cache
.libs
.deps
test
+
Makefile.in
configure
libtool
aclocal.m4
Makefile
config.h
config.h.in
config.status
stamp-h1
autom4te.cache
.libs
.deps
test-glib
test-eglib
Modified: trunk/mono/eglib/test/file.c
===================================================================
--- trunk/mono/eglib/test/file.c 2006-08-26 22:42:37 UTC (rev 64418)
+++ trunk/mono/eglib/test/file.c 2006-08-26 23:32:25 UTC (rev 64419)
@@ -89,9 +89,113 @@
return OK;
}
+RESULT
+test_file ()
+{
+ gboolean res;
+ const gchar *tmp;
+ gchar *path, *sympath;
+
+ res = g_file_test (NULL, 0);
+ if (res)
+ return FAILED ("Should return FALSE HERE");
+
+ res = g_file_test ("file.c", 0);
+ if (res)
+ return FAILED ("Should return FALSE HERE");
+
+ tmp = g_get_tmp_dir ();
+ res = g_file_test (tmp, G_FILE_TEST_EXISTS);
+ if (!res)
+ return FAILED ("tmp does not exist.");
+ res = g_file_test (tmp, G_FILE_TEST_IS_REGULAR);
+ if (res)
+ return FAILED ("tmp is regular");
+
+ res = g_file_test (tmp, G_FILE_TEST_IS_DIR);
+ if (!res)
+ return FAILED ("tmp is not a directory");
+ res = g_file_test (tmp, G_FILE_TEST_IS_EXECUTABLE);
+ if (!res)
+ return FAILED ("tmp is not a executable");
+
+ res = g_file_test (tmp, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_SYMLINK);
+ if (!res)
+ return FAILED ("2 tmp does not exist.");
+ res = g_file_test (tmp, G_FILE_TEST_IS_REGULAR |
G_FILE_TEST_IS_SYMLINK);
+ if (res)
+ return FAILED ("2 tmp is regular");
+
+ res = g_file_test (tmp, G_FILE_TEST_IS_DIR | G_FILE_TEST_IS_SYMLINK);
+ if (!res)
+ return FAILED ("2 tmp is not a directory");
+ res = g_file_test (tmp, G_FILE_TEST_IS_EXECUTABLE |
G_FILE_TEST_IS_SYMLINK);
+ if (!res)
+ return FAILED ("2 tmp is not a executable");
+
+ close (g_file_open_tmp (NULL, &path, NULL)); /* create an empty file */
+ res = g_file_test (path, G_FILE_TEST_EXISTS);
+ if (!res)
+ return FAILED ("3 %s should exist", path);
+ res = g_file_test (path, G_FILE_TEST_IS_REGULAR);
+ /* This is strange. Empty file is reported as not existing! */
+ if (!res)
+ return FAILED ("3 %s IS_REGULAR", path);
+ res = g_file_test (path, G_FILE_TEST_IS_DIR);
+ if (res)
+ return FAILED ("3 %s should not be a directory", path);
+ res = g_file_test (path, G_FILE_TEST_IS_EXECUTABLE);
+ if (res)
+ return FAILED ("3 %s should not be executable", path);
+ res = g_file_test (path, G_FILE_TEST_IS_SYMLINK);
+ if (res)
+ return FAILED ("3 %s should not be a symlink", path);
+
+ sympath = g_strconcat (path, "-link", NULL);
+ symlink (path, sympath);
+ res = g_file_test (sympath, G_FILE_TEST_EXISTS);
+ if (!res)
+ return FAILED ("4 %s should not exist", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_REGULAR);
+ if (!res)
+ return FAILED ("4 %s should not be a regular file", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_DIR);
+ if (res)
+ return FAILED ("4 %s should not be a directory", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_EXECUTABLE);
+ if (res)
+ return FAILED ("4 %s should not be executable", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_SYMLINK);
+ if (!res)
+ return FAILED ("4 %s should be a symlink", sympath);
+
+ unlink (path);
+
+ res = g_file_test (sympath, G_FILE_TEST_EXISTS);
+ if (res)
+ return FAILED ("5 %s should exist", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_REGULAR);
+ if (res)
+ return FAILED ("5 %s should be a regular file", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_DIR);
+ if (res)
+ return FAILED ("5 %s should not be a directory", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_EXECUTABLE);
+ if (res)
+ return FAILED ("5 %s should not be executable", sympath);
+ res = g_file_test (sympath, G_FILE_TEST_IS_SYMLINK);
+ if (!res)
+ return FAILED ("5 %s should be a symlink", sympath);
+ unlink (sympath);
+ g_free (path);
+ g_free (sympath);
+ return OK;
+}
+
static Test file_tests [] = {
- {"g_file_test_contents", test_file_get_contents},
+ {"g_file_get_contents", test_file_get_contents},
{"g_file_open_tmp", test_open_tmp},
+ {"g_file_test", test_file},
{NULL, NULL}
};
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches