--- a/libseed/seed-importer.c
+++ b/libseed/seed-importer.c
@@ -659,9 +659,8 @@
   JSValueRef js_file_dirname;
   JSObjectRef global, c_global;
   JSStringRef file_contents, file_name;
-  gchar *contents, *walk, *file_path, *canonical, *absolute_path, *normalp;
-  gchar *normalized_path;
-  gsize path_max;
+  gchar *contents, *walk, *file_path, *canonical, *absolute_path;
+  char *normalized_path;
 
   file_path = g_build_filename (dir, file, NULL);
   canonical = seed_importer_canonicalize_path (file_path);
@@ -715,17 +714,9 @@
 					g_path_get_dirname (file_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);
+  normalized_path = realpath (absolute_path, NULL);
 
-  js_file_dirname = seed_value_from_string (ctx, normalp, NULL);
+  js_file_dirname = seed_value_from_string (ctx, normalized_path, NULL);
 
   seed_object_set_property (nctx, global, "__script_path__", js_file_dirname);
 
--- a/modules/os/seed-os.c
+++ b/modules/os/seed-os.c
@@ -66,26 +66,16 @@
   SeedValue sv;
   gchar *arg;
   gchar *resolved_path;
-  gchar *ret;
-  gsize path_max;
 
   if (argument_count != 1)
     {
       EXPECTED_EXCEPTION("os.realpath", "1 argument");
     }
   arg = seed_value_to_string (ctx, arguments[0], exception);
-#ifdef PATH_MAX
-  path_max = PATH_MAX;
-#else
-  path_max = pathconf (arg, _PC_PATH_MAX);
-  if (path_max <= 0)
-    path_max = 4096;
-#endif
-  resolved_path = (gchar *) g_malloc (path_max);
-  ret = realpath(arg, resolved_path);
+  resolved_path = realpath (arg, NULL);
   g_free (arg);
 
-  sv = seed_value_from_string (ctx, ret, exception);
+  sv = seed_value_from_string (ctx, resolved_path, exception);
   g_free (resolved_path);
 
   return sv;
