* if advised of the possibility of such damage.
*/
+#include "config.h"
#include <string.h>
#include <errno.h>
g_free (name);
}
+static void
+test_read_link (void)
+{
+#ifdef HAVE_READLINK
+#ifdef G_OS_UNIX
+ int ret;
+ const gchar *oldpath;
+ const gchar *newpath;
+ const gchar *badpath;
+ gchar *path;
+ GError *error = NULL;
+
+ oldpath = g_test_get_filename (G_TEST_DIST, "4096-random-bytes", NULL);
+ newpath = g_test_get_filename (G_TEST_DIST, "page-of-junk", NULL);
+ badpath = g_test_get_filename (G_TEST_DIST, "4097-random-bytes", NULL);
+ remove (newpath);
+ ret = symlink (oldpath, newpath);
+ g_assert (ret == 0);
+ path = g_file_read_link (newpath, &error);
+ g_assert_no_error (error);
+ g_assert_cmpstr (path, ==, oldpath);
+ g_free (path);
+
+ remove (newpath);
+ ret = symlink (badpath, newpath);
+ g_assert (ret == 0);
+ path = g_file_read_link (newpath, &error);
+ g_assert_no_error (error);
+ g_assert_cmpstr (path, ==, badpath);
+ g_free (path);
+
+ path = g_file_read_link (oldpath, &error);
+ g_assert_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL);
+ g_assert_null (path);
+
+#endif
+#else
+ g_test_skip ("Symbolic links not supported");
+#endif
+}
+
int
main (int argc,
char *argv[])
g_test_add_func ("/fileutils/mkstemp", test_mkstemp);
g_test_add_func ("/fileutils/mkdtemp", test_mkdtemp);
g_test_add_func ("/fileutils/set-contents", test_set_contents);
+ g_test_add_func ("/fileutils/read-link", test_read_link);
return g_test_run ();
}