+static SCM sys_file_port_name_canonicalization;
+SCM_SYMBOL (sym_relative, "relative");
+SCM_SYMBOL (sym_absolute, "absolute");
+
+static SCM
+fport_canonicalize_filename (SCM filename)
+{
+ SCM mode = scm_fluid_ref (sys_file_port_name_canonicalization);
+
+ if (!scm_is_string (filename))
+ {
+ return filename;
+ }
+ else if (scm_is_eq (mode, sym_relative))
+ {
+ SCM path, rel;
+
+ path = scm_variable_ref (scm_c_module_lookup (scm_the_root_module (),
+ "%load-path"));
+ rel = scm_i_relativize_path (filename, path);
+
+ return scm_is_true (rel) ? rel : filename;
+ }
+ else if (scm_is_eq (mode, sym_absolute))
+ {
+ char *str, *canon;
+
+ str = scm_to_locale_string (filename);
+ canon = canonicalize_file_name (str);
+ free (str);
+
+ return canon ? scm_take_locale_string (canon) : filename;
+ }
+ else
+ {
+ return filename;
+ }
+}
+
+