Mercurial > octave
annotate liboctave/system/lo-sysdep.cc @ 25517:7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
* lo-sysdep.[cc/h]: Add new function "octave::sys::fopen".
* gl2ps-print.cc, gzip.cc (CFile), oct-parse.in.yy (parse_fcn_file): Replace
uses of "std::fopen" with "octave::sys::fopen".
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Fri, 29 Jun 2018 15:35:11 +0200 |
parents | 8945a6a6c0eb |
children | c2dc2fb6359b |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 1996-2018 John W. Eaton |
2926 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
10 (at your option) any later version. |
2926 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
15 GNU General Public License for more details. |
2926 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2926 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21642
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21213
diff
changeset
|
24 # include "config.h" |
2926 | 25 #endif |
26 | |
27 #include <string> | |
7695
eacf87a24f55
lo-sysdep.cc: include windows.h if windows and not cygwin
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
28 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
29 #include "dir-ops.h" |
5872 | 30 #include "file-ops.h" |
3069 | 31 #include "lo-error.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
32 #include "lo-sysdep.h" |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
33 #include "uniconv-wrappers.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
34 #include "unistd-wrappers.h" |
2926 | 35 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
36 #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
|
37 # 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
|
38 # include <wchar.h> |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
39 #endif |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
40 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
41 namespace octave |
2926 | 42 { |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
43 namespace sys |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
44 { |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
45 std::string |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
46 getcwd (void) |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
47 { |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
48 std::string retval; |
3069 | 49 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
50 // Using octave_getcwd_wrapper ensures that we have a getcwd that |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
51 // will allocate a buffer as large as necessary if buf and size are |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
52 // both 0. |
3069 | 53 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
54 char *tmp = octave_getcwd_wrapper (nullptr, 0); |
2926 | 55 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
56 if (! tmp) |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
57 (*current_liboctave_error_handler) ("unable to find current directory"); |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
58 |
10250 | 59 retval = tmp; |
60 free (tmp); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
61 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
62 return retval; |
10250 | 63 } |
2926 | 64 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
65 int |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
66 chdir (const std::string& path_arg) |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
67 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
68 std::string path = sys::file_ops::tilde_expand (path_arg); |
5872 | 69 |
21979
d04da18a407a
use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
70 #if defined (OCTAVE_USE_WINDOWS_API) |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
71 if (path.length () == 2 && path[1] == ':') |
23804
8057d3f0673d
Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
72 path += '\\'; |
6244 | 73 #endif |
74 | |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
75 return octave_chdir_wrapper (path.c_str ()); |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
76 } |
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
|
77 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
78 bool |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
79 get_dirlist (const std::string& dirname, string_vector& dirlist, std::string& msg) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
80 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
81 dirlist = ""; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
82 msg = ""; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
83 #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
|
84 _WIN32_FIND_DATAW ffd; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
85 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
86 std::string path_name (dirname); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
87 if (path_name.empty ()) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
88 return true; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
89 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
90 if (path_name.back () == '\\' || path_name.back () == '/') |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
91 path_name.push_back ('*'); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
92 else |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
93 path_name.append (R"(\*)"); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
94 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
95 // Find first file in directory. |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
96 HANDLE hFind = FindFirstFileW (u8_to_wstring (path_name).c_str (), |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
97 &ffd); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
98 if (INVALID_HANDLE_VALUE == hFind) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
99 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
100 DWORD errCode = GetLastError (); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
101 char *errorText; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
102 FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM | |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
103 FORMAT_MESSAGE_ALLOCATE_BUFFER | |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
104 FORMAT_MESSAGE_IGNORE_INSERTS, |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
105 NULL, errCode, |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
106 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
107 errorText, 0, NULL); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
108 if (errorText != NULL) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
109 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
110 msg = std::string (errorText); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
111 LocalFree (errorText); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
112 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
113 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
|
114 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
115 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
116 std::list<std::string> dirlist_str; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
117 do |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
118 dirlist_str.push_back (u8_from_wstring (ffd.cFileName)); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
119 while (FindNextFileW (hFind, &ffd) != 0); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
120 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
121 FindClose(hFind); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
122 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
123 dirlist = string_vector (dirlist_str); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
124 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
125 #else |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
126 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
127 dir_entry dir (dirname); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
128 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
129 if (! dir) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
130 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
131 msg = dir.error (); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
132 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
|
133 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
134 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
135 dirlist = dir.read (); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
136 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
137 dir.close (); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
138 #endif |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
139 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
140 return true; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
141 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
142 |
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
|
143 std::FILE * |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
144 fopen (const std::string& filename, const std::string& mode) |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
145 { |
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
|
146 #if defined (OCTAVE_USE_WINDOWS_API) |
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
|
147 return _wfopen (u8_to_wstring (filename).c_str (), |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
148 u8_to_wstring (mode).c_str ()); |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
149 #else |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
150 return std::fopen (filename.c_str (), mode.c_str ()); |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
151 #endif |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
152 } |
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
|
153 |
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
|
154 std::wstring |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
155 u8_to_wstring (const std::string& utf8_string) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
156 { |
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
|
157 wchar_t *wchar = nullptr; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
158 |
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
|
159 wchar = u8_to_wchar (utf8_string.c_str ()); |
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
|
160 |
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
|
161 std::wstring retval = L""; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
162 if (wchar != nullptr) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
163 { |
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
|
164 retval = std::wstring (wchar); |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
165 free (static_cast<void *> (wchar)); |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
166 } |
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
|
167 |
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
|
168 return retval; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
169 } |
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
|
170 |
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
|
171 std::string |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
172 u8_from_wstring (const std::wstring& wchar_string) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
173 { |
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
|
174 char *mbchar = nullptr; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
175 |
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 mbchar = u8_from_wchar (wchar_string.c_str ()); |
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
|
177 |
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
|
178 std::string retval = ""; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
179 if (mbchar != nullptr) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
180 { |
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
|
181 retval = std::string (mbchar); |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
182 free (static_cast<void *> (mbchar)); |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
183 } |
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
|
184 |
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
|
185 return retval; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
186 } |
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
|
187 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
188 } |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
189 } |