annotate liboctave/system/lo-sysdep.cc @ 33034:49128bdb9eb2

use explicit lambda-expression captures (bug #65318) Previously, we recommended using implicit capture by value (if possible) in all lambda expressions in Octave. However, this choice causes trouble in the transition period leading up to C++20, when the meaning changes for capturing 'this' by reference when the default capture is '='. Since all lambda expressions in Octave only need to capture a few variables it seems better and relatively easy to simply name all captured variable explicitly. (The maximum number of captured variables currently appears to be seven, including 'this', but the vast majority are capturing just one or two.) Affected files: Canvas.cc, GLCanvas.cc, QTerminal.cc, command-widget.cc, documentation.cc, files-dock-widget.cc, interpreter-qobject.cc, file-editor-tab.cc, file-editor.cc, octave-qscintilla.cc, main-window.cc, octave-dock-widget.cc, octave-qobject.cc, set-path-model.cc, settings-dialog.cc, variable-editor-model.cc, variable-editor.cc, call-stack.cc, gl2ps-print.cc, graphics.cc, input.cc, interpreter.cc, load-path.cc, mex.cc, pr-output.cc, strfns.cc, sysdep.cc, __delaunayn__.cc, audiodevinfo.cc, audioread.cc, oct-parse.yy, pt-eval.cc, Array-util.cc, Range.h, lo-sysdep.cc, lo-regexp.cc, oct-glob.cc, oct-string.cc, and url-transfer.cc.
author John W. Eaton <jwe@octave.org>
date Fri, 16 Feb 2024 14:42:54 -0500
parents 2e484f9f1f18
children 5b54c2fb69bb
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 //
32632
2e484f9f1f18 maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 32590
diff changeset
3 // Copyright (C) 1996-2024 The Octave Project Developers
27923
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
29141
f873857f5f86 system: Support executing commands with non-ASCII characters on Windows (bug #59572).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29016
diff changeset
30 #include <cstdlib>
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
31 #include <locale>
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
32 #include <codecvt>
29141
f873857f5f86 system: Support executing commands with non-ASCII characters on Windows (bug #59572).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29016
diff changeset
33
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
34 #include "dir-ops.h"
5872
44f24cf66b95 [project @ 2006-06-30 18:19:20 by jwe]
jwe
parents: 5307
diff changeset
35 #include "file-ops.h"
32077
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
36 #include "file-stat.h"
3069
db6d57d718f7 [project @ 1997-07-10 23:34:03 by jwe]
jwe
parents: 2926
diff changeset
37 #include "lo-error.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21828
diff changeset
38 #include "lo-sysdep.h"
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
39 #include "localcharset-wrapper.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
40 #include "putenv-wrapper.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21828
diff changeset
41 #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
42 #include "unsetenv-wrapper.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
43
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
44 #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
45 # 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
46 # 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
47
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
48 # include "filepos-wrappers.h"
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
49 # include "lo-hash.h"
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
50 # include "oct-locbuf.h"
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
51 # include "uniconv-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
52 # 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
53 #endif
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
54
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30881
diff changeset
55 OCTAVE_BEGIN_NAMESPACE(octave)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30881
diff changeset
56
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30881
diff changeset
57 OCTAVE_BEGIN_NAMESPACE(sys)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30881
diff changeset
58
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
59 int
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
60 system (const std::string& cmd_str)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
61 {
29141
f873857f5f86 system: Support executing commands with non-ASCII characters on Windows (bug #59572).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29016
diff changeset
62 #if defined (OCTAVE_USE_WINDOWS_API)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
63 const std::wstring wcmd_str = u8_to_wstring (cmd_str);
29141
f873857f5f86 system: Support executing commands with non-ASCII characters on Windows (bug #59572).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29016
diff changeset
64
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
65 return _wsystem (wcmd_str.c_str ());
29141
f873857f5f86 system: Support executing commands with non-ASCII characters on Windows (bug #59572).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29016
diff changeset
66 #else
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
67 return ::system (cmd_str.c_str ());
29141
f873857f5f86 system: Support executing commands with non-ASCII characters on Windows (bug #59572).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29016
diff changeset
68 #endif
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
69 }
29141
f873857f5f86 system: Support executing commands with non-ASCII characters on Windows (bug #59572).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29016
diff changeset
70
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
71 std::string
31771
21f9b34eb893 maint: Eliminate "(void)" in C++ function prototypes/declarations.
Rik <rik@octave.org>
parents: 31706
diff changeset
72 getcwd ()
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
73 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
74 std::string retval;
3069
db6d57d718f7 [project @ 1997-07-10 23:34:03 by jwe]
jwe
parents: 2926
diff changeset
75
28470
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
76 #if defined (OCTAVE_USE_WINDOWS_API)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
77 wchar_t *tmp = _wgetcwd (nullptr, 0);
28470
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
78
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
79 if (! tmp)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
80 (*current_liboctave_error_handler) ("unable to find current directory");
28470
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
81
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
82 std::wstring tmp_wstr (tmp);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
83 free (tmp);
28470
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
84
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
85 std::string tmp_str = u8_from_wstring (tmp_wstr);
28470
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
86
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
87 retval = tmp_str;
28470
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
88
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
89 #else
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
90 // Using octave_getcwd_wrapper ensures that we have a getcwd that
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
91 // will allocate a buffer as large as necessary if buf and size are
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
92 // both 0.
3069
db6d57d718f7 [project @ 1997-07-10 23:34:03 by jwe]
jwe
parents: 2926
diff changeset
93
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
94 char *tmp = octave_getcwd_wrapper (nullptr, 0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
95
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
96 if (! tmp)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
97 (*current_liboctave_error_handler) ("unable to find current directory");
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
98
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
99 retval = tmp;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
100 free (tmp);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
101 #endif
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
102
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
103 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
104 }
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
105
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
106 int
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
107 chdir (const std::string& path_arg)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
108 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
109 std::string path = sys::file_ops::tilde_expand (path_arg);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
110
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
111 #if defined (OCTAVE_USE_WINDOWS_API)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
112 if (path.length () == 2 && path[1] == ':')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
113 path += '\\';
28470
39c078e14824 Use wide character API to get current directory on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28223
diff changeset
114 #endif
21136
7cac4e7458f2 maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents: 19864
diff changeset
115
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
116 return octave_chdir_wrapper (path.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
117 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
118
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
119 bool
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
120 get_dirlist (const std::string& dirname, string_vector& dirlist,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
121 std::string& msg)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
122 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
123 dirlist = "";
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
124 msg = "";
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
125 #if defined (OCTAVE_USE_WINDOWS_API)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
126 _WIN32_FIND_DATAW ffd;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
127
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
128 std::string path_name (dirname);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
129 if (path_name.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
130 return true;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
131
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
132 if (path_name.back () == '\\' || path_name.back () == '/')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
133 path_name.push_back ('*');
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
134 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
135 path_name.append (R"(\*)");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
136
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
137 // Find first file in directory.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
138 std::wstring wpath_name = u8_to_wstring (path_name);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
139 HANDLE hFind = FindFirstFileW (wpath_name.c_str (), &ffd);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
140 if (INVALID_HANDLE_VALUE == hFind)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
141 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
142 DWORD errCode = GetLastError ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
143 char *errorText = nullptr;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
144 FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM |
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
145 FORMAT_MESSAGE_ALLOCATE_BUFFER |
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
146 FORMAT_MESSAGE_IGNORE_INSERTS,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
147 nullptr, errCode,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
148 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
149 reinterpret_cast <char *> (&errorText), 0, nullptr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
150 if (errorText != nullptr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
151 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
152 msg = std::string (errorText);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
153 LocalFree (errorText);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
154 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
155 return false;
10250
2d47356a7a1a use gnulib getcwd module
John W. Eaton <jwe@octave.org>
parents: 10182
diff changeset
156 }
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents:
diff changeset
157
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
158 std::list<std::string> dirlist_str;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
159 do
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
160 dirlist_str.push_back (u8_from_wstring (ffd.cFileName));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
161 while (FindNextFileW (hFind, &ffd) != 0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
162
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
163 FindClose(hFind);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
164
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
165 dirlist = string_vector (dirlist_str);
5872
44f24cf66b95 [project @ 2006-06-30 18:19:20 by jwe]
jwe
parents: 5307
diff changeset
166
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
167 #else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
168
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
169 dir_entry dir (dirname);
6244
8cab253171b6 [project @ 2007-01-17 21:55:49 by jwe]
jwe
parents: 6208
diff changeset
170
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
171 if (! dir)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
172 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
173 msg = dir.error ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
174 return false;
21738
a99c2407f930 use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
175 }
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
176
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
177 dirlist = dir.read ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
178
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
179 dir.close ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
180 #endif
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
181
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
182 return true;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
183 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
184
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
185 #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
186
32590
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 32188
diff changeset
187 static bool
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 32188
diff changeset
188 check_fseek_ftell_workaround_needed (bool set_nonbuffered_mode)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
189 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
190 // To check whether the workaround is needed:
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
191 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
192 // * Create a tmp file with LF line endings only.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
193 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
194 // * Open that file for reading in text mode.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
195 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
196 // * Read a line.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
197 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
198 // * Use ftello to record the position of the beginning of the
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
199 // second line.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
200 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
201 // * Read and save the contents of the second line.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
202 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
203 // * Use fseeko to return to the saved position.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
204 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
205 // * Read the second line again and compare to the previously
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
206 // saved text.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
207 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
208 // * If the lines are different, we need to set non-buffered
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
209 // input mode for files opened in text mode.
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
210
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
211 std::string tmpname = sys::tempnam ("", "oct-");
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
212
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
213 if (tmpname.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
214 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
215 (*current_liboctave_warning_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
216 ("fseek/ftell bug check failed (tmp name creation)!");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
217 return false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
218 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
219
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
220 std::FILE *fptr = std::fopen (tmpname.c_str (), "wb");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
221
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
222 if (! fptr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
223 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
224 (*current_liboctave_warning_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
225 ("fseek/ftell bug check failed (opening tmp file for writing)!");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
226 return false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
227 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
228
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
229 fprintf (fptr, "%s", "foo\nbar\nbaz\n");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
230
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
231 std::fclose (fptr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
232
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
233 fptr = std::fopen (tmpname.c_str (), "rt");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
234
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
235 if (! fptr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
236 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
237 (*current_liboctave_warning_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
238 ("fseek/ftell bug check failed (opening tmp file for reading)!");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
239 return false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
240 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
241
33034
49128bdb9eb2 use explicit lambda-expression captures (bug #65318)
John W. Eaton <jwe@octave.org>
parents: 32632
diff changeset
242 unwind_action act ([] ()
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
243 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
244 std::fclose (fptr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
245 sys::unlink (tmpname);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
246 });
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
247
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
248 if (set_nonbuffered_mode)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
249 ::setvbuf (fptr, nullptr, _IONBF, 0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
250
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
251 while (true)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
252 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
253 int c = fgetc (fptr);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
254
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
255 if (c == EOF)
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
256 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
257 (*current_liboctave_warning_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
258 ("fseek/ftell bug check failed (skipping first line)!");
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
259 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
260 }
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
261
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
262 if (c == '\n')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
263 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
264 }
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
265
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
266 off_t pos = octave_ftello_wrapper (fptr);
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
267
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
268 char buf1[8];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
269 int i = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
270 while (true)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
271 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
272 int c = fgetc (fptr);
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
273
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
274 if (c == EOF)
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
275 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
276 (*current_liboctave_warning_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
277 ("fseek/ftell bug check failed (reading second line)!");
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
278 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
279 }
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
280
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
281 if (c == '\n')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
282 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
283
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
284 buf1[i++] = static_cast<char> (c);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
285 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
286 buf1[i] = '\0';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
287
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
288 octave_fseeko_wrapper (fptr, pos, SEEK_SET);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
289
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
290 char buf2[8];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
291 i = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
292 while (true)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
293 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
294 int c = fgetc (fptr);
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
295
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
296 if (c == EOF)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
297 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
298 (*current_liboctave_warning_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
299 ("fseek/ftell bug check failed (reading after repositioning)!");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
300 return false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
301 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
302
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
303 if (c == '\n')
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
304 break;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
305
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
306 buf2[i++] = static_cast<char> (c);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
307 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
308 buf2[i] = '\0';
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
309
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
310 return strcmp (buf1, buf2);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
311 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
312
32077
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
313 static std::string
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
314 get_formatted_last_error ()
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
315 {
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
316 std::string msg = "";
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
317
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
318 DWORD last_error = GetLastError ();
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
319
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
320 wchar_t *error_text = nullptr;
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
321 FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
322 FORMAT_MESSAGE_ALLOCATE_BUFFER |
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
323 FORMAT_MESSAGE_IGNORE_INSERTS,
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
324 nullptr, last_error,
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
325 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
326 reinterpret_cast <wchar_t *> (&error_text), 0, nullptr);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
327
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
328 if (error_text != nullptr)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
329 {
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
330 msg = u8_from_wstring (error_text);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
331 LocalFree (error_text);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
332 }
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
333 else
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
334 msg = "Unknown error.";
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
335
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
336 return msg;
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
337 }
25516
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
338 #endif
8945a6a6c0eb Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25514
diff changeset
339
32077
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
340 bool
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
341 file_exists (const std::string& filename, bool is_dir)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
342 {
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
343 // Check if a file with the given name exists on the file system. If is_dir
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
344 // is true (the default), also return true if filename refers to a directory.
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
345 #if defined (OCTAVE_USE_WINDOWS_API)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
346 std::wstring w_fn = u8_to_wstring (filename);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
347
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
348 DWORD f_attr = GetFileAttributesW (w_fn.c_str ());
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
349
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
350 return ((f_attr != INVALID_FILE_ATTRIBUTES)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
351 && (is_dir || ! (f_attr & FILE_ATTRIBUTE_DIRECTORY)));
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
352
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
353 #else
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
354 file_stat fs (filename);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
355
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
356 return (fs && (fs.is_reg () || (is_dir && fs.is_dir ())));
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
357
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
358 #endif
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
359 }
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
360
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
361 bool
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
362 file_exists (const std::string& filename, bool is_dir, std::string& msg)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
363 {
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
364 // Check if a file with the given name exists on the file system. If is_dir
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
365 // is true (the default), also return true if filename refers to a directory.
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
366 #if defined (OCTAVE_USE_WINDOWS_API)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
367 std::wstring w_fn = u8_to_wstring (filename);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
368
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
369 DWORD f_attr = GetFileAttributesW (w_fn.c_str ());
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
370
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
371 if (f_attr == INVALID_FILE_ATTRIBUTES)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
372 msg = get_formatted_last_error ();
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
373
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
374 return ((f_attr != INVALID_FILE_ATTRIBUTES)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
375 && (is_dir || ! (f_attr & FILE_ATTRIBUTE_DIRECTORY)));
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
376
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
377 #else
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
378 file_stat fs (filename);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
379
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
380 if (! fs)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
381 msg = fs.error ();
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
382
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
383 return (fs && (fs.is_reg () || (is_dir && fs.is_dir ())));
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
384
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
385 #endif
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
386 }
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
387
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
388 bool
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
389 dir_exists (const std::string& dirname)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
390 {
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
391 // Check if a directory with the given name exists on the file system.
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
392 #if defined (OCTAVE_USE_WINDOWS_API)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
393 std::wstring w_dn = u8_to_wstring (dirname);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
394
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
395 DWORD f_attr = GetFileAttributesW (w_dn.c_str ());
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
396
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
397 return ((f_attr != INVALID_FILE_ATTRIBUTES)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
398 && (f_attr & FILE_ATTRIBUTE_DIRECTORY));
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
399
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
400 #else
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
401 file_stat fs (dirname);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
402
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
403 return (fs && fs.is_dir ());
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
404
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
405 #endif
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
406 }
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
407
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
408 bool
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
409 dir_exists (const std::string& dirname, std::string& msg)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
410 {
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
411 // Check if a directory with the given name exists on the file system.
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
412 #if defined (OCTAVE_USE_WINDOWS_API)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
413 std::wstring w_dn = u8_to_wstring (dirname);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
414
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
415 DWORD f_attr = GetFileAttributesW (w_dn.c_str ());
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
416
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
417 if (f_attr == INVALID_FILE_ATTRIBUTES)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
418 msg = get_formatted_last_error ();
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
419
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
420 return ((f_attr != INVALID_FILE_ATTRIBUTES)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
421 && (f_attr & FILE_ATTRIBUTE_DIRECTORY));
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
422
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
423 #else
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
424 file_stat fs (dirname);
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
425
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
426 if (! fs)
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
427 msg = fs.error ();
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
428
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
429 return (fs && fs.is_dir ());
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
430
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
431 #endif
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
432 }
ed3a18fe328a Add more efficient functions to check for files or directories on Windows (bug #59711).
Markus Mützel <markus.muetzel@gmx.de>
parents: 31771
diff changeset
433
32086
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
434 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file.
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
435
32590
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 32188
diff changeset
436 bool
3c2c585965cc maint: C++ style check for liboctave/ before 9.1 release.
Rik <rik@octave.org>
parents: 32188
diff changeset
437 same_file (const std::string& file1, const std::string& file2)
32086
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
438 {
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
439 #if defined (OCTAVE_USE_WINDOWS_API)
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
440
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
441 // FIXME: When Octave switches to C++17, consider replacing this function
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
442 // by https://en.cppreference.com/w/cpp/filesystem/equivalent.
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
443
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
444 bool retval = false;
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
445
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
446 std::wstring file1w = sys::u8_to_wstring (file1);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
447 std::wstring file2w = sys::u8_to_wstring (file2);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
448 const wchar_t *f1 = file1w.c_str ();
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
449 const wchar_t *f2 = file2w.c_str ();
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
450
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
451 bool f1_is_dir = GetFileAttributesW (f1) & FILE_ATTRIBUTE_DIRECTORY;
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
452 bool f2_is_dir = GetFileAttributesW (f2) & FILE_ATTRIBUTE_DIRECTORY;
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
453
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
454 // Windows native code
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
455 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
456
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
457 DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
458
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
459 HANDLE hfile1
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
460 = CreateFileW (f1, 0, share, 0, OPEN_EXISTING,
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
461 f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
462
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
463 if (hfile1 != INVALID_HANDLE_VALUE)
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
464 {
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
465 HANDLE hfile2
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
466 = CreateFileW (f2, 0, share, 0, OPEN_EXISTING,
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
467 f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
468
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
469 if (hfile2 != INVALID_HANDLE_VALUE)
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
470 {
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
471 BY_HANDLE_FILE_INFORMATION hfi1;
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
472 BY_HANDLE_FILE_INFORMATION hfi2;
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
473
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
474 if (GetFileInformationByHandle (hfile1, &hfi1)
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
475 && GetFileInformationByHandle (hfile2, &hfi2))
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
476 {
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
477 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
478 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
479 && hfi1.nFileIndexLow == hfi2.nFileIndexLow
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
480 && hfi1.nFileSizeHigh == hfi2.nFileSizeHigh
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
481 && hfi1.nFileSizeLow == hfi2.nFileSizeLow
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
482 && hfi1.ftLastWriteTime.dwLowDateTime
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
483 == hfi2.ftLastWriteTime.dwLowDateTime
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
484 && hfi1.ftLastWriteTime.dwHighDateTime
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
485 == hfi2.ftLastWriteTime.dwHighDateTime);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
486 }
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
487
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
488 CloseHandle (hfile2);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
489 }
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
490
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
491 CloseHandle (hfile1);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
492 }
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
493
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
494 return retval;
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
495
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
496 #else
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
497
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
498 // POSIX Code
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
499
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
500 sys::file_stat fs_file1 (file1);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
501 sys::file_stat fs_file2 (file2);
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
502
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
503 return (fs_file1 && fs_file2
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
504 && fs_file1.ino () == fs_file2.ino ()
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
505 && fs_file1.dev () == fs_file2.dev ());
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
506
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
507 #endif
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
508 }
3c608abd55f5 Move "same_file" from liboctinterp to liboctave (bug #63803).
Markus Mützel <markus.muetzel@gmx.de>
parents: 32077
diff changeset
509
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
510 std::FILE *
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
511 fopen (const std::string& filename, const std::string& mode)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
512 {
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
513 #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
514
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
515 std::wstring wfilename = u8_to_wstring (filename);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
516 std::wstring wmode = u8_to_wstring (mode);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
517
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
518 std::FILE *fptr = _wfopen (wfilename.c_str (), wmode.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
519
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
520 static bool fseek_ftell_bug_workaround_needed = false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
521 static bool fseek_ftell_bug_checked = false;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
522
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
523 if (! fseek_ftell_bug_checked && mode.find ('t') != std::string::npos)
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
524 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
525 // FIXME: Is the following workaround needed for all files
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
526 // opened in text mode, or only for files opened for reading?
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
527
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
528 // Try to avoid fseek/ftell bug on Windows systems by setting
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
529 // non-buffered input mode for files opened in text mode, but
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
530 // only if it appears that the workaround is needed. See
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
531 // Octave bug #58055.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
532
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
533 // 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
534 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
535 // * 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
536 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
537 // * 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
538 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
539 // * Read a line.
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
540 //
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
541 // * Use ftello to record the position of the beginning of
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
542 // the second line.
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
543 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
544 // * 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
545 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
546 // * 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
547 //
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
548 // * Read the second line again and compare to the
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
549 // previously saved text.
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
550 //
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
551 // * 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
552 // input mode for files opened in text mode.
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
553 //
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
554 // * To verify that the workaround solves the problem,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
555 // repeat the above test with non-buffered input mode. If
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
556 // that fails, warn that there may be trouble with
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
557 // ftell/fseek when reading files opened in text mode.
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
558
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
559 if (check_fseek_ftell_workaround_needed (false))
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
560 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
561 if (check_fseek_ftell_workaround_needed (true))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
562 (*current_liboctave_warning_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
563 ("fseek/ftell may fail for files opened in text mode");
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
564 else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
565 fseek_ftell_bug_workaround_needed = true;
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
566 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
567
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
568 fseek_ftell_bug_checked = true;
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
569 }
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
570
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
571 if (fseek_ftell_bug_workaround_needed
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
572 && mode.find ('t') != std::string::npos)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
573 ::setvbuf (fptr, nullptr, _IONBF, 0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
574
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
575 return fptr;
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
576
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
577 #else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
578 return std::fopen (filename.c_str (), mode.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
579 #endif
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
580 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
581
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
582 std::FILE *
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
583 fopen_tmp (const std::string& name, const std::string& mode)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
584 {
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
585 #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
586
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
587 // Append "D" to the mode string to indicate that this is a temporary
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
588 // file that should be deleted when the last open handle is closed.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
589 std::string tmp_mode = mode + "D";
28220
6cccc3c82175 attempt to work around Windows ftello/fseeko bug (bug #58055)
John W. Eaton <jwe@octave.org>
parents: 28175
diff changeset
590
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
591 return std::fopen (name.c_str (), tmp_mode.c_str ());
30881
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
592
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
593 #else
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
594
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
595 std::FILE *fptr = std::fopen (name.c_str (), mode.c_str ());
30881
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
596
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
597 // From gnulib: This relies on the Unix semantics that a file is not
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
598 // really removed until it is closed.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
599 octave_unlink_wrapper (name.c_str ());
30881
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
600
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
601 return fptr;
30881
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
602
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
603 #endif
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
604 }
30881
1921d9d0e62b Unify detection of temporary directory (bug #62215).
Markus Mützel <markus.muetzel@gmx.de>
parents: 30565
diff changeset
605
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
606 std::fstream
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
607 fstream (const std::string& filename, const std::ios::openmode mode)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
608 {
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
609 #if defined (OCTAVE_USE_WINDOWS_API)
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
610
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
611 std::wstring wfilename = u8_to_wstring (filename);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
612
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
613 return std::fstream (wfilename.c_str (), mode);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
614
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
615 #else
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
616 return std::fstream (filename.c_str (), mode);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
617 #endif
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
618 }
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
619
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
620 std::ifstream
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
621 ifstream (const std::string& filename, const std::ios::openmode mode)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
622 {
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
623 #if defined (OCTAVE_USE_WINDOWS_API)
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
624
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
625 std::wstring wfilename = u8_to_wstring (filename);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
626
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
627 return std::ifstream (wfilename.c_str (), mode);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
628
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
629 #else
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
630 return std::ifstream (filename.c_str (), mode);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
631 #endif
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
632 }
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
633
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
634 std::ofstream
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
635 ofstream (const std::string& filename, const std::ios::openmode mode)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
636 {
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
637 #if defined (OCTAVE_USE_WINDOWS_API)
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
638
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
639 std::wstring wfilename = u8_to_wstring (filename);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
640
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
641 return std::ofstream (wfilename.c_str (), mode);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
642
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
643 #else
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
644 return std::ofstream (filename.c_str (), mode);
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
645 #endif
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
646 }
29006
139df373c107 Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28470
diff changeset
647
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
648 void
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
649 putenv_wrapper (const std::string& name, const std::string& value)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
650 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
651 std::string new_env = name + "=" + value;
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
652
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
653 // FIXME: The malloc leaks memory, but so would a call to setenv.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
654 // Short of extreme measures to track memory, altering the environment
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
655 // always leaks memory, but the saving grace is that the leaks are small.
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
656
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
657 // As far as I can see there's no way to distinguish between the
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
658 // various errors; putenv doesn't have errno values.
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
659
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
660 #if defined (OCTAVE_USE_WINDOWS_API)
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
661 std::wstring new_wenv = u8_to_wstring (new_env);
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
662
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
663 int len = (new_wenv.length () + 1) * sizeof (wchar_t);
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
664
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
665 wchar_t *new_item = static_cast<wchar_t *> (std::malloc (len));
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
666
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
667 wcscpy (new_item, new_wenv.c_str());
28852
fe0298edc04d Fix compilation error with lambda expression.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28851
diff changeset
668
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
669 if (_wputenv (new_item) < 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
670 (*current_liboctave_error_handler)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
671 ("putenv (%s) failed", new_env.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
672 #else
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
673 int len = new_env.length () + 1;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
674
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
675 char *new_item = static_cast<char *> (std::malloc (len));
28824
a98fd0657e35 Replace unwind_protect with more efficient constructs in liboctave (bug #59192).
Rik <rik@octave.org>
parents: 28534
diff changeset
676
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
677 std::strcpy (new_item, new_env.c_str());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
678
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
679 if (octave_putenv_wrapper (new_item) < 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
680 (*current_liboctave_error_handler) ("putenv (%s) failed", new_item);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
681 #endif
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
682 }
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
683
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
684 std::string
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
685 getenv_wrapper (const std::string& name)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
686 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
687 #if defined (OCTAVE_USE_WINDOWS_API)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
688 std::wstring wname = u8_to_wstring (name);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
689 wchar_t *env = _wgetenv (wname.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
690 return env ? u8_from_wstring (env) : "";
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
691 #else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
692 char *env = ::getenv (name.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
693 return env ? env : "";
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
694 #endif
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
695 }
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
696
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
697 int
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
698 unsetenv_wrapper (const std::string& name)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
699 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
700 #if defined (OCTAVE_USE_WINDOWS_API)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
701 putenv_wrapper (name, "");
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
702
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
703 std::wstring wname = u8_to_wstring (name);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
704 return (SetEnvironmentVariableW (wname.c_str (), nullptr) ? 0 : -1);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
705 #else
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
706 return octave_unsetenv_wrapper (name.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
707 #endif
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
708 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
709
32188
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
710 bool
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
711 isenv_wrapper (const std::string& name)
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
712 {
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
713 #if defined (OCTAVE_USE_WINDOWS_API)
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
714 std::wstring wname = u8_to_wstring (name);
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
715 wchar_t *env = _wgetenv (wname.c_str ());
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
716 #else
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
717 char *env = ::getenv (name.c_str ());
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
718 #endif
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
719 return env != 0;
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
720 }
85255746fc21 Add isenv function (patch #10354).
John Donoghue <john.donoghue@ieee.org>
parents: 32086
diff changeset
721
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
722 std::wstring
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
723 u8_to_wstring (const std::string& utf8_string)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
724 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
725 // convert multibyte UTF-8 string to wide character string
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
726 static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
727 wchar_conv;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
728
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
729 std::wstring retval = L"";
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
730
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
731 try
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
732 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
733 retval = wchar_conv.from_bytes (utf8_string);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
734 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
735 catch (const std::range_error& e)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
736 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
737 // What to do in case of error?
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
738 // error ("u8_to_wstring: converting from UTF-8 to wchar_t: %s",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
739 // e.what ());
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
740 }
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
741
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
742 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
743 }
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25660
diff changeset
744
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
745 std::string
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
746 u8_from_wstring (const std::wstring& wchar_string)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
747 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
748 // convert wide character string to multibyte UTF-8 string
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
749 static std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
750 wchar_conv;
29492
be4b78fb4411 Replace Unicode conversion functions from gnulib with STL functions.
Markus Mützel <markus.muetzel@gmx.de>
parents: 29359
diff changeset
751
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
752 std::string retval = "";
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
753
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
754 try
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
755 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
756 retval = wchar_conv.to_bytes (wchar_string);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
757 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
758 catch (const std::range_error& e)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
759 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
760 // What to do in case of error?
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
761 // error ("u8_from_wstring: converting from wchar_t to UTF-8: %s",
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
762 // e.what ());
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
763 }
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
764
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
765 return retval;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
766 }
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
767
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
768 // At quite a few places in the code we are passing file names as
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
769 // char arrays to external library functions.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
770
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
771 // When these functions try to locate the corresponding file on the
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
772 // disc, they need to use the wide character API on Windows to
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
773 // correctly open files with non-ASCII characters.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
774
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
775 // But they have no way of knowing which encoding we are using for
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
776 // the passed string. So they have no way of reliably converting to
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
777 // a wchar_t array. (I.e. there is no possible fix for these
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
778 // functions with current C or C++.)
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
779
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
780 // To solve the dilemma, the function "get_ASCII_filename" first
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
781 // checks whether there are any non-ASCII characters in the passed
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
782 // file name. If there are not, it returns the original name.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
783
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
784 // Otherwise, it optionally tries to convert the file name to the locale
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
785 // charset.
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
786
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
787 // If the file name contains characters that cannot be converted to the
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
788 // locale charset (or that step is skipped), it tries to obtain the short
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
789 // file name (8.3 naming scheme) which only consists of ASCII characters
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
790 // and are safe to pass. However, short file names can be disabled for
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
791 // performance reasons on the file system level with NTFS and they are not
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
792 // stored on other file systems (e.g. ExFAT). So there is no guarantee
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
793 // that these exist.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
794
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
795 // If short file names are not stored, a hard link to the file is
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
796 // created. For this the path to the file is split at the deepest
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
797 // possible level that doesn't contain non-ASCII characters. At
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
798 // that level a hidden folder is created that holds the hard links.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
799 // That means we need to have write access on that location. A path
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
800 // to that hard link is returned.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
801
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
802 // If the file system is FAT32, there are no hard links. But FAT32
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
803 // always stores short file names. So we are safe.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
804
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
805 // ExFAT that is occasionally used on USB sticks and SD cards stores
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
806 // neither short file names nor does it support hard links. So for
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
807 // exFAT with this function, there is (currently) no way to generate
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
808 // a file name that is stripped from non-ASCII characters but still
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
809 // is valid.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
810
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
811 // For Unixy systems, this function does nothing.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
812
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
813 std::string
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
814 get_ASCII_filename (const std::string& orig_file_name,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
815 const bool allow_locale)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
816 {
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
817 #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
818
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
819 // Return file name that only contains ASCII characters that can
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
820 // be used to access the file orig_file_name. The original file
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
821 // must exist in the file system before calling this function.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
822 // This is useful for passing file names to functions that are not
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
823 // 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
824
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
825 // 0. Check whether filename contains non-ASCII (UTF-8) characters.
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
826
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
827 std::string::const_iterator first_non_ASCII
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
828 = std::find_if (orig_file_name.begin (), orig_file_name.end (),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
829 [](char c) { return (c < 0 || c >= 128); });
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
830
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
831 if (first_non_ASCII == orig_file_name.end ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
832 return orig_file_name;
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
833
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
834 // 1. Optionally, check if all characters in the path can be successfully
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
835 // converted to the locale charset
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
836 if (allow_locale)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
837 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
838 const char *locale = octave_locale_charset_wrapper ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
839 if (locale)
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
840 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
841 const uint8_t *name_u8 = reinterpret_cast<const uint8_t *>
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
842 (orig_file_name.c_str ());
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
843 std::size_t length = 0;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
844 char *name_locale = octave_u8_conv_to_encoding_strict
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
845 (locale, name_u8,
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
846 orig_file_name.length () + 1, &length);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
847 if (name_locale)
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
848 {
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
849 std::string file_name_locale (name_locale, length);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
850 free (name_locale);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
851 return file_name_locale;
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
852 }
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
853 }
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
854 }
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
855
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
856 // 2. Check if file system stores short filenames (might be ASCII-only).
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
857
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
858 std::wstring w_orig_file_name_str = u8_to_wstring (orig_file_name);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
859 const wchar_t *w_orig_file_name = w_orig_file_name_str.c_str ();
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
860
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
861 // Get full path to file
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
862 wchar_t w_full_file_name[_MAX_PATH];
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
863 if (_wfullpath (w_full_file_name, w_orig_file_name, _MAX_PATH) == nullptr)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
864 return orig_file_name;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
865
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
866 std::wstring w_full_file_name_str = w_full_file_name;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
867
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
868 // Get short filename (8.3) from UTF-16 filename.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
869
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
870 long length = GetShortPathNameW (w_full_file_name, nullptr, 0);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
871
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
872 if (length > 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
873 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
874 // Dynamically allocate the correct size (terminating null char
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
875 // was included in length).
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
876
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
877 OCTAVE_LOCAL_BUFFER (wchar_t, w_short_file_name, length);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
878 GetShortPathNameW (w_full_file_name, w_short_file_name, length);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
879
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
880 std::wstring w_short_file_name_str
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
881 = std::wstring (w_short_file_name, length);
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
882
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
883 if (w_short_file_name_str.compare (0, length-1, w_full_file_name_str) != 0)
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
884 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
885 // Check whether short file name contains non-ASCII characters
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
886 std::string short_file_name
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
887 = u8_from_wstring (w_short_file_name_str);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
888 first_non_ASCII
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
889 = std::find_if (short_file_name.begin (),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
890 short_file_name.end (),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
891 [](char c) { return (c < 0 || c >= 128); });
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
892 if (first_non_ASCII == short_file_name.end ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
893 return short_file_name;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
894 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
895 }
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
896
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
897 // 3. Create hard link with only-ASCII characters.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
898 // Get longest possible part of path that only contains ASCII chars.
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
899
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
900 std::wstring::iterator w_first_non_ASCII
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
901 = std::find_if (w_full_file_name_str.begin (), w_full_file_name_str.end (),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
902 [](wchar_t c) { return (c < 0 || c >= 128); });
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
903 std::wstring tmp_substr
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
904 = std::wstring (w_full_file_name_str.begin (), w_first_non_ASCII);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
905
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
906 std::size_t pos
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
907 = tmp_substr.find_last_of (u8_to_wstring (file_ops::dir_sep_chars ()));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
908
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
909 std::string par_dir
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
910 = u8_from_wstring (w_full_file_name_str.substr (0, pos+1));
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
911
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
912 // Create .oct_ascii directory.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
913 // FIXME: We need to have write permission in this location.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
914
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
915 std::string oct_ascii_dir = par_dir + ".oct_ascii";
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
916 std::string test_dir = canonicalize_file_name (oct_ascii_dir);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
917
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
918 if (test_dir.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
919 {
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
920 std::string msg;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
921 int status = sys::mkdir (oct_ascii_dir, 0777, msg);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
922
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
923 if (status < 0)
25660
4de7535ece11 Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25615
diff changeset
924 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
925
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
926 // Set hidden property.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
927 SetFileAttributesA (oct_ascii_dir.c_str (), FILE_ATTRIBUTE_HIDDEN);
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
928 }
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
929
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
930 // Create file from hash of full filename.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
931 std::string filename_hash
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
932 = (oct_ascii_dir + file_ops::dir_sep_str ()
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
933 + 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
934
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
935 // FIXME: This is just to check if the file exists. Use a more efficient
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
936 // method.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
937 std::string abs_filename_hash = canonicalize_file_name (filename_hash);
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
938
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
939 if (! abs_filename_hash.empty ())
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
940 sys::unlink (filename_hash);
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
941
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
942 // At this point, we know that we have only ASCII characters.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
943 // So instead of converting, just copy the characters to std::wstring.
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
944 std::wstring w_filename_hash (filename_hash.begin (),
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
945 filename_hash.end ());
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
946
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
947 if (CreateHardLinkW (w_filename_hash.c_str (), w_orig_file_name, nullptr))
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
948 return filename_hash;
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
949
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
950 #else
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
951
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
952 octave_unused_parameter (allow_locale);
28534
548598760b66 get_ASCII_filename: On Windows, optionally try to convert to the locale charset.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28472
diff changeset
953
25615
ffc858064239 style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents: 25609
diff changeset
954 #endif
25532
7dad5fa7e88e Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25531
diff changeset
955
31607
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
956 return orig_file_name;
aac27ad79be6 maint: Re-indent code after switch to using namespace macros.
Rik <rik@octave.org>
parents: 31605
diff changeset
957 }
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30881
diff changeset
958
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30881
diff changeset
959 OCTAVE_END_NAMESPACE(sys)
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 30881
diff changeset
960 OCTAVE_END_NAMESPACE(octave)