changeset 25513:7fb40efda31f

Use wide character Windows API for operations on folders (bug #49118). * stat-wrappers.c: Use wide character API for mkdir and stat. * unistd-wrappers.c: Use wide character API for chdir, getcwd, and rmdir.
author Markus Mützel <markus.muetzel@gmx.de>
date Wed, 27 Jun 2018 21:01:58 +0200
parents 7335d44f34b4
children c63f67d87b4a
files liboctave/wrappers/stat-wrappers.c liboctave/wrappers/unistd-wrappers.c
diffstat 2 files changed, 68 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/wrappers/stat-wrappers.c	Wed Jun 27 20:56:37 2018 +0200
+++ b/liboctave/wrappers/stat-wrappers.c	Wed Jun 27 21:01:58 2018 +0200
@@ -35,11 +35,25 @@
 #include <sys/stat.h>
 
 #include "stat-wrappers.h"
+#include "uniconv-wrappers.h"
+
+#if defined (OCTAVE_USE_WINDOWS_API)
+#  include <windows.h>
+#  include <wchar.h>
+#endif
 
 int
 octave_mkdir_wrapper (const char *name, mode_t mode)
 {
+#if defined (OCTAVE_USE_WINDOWS_API)
+  wchar_t *wname = u8_to_wchar (name);
+  int status = _wmkdir (wname);
+  free ((void *) wname);
+  octave_unused_parameter (mode);
+  return status;
+#else
   return mkdir (name, mode);
+#endif
 }
 
 int
@@ -100,7 +114,13 @@
 {
   struct stat buf;
 
+#if defined (OCTAVE_USE_WINDOWS_API)
+  wchar_t *wfname = u8_to_wchar (fname);
+  int status = _wstati64 (wfname, &buf);
+  free ((void *) wfname);
+#else
   int status = stat (fname, &buf);
+#endif
 
   assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
                       atime, mtime, ctime, rdev, blksize, blocks);
@@ -117,7 +137,14 @@
 {
   struct stat buf;
 
+#if defined (OCTAVE_USE_WINDOWS_API)
+  // Windows doesn't have an lstat. Use stat instead
+  wchar_t *wlname = u8_to_wchar (lname);
+  int status = _wstati64 (wlname, &buf);
+  free ((void *) wlname);
+#else
   int status = lstat (lname, &buf);
+#endif
 
   assign_stat_fields (&buf, mode, ino, dev, nlink, uid, gid, size,
                       atime, mtime, ctime, rdev, blksize, blocks);
--- a/liboctave/wrappers/unistd-wrappers.c	Wed Jun 27 20:56:37 2018 +0200
+++ b/liboctave/wrappers/unistd-wrappers.c	Wed Jun 27 21:01:58 2018 +0200
@@ -31,8 +31,6 @@
 
 #include <stdio.h>
 
-#include <stdio.h>
-
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -40,6 +38,12 @@
 #  include <process.h>
 #endif
 
+#if defined (OCTAVE_USE_WINDOWS_API)
+#  include <windows.h>
+#  include <wchar.h>
+#endif
+
+#include "uniconv-wrappers.h"
 #include "unistd-wrappers.h"
 
 int
@@ -75,7 +79,14 @@
 int
 octave_chdir_wrapper (const char *nm)
 {
+#if defined (OCTAVE_USE_WINDOWS_API)
+  wchar_t *wnm = u8_to_wchar (nm);
+  int status = _wchdir (wnm);
+  free ((void *) wnm);
+  return status;
+#else
   return chdir (nm);
+#endif
 }
 
 int
@@ -281,7 +292,28 @@
 char *
 octave_getcwd_wrapper (char *nm, size_t len)
 {
+#if defined (OCTAVE_USE_WINDOWS_API)
+  wchar_t *tmp = _wgetcwd (NULL, 0);
+  char *retval = NULL;
+
+  if (! tmp)
+    return retval;
+
+  retval = u8_from_wchar (tmp);
+  if (! nm)
+    return retval;
+  else
+    {
+      if (strlen (retval) > len)
+        return NULL;
+      
+      memcpy (nm, retval, len);
+      free (retval);
+      return nm;
+    }
+#else
   return getcwd (nm, len);
+#endif
 }
 
 gid_t
@@ -381,7 +413,14 @@
 int
 octave_rmdir_wrapper (const char *nm)
 {
+#if defined (OCTAVE_USE_WINDOWS_API)
+  wchar_t *wnm = u8_to_wchar (nm);
+  int status = _wrmdir (wnm);
+  free ((void *) wnm);
+  return status;
+#else
   return rmdir (nm);
+#endif
 }
 
 pid_t