changeset 27617:12f28f9368ec

* kpse.cc (READABLE): Use wide character file system API on Windows.
author Markus Mützel <markus.muetzel@gmx.de>
date Sat, 02 Nov 2019 18:22:39 +0100
parents 1c13a0f36160
children dd9803e83b9f
files liboctave/util/kpse.cc
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/util/kpse.cc	Sat Nov 02 08:03:40 2019 -0700
+++ b/liboctave/util/kpse.cc	Sat Nov 02 18:22:39 2019 +0100
@@ -52,6 +52,8 @@
 #if defined (OCTAVE_USE_WINDOWS_API)
 #  define WIN32_LEAN_AND_MEAN 1
 #  include <windows.h>
+
+#  include "lo-sysdep.h"
 #endif
 
 // Define the characters which separate components of filenames and
@@ -162,18 +164,19 @@
    regular file, as it is potentially useful to read fifo's or some
    kinds of devices.  */
 
-#if defined (OCTAVE_USE_WINDOWS_API)
 static inline bool
 READABLE (const std::string& fn)
 {
-  const char *t = fn.c_str ();
-  return (GetFileAttributes (t) != 0xFFFFFFFF
-          && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY));
-}
+#if defined (OCTAVE_USE_WINDOWS_API)
+
+  std::wstring w_fn = L"\\\\?\\" + octave::sys::u8_to_wstring (fn);
+
+  DWORD f_attr = GetFileAttributesW (w_fn.c_str ());
+
+  return (f_attr != 0xFFFFFFFF && ! (f_attr & FILE_ATTRIBUTE_DIRECTORY));
+
 #else
-static inline bool
-READABLE (const std::string& fn)
-{
+
   bool retval = false;
 
   const char *t = fn.c_str ();
@@ -186,8 +189,9 @@
     }
 
   return retval;
+
+#endif
 }
-#endif
 
 /* POSIX invented the brain-damage of not necessarily truncating
    filename components; the system's behavior is defined by the value of