annotate liboctave/system/lo-sysdep.cc @ 28467:159b6a1eb408

Use wide character overload to open file streams on Windows. * liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h (fstream, ifstream, ofstream): Add "wrapper" functions to open file streams. * libinterp/corefcn/__fcn__.cc (F__ftp_mput__, F__ftp_mget__), libinterp/corefcn/debug.cc (do_dbtype), libinterp/corefcn/help.cc (help_system::raw_help_from_docstrings_file), libinterp/corefcn/load-save.cc (check_gzip_magic, load_save_system::get_file_format, load_save_system::dump_octave_core, load_save_system::load, load_save_system::save), libinterp/corefcn/oct-hist.cc (mk_tmp_hist_file, history_system::do_edit_history), libinterp/corefcn/urlwrite.cc (Furlwrite), libinterp/octave-value/ov-java.cc (read_java_opts, read_classpath_txt), libinterp/parse-tree/oct-parse.yy (get_file_line), liboctave/util/cmd-hist.cc (gnu_history::do_append), liboctave/util/file-info.cc (file_info::snarf_file), liboctave/util/url-transfer.cc (base_url_transfer::mget_directory, base_url_transfer::mput_directory): Use new functions. * libinterp/corefcn/dlmread.cc (dlmread): Use wide character overload for std::ifstream::open on Windows. * src/mkoctfile.in.cc (octave_u8_conv_to_encoding): Dummy function for cross-compiler. (main): Use wide character overload of std::ofstream::open on Windows.
author Markus Mützel <markus.muetzel@gmx.de>
date Fri, 12 Jun 2020 22:13:04 +0200
parents 45763d59cb4f
children a40e3c3e17fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 1996-2020 The Octave Project Developers
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21642
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21213
diff changeset
27 # include "config.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
28 #endif
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
29
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
30 #include "dir-ops.h"
5872
44f24cf66b95 [project @ 2006-06-30 18:19:20 by jwe]
jwe
parents: 5307
diff changeset
31 #include "file-ops.h"
3069
db6d57d718f7 [project @ 1997-07-10 23:34:03 by jwe]
jwe
parents: 2926
diff changeset
32 #include "lo-error.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21828
diff changeset
33 #include "lo-sysdep.h"
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
34 #include "putenv-wrapper.h"
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
35 #include "uniconv-wrappers.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21828
diff changeset
36 #include "unistd-wrappers.h"
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
37 #include "unsetenv-wrapper.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
38
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
39 #if defined (OCTAVE_USE_WINDOWS_API)
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
40 # include <windows.h>
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
41 # include <wchar.h>
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
42
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
43 # include "lo-hash.h"
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
44 # include "filepos-wrappers.h"
26531
481ac37b0e0e lo-sysdep.cc: Fix static analyzer detected issue (bug #55464).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26506
diff changeset
45 # include "unwind-prot.h"
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
46 #endif
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
47
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
48 namespace octave
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
49 {
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
50 namespace sys
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
51 {
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
52 std::string
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
53 getcwd (void)
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
54 {
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
55 std::string retval;
3069
db6d57d718f7 [project @ 1997-07-10 23:34:03 by jwe]
jwe
parents: 2926
diff changeset
56
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21828
diff changeset
57 // Using octave_getcwd_wrapper ensures that we have a getcwd that
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
58 // will allocate a buffer as large as necessary if buf and size are
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
59 // both 0.
3069
db6d57d718f7 [project @ 1997-07-10 23:34:03 by jwe]
jwe
parents: 2926
diff changeset
60
23795
980f39c3ab90 Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents: 23696
diff changeset
61 char *tmp = octave_getcwd_wrapper (nullptr, 0);
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
62
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
63 if (! tmp)
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
64 (*current_liboctave_error_handler) ("unable to find current directory");
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
65
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
66 retval = tmp;
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
67 free (tmp);
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 19864
diff changeset
68
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
69 return retval;
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
70 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
71
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
72 int
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
73 chdir (const std::string& path_arg)
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
74 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23220
diff changeset
75 std::string path = sys::file_ops::tilde_expand (path_arg);
5872
44f24cf66b95 [project @ 2006-06-30 18:19:20 by jwe]
jwe
parents: 5307
diff changeset
76
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
77 #if defined (OCTAVE_USE_WINDOWS_API)
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
78 if (path.length () == 2 && path[1] == ':')
23804
8057d3f0673d Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents: 23795
diff changeset
79 path += '\\';
6244
8cab253171b6 [project @ 2007-01-17 21:55:49 by jwe]
jwe
parents: 6208
diff changeset
80 #endif
8cab253171b6 [project @ 2007-01-17 21:55:49 by jwe]
jwe
parents: 6208
diff changeset
81
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21828
diff changeset
82 return octave_chdir_wrapper (path.c_str ());
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
83 }
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
84
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
85 bool
27933
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
86 get_dirlist (const std::string& dirname, string_vector& dirlist,
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
87 std::string& msg)
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
88 {
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
89 dirlist = "";
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
90 msg = "";
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
91 #if defined (OCTAVE_USE_WINDOWS_API)
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
92 _WIN32_FIND_DATAW ffd;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
93
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
94 std::string path_name (dirname);
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
95 if (path_name.empty ())
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
96 return true;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
97
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
98 if (path_name.back () == '\\' || path_name.back () == '/')
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
99 path_name.push_back ('*');
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
100 else
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
101 path_name.append (R"(\*)");
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
102
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
103 // Find first file in directory.
28175
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27933
diff changeset
104 std::wstring wpath_name = u8_to_wstring (path_name);
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27933
diff changeset
105 HANDLE hFind = FindFirstFileW (wpath_name.c_str (), &ffd);
25609
506419b5f817 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25532
diff changeset
106 if (INVALID_HANDLE_VALUE == hFind)
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
107 {
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
108 DWORD errCode = GetLastError ();
26163
d478d5d1c8e9 Fix potential segfault on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25916
diff changeset
109 char *errorText = nullptr;
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
110 FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM |
27933
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
111 FORMAT_MESSAGE_ALLOCATE_BUFFER |
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
112 FORMAT_MESSAGE_IGNORE_INSERTS,
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
113 nullptr, errCode,
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
114 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
115 reinterpret_cast <char *> (&errorText), 0, nullptr);
26163
d478d5d1c8e9 Fix potential segfault on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25916
diff changeset
116 if (errorText != nullptr)
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
117 {
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
118 msg = std::string (errorText);
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
119 LocalFree (errorText);
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
120 }
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
121 return false;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
122 }
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
123
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
124 std::list<std::string> dirlist_str;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
125 do
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
126 dirlist_str.push_back (u8_from_wstring (ffd.cFileName));
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
127 while (FindNextFileW (hFind, &ffd) != 0);
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
128
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
129 FindClose(hFind);
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
130
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
131 dirlist = string_vector (dirlist_str);
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
132
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
133 #else
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
134
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
135 dir_entry dir (dirname);
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
136
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
137 if (! dir)
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
138 {
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
139 msg = dir.error ();
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
140 return false;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
141 }
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
142
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
143 dirlist = dir.read ();
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
144
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
145 dir.close ();
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
146 #endif
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
147
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
148 return true;
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
149 }
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
150
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
151 #if defined (OCTAVE_USE_WINDOWS_API)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
152
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
153 static bool check_fseek_ftell_workaround_needed (bool set_nonbuffered_mode)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
154 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
155 // To check whether the workaround is needed:
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
156 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
157 // * Create a tmp file with LF line endings only.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
158 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
159 // * Open that file for reading in text mode.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
160 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
161 // * Read a line.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
162 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
163 // * Use ftello to record the position of the beginning of the
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
164 // second line.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
165 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
166 // * Read and save the contents of the second line.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
167 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
168 // * Use fseeko to return to the saved position.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
169 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
170 // * Read the second line again and compare to the previously
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
171 // saved text.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
172 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
173 // * If the lines are different, we need to set non-buffered
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
174 // input mode for files opened in text mode.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
175
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
176 std::string tmpname = sys::tempnam ("", "oct-");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
177
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
178 if (tmpname.empty ())
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
179 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
180 (*current_liboctave_warning_handler)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
181 ("fseek/ftell bug check failed (tmp name creation)!");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
182 return false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
183 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
184
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
185 std::FILE *fptr = std::fopen (tmpname.c_str (), "wb");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
186
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
187 if (! fptr)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
188 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
189 (*current_liboctave_warning_handler)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
190 ("fseek/ftell bug check failed (opening tmp file for writing)!");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
191 return false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
192 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
193
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
194 fprintf (fptr, "%s", "foo\nbar\nbaz\n");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
195
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
196 std::fclose (fptr);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
197
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
198 fptr = std::fopen (tmpname.c_str (), "rt");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
199
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
200 if (! fptr)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
201 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
202 (*current_liboctave_warning_handler)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
203 ("fseek/ftell bug check failed (opening tmp file for reading)!");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
204 return false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
205 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
206
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
207 unwind_action act ([fptr, tmpname] () {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
208 std::fclose (fptr);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
209 sys::unlink (tmpname);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
210 });
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
211
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
212 if (set_nonbuffered_mode)
28223
45763d59cb4f use nullptr instead of NULL or 0 in a few more places
John W. Eaton <jwe@octave.org>
parents: 28220
diff changeset
213 ::setvbuf (fptr, nullptr, _IONBF, 0);
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
214
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
215 while (true)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
216 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
217 int c = fgetc (fptr);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
218
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
219 if (c == EOF)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
220 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
221 (*current_liboctave_warning_handler)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
222 ("fseek/ftell bug check failed (skipping first line)!");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
223 return false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
224 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
225
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
226 if (c == '\n')
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
227 break;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
228 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
229
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
230 off_t pos = octave_ftello_wrapper (fptr);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
231
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
232 char buf1[8];
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
233 int i = 0;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
234 while (true)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
235 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
236 int c = fgetc (fptr);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
237
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
238 if (c == EOF)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
239 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
240 (*current_liboctave_warning_handler)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
241 ("fseek/ftell bug check failed (reading second line)!");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
242 return false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
243 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
244
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
245 if (c == '\n')
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
246 break;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
247
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
248 buf1[i++] = static_cast<char> (c);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
249 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
250 buf1[i] = '\0';
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
251
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
252 octave_fseeko_wrapper (fptr, pos, SEEK_SET);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
253
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
254 char buf2[8];
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
255 i = 0;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
256 while (true)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
257 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
258 int c = fgetc (fptr);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
259
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
260 if (c == EOF)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
261 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
262 (*current_liboctave_warning_handler)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
263 ("fseek/ftell bug check failed (reading after repositioning)!");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
264 return false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
265 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
266
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
267 if (c == '\n')
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
268 break;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
269
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
270 buf2[i++] = static_cast<char> (c);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
271 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
272 buf2[i] = '\0';
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
273
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
274 return strcmp (buf1, buf2);
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
275 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
276
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
277 #endif
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
278
25517
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
279 std::FILE *
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
280 fopen (const std::string& filename, const std::string& mode)
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
281 {
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
282 #if defined (OCTAVE_USE_WINDOWS_API)
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
283
28175
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27933
diff changeset
284 std::wstring wfilename = u8_to_wstring (filename);
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27933
diff changeset
285 std::wstring wmode = u8_to_wstring (mode);
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
286
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
287 std::FILE *fptr = _wfopen (wfilename.c_str (), wmode.c_str ());
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
288
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
289 static bool fseek_ftell_bug_workaround_needed = false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
290 static bool fseek_ftell_bug_checked = false;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
291
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
292 if (! fseek_ftell_bug_checked && mode.find ('t') != std::string::npos)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
293 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
294 // FIXME: Is the following workaround needed for all files
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
295 // opened in text mode, or only for files opened for reading?
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
296
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
297 // Try to avoid fseek/ftell bug on Windows systems by setting
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
298 // non-buffered input mode for files opened in text mode, but
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
299 // only if it appears that the workaround is needed. See
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
300 // Octave bug #58055.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
301
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
302 // To check whether the workaround is needed:
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
303 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
304 // * Create a tmp file with LF line endings only.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
305 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
306 // * Open that file for reading in text mode.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
307 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
308 // * Read a line.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
309 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
310 // * Use ftello to record the position of the beginning of
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
311 // the second line.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
312 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
313 // * Read and save the contents of the second line.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
314 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
315 // * Use fseeko to return to the saved position.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
316 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
317 // * Read the second line again and compare to the
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
318 // previously saved text.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
319 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
320 // * If the lines are different, we need to set non-buffered
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
321 // input mode for files opened in text mode.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
322 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
323 // * To verify that the workaround solves the problem,
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
324 // repeat the above test with non-buffered input mode. If
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
325 // that fails, warn that there may be trouble with
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
326 // ftell/fseek when reading files opened in text mode.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
327
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
328 if (check_fseek_ftell_workaround_needed (false))
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
329 {
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
330 if (check_fseek_ftell_workaround_needed (true))
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
331 (*current_liboctave_warning_handler)
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
332 ("fseek/ftell may fail for files opened in text mode");
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
333 else
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
334 fseek_ftell_bug_workaround_needed = true;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
335 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
336
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
337 fseek_ftell_bug_checked = true;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
338 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
339
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
340 if (fseek_ftell_bug_workaround_needed
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
341 && mode.find ('t') != std::string::npos)
28223
45763d59cb4f use nullptr instead of NULL or 0 in a few more places
John W. Eaton <jwe@octave.org>
parents: 28220
diff changeset
342 ::setvbuf (fptr, nullptr, _IONBF, 0);
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
343
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
344 return fptr;
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
345
25517
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
346 #else
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
347 return std::fopen (filename.c_str (), mode.c_str ());
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
348 #endif
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
349 }
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
350
28467
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
351 std::fstream
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
352 fstream (const std::string& filename, const std::ios::openmode mode)
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
353 {
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
354 #if defined (OCTAVE_USE_WINDOWS_API)
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
355
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
356 std::wstring wfilename = u8_to_wstring (filename);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
357
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
358 return std::fstream (wfilename.c_str (), mode);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
359
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
360 #else
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
361 return std::fstream (filename.c_str (), mode);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
362 #endif
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
363 }
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
364
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
365 std::ifstream
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
366 ifstream (const std::string& filename, const std::ios::openmode mode)
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
367 {
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
368 #if defined (OCTAVE_USE_WINDOWS_API)
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
369
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
370 std::wstring wfilename = u8_to_wstring (filename);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
371
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
372 return std::ifstream (wfilename.c_str (), mode);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
373
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
374 #else
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
375 return std::ifstream (filename.c_str (), mode);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
376 #endif
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
377 }
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
378
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
379 std::ofstream
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
380 ofstream (const std::string& filename, const std::ios::openmode mode)
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
381 {
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
382 #if defined (OCTAVE_USE_WINDOWS_API)
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
383
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
384 std::wstring wfilename = u8_to_wstring (filename);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
385
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
386 return std::ofstream (wfilename.c_str (), mode);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
387
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
388 #else
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
389 return std::ofstream (filename.c_str (), mode);
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
390 #endif
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
391 }
159b6a1eb408 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
392
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
393 void
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
394 putenv_wrapper (const std::string& name, const std::string& value)
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
395 {
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
396 // This function was adapted from xputenv from Karl Berry's kpathsearch
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
397 // library.
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
398 // FIXME: make this do the right thing if we don't have a SMART_PUTENV.
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
399
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
400 int new_len = name.length () + value.length () + 2;
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
401
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
402 // FIXME: This leaks memory, but so would a call to setenv.
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
403 // Short of extreme measures to track memory, altering the environment
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
404 // always leaks memory, but the saving grace is that the leaks are small.
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
405
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
406 char *new_item = static_cast<char *> (std::malloc (new_len));
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
407
26506
9cf999911dfe lo-sysdep.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
408 if (new_item)
9cf999911dfe lo-sysdep.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
409 sprintf (new_item, "%s=%s", name.c_str (), value.c_str ());
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
410
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
411 // As far as I can see there's no way to distinguish between the
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
412 // various errors; putenv doesn't have errno values.
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
413
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
414 #if defined (OCTAVE_USE_WINDOWS_API)
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
415 wchar_t *wnew_item = u8_to_wchar (new_item);
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26531
diff changeset
416 unwind_protect frame;
26531
481ac37b0e0e lo-sysdep.cc: Fix static analyzer detected issue (bug #55464).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26506
diff changeset
417 frame.add_fcn (std::free, static_cast<void *> (new_item));
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
418 if (_wputenv (wnew_item) < 0)
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
419 (*current_liboctave_error_handler) ("putenv (%s) failed", new_item);
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
420 #else
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
421 if (octave_putenv_wrapper (new_item) < 0)
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
422 (*current_liboctave_error_handler) ("putenv (%s) failed", new_item);
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
423 #endif
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
424 }
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
425
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
426 std::string
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
427 getenv_wrapper (const std::string& name)
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
428 {
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
429 #if defined (OCTAVE_USE_WINDOWS_API)
28175
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27933
diff changeset
430 std::wstring wname = u8_to_wstring (name);
b895daca20e2 Avoid potential lifetime issues with temporary std::wstring objects.
Markus Mützel <markus.muetzel@gmx.de>
parents: 27933
diff changeset
431 wchar_t *env = _wgetenv (wname.c_str ());
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
432 return env ? u8_from_wstring (env) : "";
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
433 #else
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
434 char *env = ::getenv (name.c_str ());
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
435 return env ? env : "";
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
436 #endif
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
437 }
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
438
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
439 int
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
440 unsetenv_wrapper (const std::string& name)
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
441 {
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
442 #if defined (OCTAVE_USE_WINDOWS_API)
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
443 putenv_wrapper (name, "");
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
444
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
445 std::wstring wname = u8_to_wstring (name);
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
446 return (SetEnvironmentVariableW (wname.c_str (), nullptr) ? 0 : -1);
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
447 #else
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
448 return octave_unsetenv_wrapper (name.c_str ());
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
449 #endif
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
450 }
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
451
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
452 std::wstring
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
453 u8_to_wstring (const std::string& utf8_string)
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
454 {
25531
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
455 size_t srclen = utf8_string.length ();
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
456 const uint8_t *src = reinterpret_cast<const uint8_t *>
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
457 (utf8_string.c_str ());
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
458
25531
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
459 size_t length = 0;
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
460 wchar_t *wchar = reinterpret_cast<wchar_t *>
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
461 (octave_u8_conv_to_encoding ("wchar_t", src, srclen,
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
462 &length));
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
463
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
464 std::wstring retval = L"";
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
465 if (wchar != nullptr)
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
466 {
25531
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
467 retval = std::wstring (wchar, length / sizeof (wchar_t));
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
468 free (static_cast<void *> (wchar));
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
469 }
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
470
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
471 return retval;
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
472 }
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
473
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
474 std::string
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
475 u8_from_wstring (const std::wstring& wchar_string)
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
476 {
25531
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
477 size_t srclen = wchar_string.length () * sizeof (wchar_t);
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
478 const char *src = reinterpret_cast<const char *> (wchar_string.c_str ());
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
479
25531
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
480 size_t length = 0;
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
481 char *mbchar = reinterpret_cast<char *>
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
482 (octave_u8_conv_from_encoding ("wchar_t", src, srclen,
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
483 &length));
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
484
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
485 std::string retval = "";
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
486 if (mbchar != nullptr)
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
487 {
25531
c2dc2fb6359b Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25517
diff changeset
488 retval = std::string (mbchar, length);
25514
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
489 free (static_cast<void *> (mbchar));
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
490 }
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
491
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
492 return retval;
c63f67d87b4a Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25054
diff changeset
493 }
25517
7fbc39a46be8 Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25516
diff changeset
494
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
495 // At quite a few places in the code we are passing file names as
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
496 // char arrays to external library functions.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
497
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
498 // When these functions try to locate the corresponding file on the
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
499 // disc, they need to use the wide character API on Windows to
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
500 // correctly open files with non-ASCII characters.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
501
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
502 // But they have no way of knowing which encoding we are using for
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
503 // the passed string. So they have no way of reliably converting to
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
504 // a wchar_t array. (I.e. there is no possible fix for these
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
505 // functions with current C or C++.)
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
506
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
507 // To solve the dilemma, the function "get_ASCII_filename" first
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
508 // checks whether there are any non-ASCII characters in the passed
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
509 // file name. If there are not, it returns the original name.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
510
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
511 // Otherwise, it tries to obtain the short file name (8.3 naming
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
512 // scheme) which only consists of ASCII characters and are safe to
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
513 // pass. However, short file names can be disabled for performance
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
514 // reasons on the file system level with NTFS. So there is no
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
515 // guarantee that these exist.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
516
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
517 // If short file names are not stored, a hard link to the file is
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
518 // created. For this the path to the file is split at the deepest
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
519 // possible level that doesn't contain non-ASCII characters. At
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
520 // that level a hidden folder is created that holds the hard links.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
521 // That means we need to have write access on that location. A path
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
522 // to that hard link is returned.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
523
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
524 // If the file system is FAT32, there are no hard links. But FAT32
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
525 // always stores short file names. So we are safe.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
526
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
527 // ExFAT that is occasionally used on USB sticks and SD cards stores
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
528 // neither short file names nor does it support hard links. So for
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
529 // exFAT with this function, there is (currently) no way to generate
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
530 // a file name that is stripped from non-ASCII characters but still
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
531 // is valid.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
532
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
533 // For Unixy systems, this function does nothing.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
534
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
535 std::string
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
536 get_ASCII_filename (const std::string& orig_file_name)
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
537 {
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
538 #if defined (OCTAVE_USE_WINDOWS_API)
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
539
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
540 // Return file name that only contains ASCII characters that can
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
541 // be used to access the file orig_file_name. The original file
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
542 // must exist in the file system before calling this function.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
543 // This is useful for passing file names to functions that are not
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
544 // aware of the character encoding we are using.
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
545
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
546 // 1. Check whether filename contains non-ASCII (UTF-8) characters.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
547
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
548 std::string::const_iterator first_non_ASCII
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
549 = std::find_if (orig_file_name.begin (), orig_file_name.end (),
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
550 [](char c) { return (c < 0 || c >= 128); });
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
551
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
552 if (first_non_ASCII == orig_file_name.end ())
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
553 return orig_file_name;
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
554
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
555 // 2. Check if file system stores short filenames (always
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
556 // ASCII-only).
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
557
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
558 std::wstring w_orig_file_name_str = u8_to_wstring (orig_file_name);
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
559 const wchar_t *w_orig_file_name = w_orig_file_name_str.c_str ();
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
560
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
561 // Get full path to file
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
562 wchar_t w_full_file_name[_MAX_PATH];
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
563 if (_wfullpath (w_full_file_name, w_orig_file_name, _MAX_PATH) == nullptr)
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
564 return orig_file_name;
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
565
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
566 std::wstring w_full_file_name_str = w_full_file_name;
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
567
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
568 // Get short filename (8.3) from UTF-16 filename.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
569
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
570 long length = GetShortPathNameW (w_full_file_name, nullptr, 0);
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
571
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
572 if (length > 0)
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
573 {
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
574 // Dynamically allocate the correct size (terminating null char
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
575 // was included in length).
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
576
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
577 wchar_t *w_short_file_name = new wchar_t[length];
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
578 GetShortPathNameW (w_full_file_name, w_short_file_name, length);
25609
506419b5f817 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25532
diff changeset
579
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
580 std::wstring w_short_file_name_str
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
581 = std::wstring (w_short_file_name, length);
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
582 std::string short_file_name = u8_from_wstring (w_short_file_name_str);
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
583
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
584 if (w_short_file_name_str.compare (0, length-1, w_full_file_name_str) != 0)
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
585 return short_file_name;
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
586 }
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
587
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
588 // 3. Create hard link with only-ASCII characters.
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
589 // Get longest possible part of path that only contains ASCII chars.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
590
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
591 std::wstring::iterator w_first_non_ASCII
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
592 = std::find_if (w_full_file_name_str.begin (), w_full_file_name_str.end (),
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
593 [](wchar_t c) { return (c < 0 || c >= 128); });
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
594 std::wstring tmp_substr
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
595 = std::wstring (w_full_file_name_str.begin (), w_first_non_ASCII);
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
596
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
597 size_t pos
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
598 = tmp_substr.find_last_of (u8_to_wstring (file_ops::dir_sep_chars ()));
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
599
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
600 std::string par_dir
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
601 = u8_from_wstring (w_full_file_name_str.substr (0, pos+1));
25609
506419b5f817 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 25532
diff changeset
602
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
603 // Create .oct_ascii directory.
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
604 // FIXME: We need to have write permission in this location.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
605
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
606 std::string oct_ascii_dir = par_dir + ".oct_ascii";
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
607 std::string test_dir = canonicalize_file_name (oct_ascii_dir);
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
608
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
609 if (test_dir.empty ())
27933
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
610 {
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
611 std::string msg;
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
612 int status = sys::mkdir (oct_ascii_dir, 0777, msg);
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
613
27933
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
614 if (status < 0)
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
615 return orig_file_name;
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
616
27933
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
617 // Set hidden property.
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
618 SetFileAttributesA (oct_ascii_dir.c_str (), FILE_ATTRIBUTE_HIDDEN);
863ae57eee69 maint: Use Octave coding conventions in liboctave/
Rik <rik@octave.org>
parents: 27923
diff changeset
619 }
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
620
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
621 // Create file from hash of full filename.
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
622 std::string filename_hash
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
623 = (oct_ascii_dir + file_ops::dir_sep_str ()
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26531
diff changeset
624 + crypto::hash ("SHA1", orig_file_name));
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
625
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
626 std::string abs_filename_hash = canonicalize_file_name (filename_hash);
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
627
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
628 if (! abs_filename_hash.empty ())
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26531
diff changeset
629 sys::unlink (filename_hash);
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
630
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
631 wchar_t w_filename_hash[filename_hash.length ()+1] = {0};
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
632
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
633 for (size_t i=0; i < filename_hash.length (); i++)
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
634 w_filename_hash[i] = filename_hash.at (i);
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
635
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
636 if (CreateHardLinkW (w_filename_hash, w_orig_file_name, nullptr))
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
637 return filename_hash;
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
638
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
639 #endif
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
640
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
641 return orig_file_name;
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
642 }
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
643 }
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
644 }