changeset 6598:ce819776ee76

[project @ 2007-04-27 17:34:27 by jwe]
author jwe
date Fri, 27 Apr 2007 17:34:28 +0000
parents 65919b012b35
children 08ca72d6ffc9
files src/ChangeLog src/octave.cc src/sysdep.cc src/sysdep.h src/utils.cc
diffstat 5 files changed, 83 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Apr 27 16:58:25 2007 +0000
+++ b/src/ChangeLog	Fri Apr 27 17:34:28 2007 +0000
@@ -1,3 +1,18 @@
+2007-04-27  Benjamin Lindner  <lindnerb@users.sourceforge.net>.
+
+	* octave.cc (execute_startup_files): Call same_file to check for
+	already executed init files.
+
+2007-04-27  John W. Eaton  <jwe@octave.org>
+
+	* sysdep.cc (same_file_internal): New function.  POSIX code
+	from same_file in utils.cc.  Windows code from
+	Benjamin Lindner  <lindnerb@users.sourceforge.net>.
+	Don't canonicalize file names.
+	Also return false if stat calls fail.
+	* sysdep.h: Provide decl.
+	* utils.cc (same_file): Use same_file_internal.
+
 2007-04-27  David Bateman  <dbateman@free.fr>
 
 	* graphic.cc (get_property_form_handle, set_property_in_handle):
--- a/src/octave.cc	Fri Apr 27 16:58:25 2007 +0000
+++ b/src/octave.cc	Fri Apr 27 17:34:28 2007 +0000
@@ -338,10 +338,7 @@
 
 	      local_rc = octave_env::make_absolute (initfile, curr_dir);
 
-	      file_stat fs_dot_rc (local_rc);
-
-	      if (fs_dot_rc && fs_home_rc.ino () == fs_dot_rc.ino ())
-		home_rc_already_executed = true;
+	      home_rc_already_executed = same_file (home_rc, local_rc);
 	    }
 	}
 
--- a/src/sysdep.cc	Fri Apr 27 16:58:25 2007 +0000
+++ b/src/sysdep.cc	Fri Apr 27 17:34:28 2007 +0000
@@ -89,6 +89,7 @@
 #include "sysdep.h"
 #include "toplev.h"
 #include "utils.h"
+#include "file-stat.h"
 
 #ifndef STDIN_FILENO
 #define STDIN_FILENO 1
@@ -224,6 +225,69 @@
 }
 #endif
 
+// Return TRUE if FILE1 and FILE2 refer to the same (physical) file.
+
+bool
+same_file_internal (const std::string& file1, const std::string& file2)
+{
+#ifdef OCTAVE_USE_WINDOWS_API
+
+  // Windows native code 
+  // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx
+
+  HANDLE hfile1;
+  HANDLE hfile2;
+  
+  BY_HANDLE_FILE_INFORMATION hfi1;
+  BY_HANDLE_FILE_INFORMATION hfi2;
+  
+  hfile1 = CreateFile (file1.c_str (), 0, FILE_SHARE_READ, 0,
+		       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); 
+
+  if (hfile1 == INVALID_FILE_HANDLE)
+    return false;
+  
+  hfile2 = CreateFile (file2.c_str (), 0, FILE_SHARE_READ, 0,
+		       OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
+
+  if (hfile2 == INVALID_FILE_HANDLE)
+    {
+      CloseHandle (hfile1);
+      return false;
+    }
+  
+  if (! GetFileInformationByHandle (hfile1, &hfi1))
+    {
+      CloseHandle (hfile1);
+      CloseHandle (hfile2);
+      return false;
+    }
+   
+  if (! GetFileInformationByHandle (hfile2, &hfi2))
+    {
+      CloseHandle (hfile1);
+      CloseHandle (hfile2);
+      return false;
+    }
+  
+  return (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
+	  && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
+	  && hfi1.nFileIndexLow == hfi2.nFileIndexLow);
+
+#else
+
+  // POSIX Code
+
+  file_stat fs_file1 (file1);
+  file_stat fs_file2 (file2);
+
+  return (fs_file1 && fs_file2
+	  && fs_file1.ino () == fs_file2.ino ()
+	  && fs_file1.dev () == fs_file2.dev ());
+
+#endif
+}
+
 #if defined (__DECCXX)
 
 // These don't seem to be instantiated automatically...
--- a/src/sysdep.h	Fri Apr 27 16:58:25 2007 +0000
+++ b/src/sysdep.h	Fri Apr 27 17:34:28 2007 +0000
@@ -47,6 +47,8 @@
 #define MINGW_SIGNAL_CLEANUP() do { } while (0)
 #endif
 
+extern bool same_file_internal (const std::string&, const std::string&);
+
 #endif
 
 /*
--- a/src/utils.cc	Fri Apr 27 16:58:25 2007 +0000
+++ b/src/utils.cc	Fri Apr 27 17:34:28 2007 +0000
@@ -118,13 +118,7 @@
 bool
 same_file (const std::string& f, const std::string& g)
 {
-  std::string c_f = file_ops::canonicalize_file_name (f);
-  std::string c_g = file_ops::canonicalize_file_name (g);
-
-  file_stat f_fs (c_f);
-  file_stat g_fs (c_g);
-
-  return (f_fs.ino () == g_fs.ino () && f_fs.dev () == g_fs.dev ());
+  return same_file_internal (f, g);
 }
 
 int