[seed] fix #650233 Fix importing scripts on *BSD



commit 18861a32f2a251c323c21e172ad39fd91fc80e3f
Author: Jasper Lievisse Adriaanse <jasper humppa nl>
Date:   Mon May 16 17:36:33 2011 +0800

    fix #650233 Fix importing scripts on *BSD

 libseed/seed-importer.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/libseed/seed-importer.c b/libseed/seed-importer.c
index 1d34ef3..b6c012d 100644
--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -19,6 +19,8 @@
 
 #include <gio/gio.h>
 #include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include "seed-private.h"
 
@@ -656,8 +658,9 @@ seed_importer_handle_file (JSContextRef ctx,
   JSValueRef js_file_dirname;
   JSObjectRef global, c_global;
   JSStringRef file_contents, file_name;
-  gchar *contents, *walk, *file_path, *canonical, *absolute_path;
+  gchar *contents, *walk, *file_path, *canonical, *absolute_path, *normalp;
   gchar *normalized_path;
+  gsize path_max;
 
   file_path = g_build_filename (dir, file, NULL);
   canonical = seed_importer_canonicalize_path (file_path);
@@ -711,15 +714,24 @@ seed_importer_handle_file (JSContextRef ctx,
 					g_path_get_dirname (file_path), NULL);
     }
 
-  normalized_path = realpath (absolute_path, NULL);
+#ifdef PATH_MAX
+  path_max = PATH_MAX;
+#else
+  path_max = pathconf (absolute_path, _PC_PATH_MAX);
+  if (path_max <= 0)
+    path_max = 4096;
+#endif
+  normalized_path = (gchar *) g_malloc (path_max);
+  normalp = realpath (absolute_path, normalized_path);
 
-  js_file_dirname = seed_value_from_string (ctx, normalized_path, NULL);
+  js_file_dirname = seed_value_from_string (ctx, normalp, NULL);
 
   seed_object_set_property (nctx, global, "__script_path__", js_file_dirname);
 
   g_hash_table_insert (file_imports, canonical, global);
   g_free (file_path);
   g_free (absolute_path);
+  g_free (normalized_path);
 
   JSEvaluateScript (nctx, file_contents, NULL, file_name, 0, exception);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]