Mercurial > octave
annotate liboctave/system/file-ops.cc @ 27496:def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
* file-ops.cc (canonicalize_file_name): Call GetLongPathNameW to get actual
letter case of file name and path.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Sat, 21 Sep 2019 18:09:29 +0200 |
parents | 84ff9953faa1 |
children | b442ec6dda5c |
rev | line source |
---|---|
1765 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25624
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
1765 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23812
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:
23812
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. |
1765 | 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. |
1765 | 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:
23812
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
1765 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21308
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
24 # include "config.h" |
1765 | 25 #endif |
26 | |
27 #include <cerrno> | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstdio> |
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
29 #include <cstdlib> |
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
30 #include <cstring> |
1765 | 31 |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
32 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
33 # include <algorithm> |
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
34 #endif |
27496
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
35 #if defined (OCTAVE_USE_WINDOWS_API) |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
36 # include <windows.h> |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
37 #endif |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
38 |
4726 | 39 #include <vector> |
3040 | 40 |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
41 #include "areadlink-wrapper.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
42 #include "canonicalize-file-name-wrapper.h" |
5476 | 43 #include "dir-ops.h" |
1765 | 44 #include "file-ops.h" |
5476 | 45 #include "file-stat.h" |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
46 #include "gen-tempname-wrapper.h" |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25438
diff
changeset
|
47 #include "lo-sysdep.h" |
2926 | 48 #include "oct-env.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
49 #include "oct-locbuf.h" |
2934 | 50 #include "oct-passwd.h" |
5476 | 51 #include "quit.h" |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
52 #include "stat-wrappers.h" |
2926 | 53 #include "str-vec.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
54 #include "unistd-wrappers.h" |
20503
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
55 |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
56 namespace octave |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
57 { |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
58 // The following tilde-expansion code was stolen and adapted from |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
59 // readline. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
60 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
61 // The default value of tilde_additional_prefixes. This is set to |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
62 // whitespace preceding a tilde so that simple programs which do not |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
63 // perform any word separation get desired behavior. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
64 static const char *default_prefixes[] = { " ~", "\t~", ":~", nullptr }; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
65 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
66 // The default value of tilde_additional_suffixes. This is set to |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
67 // whitespace or newline so that simple programs which do not perform |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
68 // any word separation get desired behavior. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
69 static const char *default_suffixes[] = { " ", "\n", ":", nullptr }; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
70 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
71 static size_t |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
72 tilde_find_prefix (const std::string& s, size_t& len) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
73 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
74 len = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
75 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
76 size_t s_len = s.length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
77 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
78 if (s_len == 0 || s[0] == '~') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
79 return 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
80 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
81 string_vector prefixes = sys::file_ops::tilde_additional_prefixes; |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
82 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
83 if (! prefixes.empty ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
84 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
85 for (size_t i = 0; i < s_len; i++) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
86 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
87 for (int j = 0; j < prefixes.numel (); j++) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
88 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
89 size_t pfx_len = prefixes[j].length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
90 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
91 if (prefixes[j] == s.substr (i, pfx_len)) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
92 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
93 len = pfx_len - 1; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
94 return i + len; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
95 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
96 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
97 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
98 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
99 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
100 return s_len; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
101 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
102 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
103 // Find the end of a tilde expansion in S, and return the index |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
104 // of the character which ends the tilde definition. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
105 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
106 static size_t |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
107 tilde_find_suffix (const std::string& s) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
108 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
109 size_t s_len = s.length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
110 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
111 string_vector suffixes = sys::file_ops::tilde_additional_suffixes; |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
112 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
113 size_t i = 0; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
114 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
115 for ( ; i < s_len; i++) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
116 { |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
117 if (sys::file_ops::is_dir_sep (s[i])) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
118 break; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
119 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
120 if (! suffixes.empty ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
121 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
122 for (int j = 0; j < suffixes.numel (); j++) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
123 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
124 size_t sfx_len = suffixes[j].length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
125 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
126 if (suffixes[j] == s.substr (i, sfx_len)) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
127 return i; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
128 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
129 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
130 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
131 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
132 return i; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
133 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
134 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
135 // Take FNAME and return the tilde prefix we want expanded. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
136 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
137 static std::string |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
138 isolate_tilde_prefix (const std::string& fname) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
139 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
140 size_t f_len = fname.length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
141 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
142 size_t len = 1; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
143 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
144 while (len < f_len && ! sys::file_ops::is_dir_sep (fname[len])) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
145 len++; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
146 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
147 return fname.substr (1, len); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
148 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
149 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
150 // Do the work of tilde expansion on FILENAME. FILENAME starts with a |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
151 // tilde. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
152 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
153 static std::string |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
154 tilde_expand_word (const std::string& filename) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
155 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
156 size_t f_len = filename.length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
157 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
158 if (f_len == 0 || filename[0] != '~') |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
159 return std::string (filename); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
160 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
161 // A leading '~/' or a bare '~' is *always* translated to the value |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
162 // of $HOME or the home directory of the current user, regardless of |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
163 // any preexpansion hook. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
164 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
165 if (f_len == 1 || sys::file_ops::is_dir_sep (filename[1])) |
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
166 return sys::env::get_home_directory () + filename.substr (1); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
167 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
168 std::string username = isolate_tilde_prefix (filename); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
169 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
170 size_t user_len = username.length (); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
171 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
172 std::string dirname; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
173 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
174 if (sys::file_ops::tilde_expansion_preexpansion_hook) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
175 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
176 std::string expansion |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
177 = sys::file_ops::tilde_expansion_preexpansion_hook (username); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
178 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
179 if (! expansion.empty ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
180 return expansion + filename.substr (user_len+1); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
181 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
182 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
183 // No preexpansion hook, or the preexpansion hook failed. Look in the |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
184 // password database. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
185 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
186 sys::password pw = sys::password::getpwnam (username); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
187 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
188 if (! pw) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
189 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
190 // If the calling program has a special syntax for expanding tildes, |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
191 // and we couldn't find a standard expansion, then let them try. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
192 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
193 if (sys::file_ops::tilde_expansion_failure_hook) |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
194 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
195 std::string expansion |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27101
diff
changeset
|
196 = sys::file_ops::tilde_expansion_failure_hook (username); |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
197 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
198 if (! expansion.empty ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
199 dirname = expansion + filename.substr (user_len+1); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
200 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
201 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
202 // If we don't have a failure hook, or if the failure hook did not |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
203 // expand the tilde, return a copy of what we were passed. |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
204 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
205 if (dirname.empty ()) |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
206 dirname = filename; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
207 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
208 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
209 dirname = pw.dir () + filename.substr (user_len+1); |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
210 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
211 return dirname; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
212 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
213 |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
214 namespace sys |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
215 { |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
216 namespace file_ops |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
217 { |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
218 char dev_sep_char (void) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
219 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
220 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
221 return ':'; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
222 #else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
223 return 0; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
224 #endif |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
225 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
226 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
227 char dir_sep_char (void) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
228 { |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
229 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
230 return '\\'; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
231 #else |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
232 return '/'; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
233 #endif |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
234 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
235 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
236 std::string dir_sep_str (void) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
237 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
238 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
23804
8057d3f0673d
Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
239 return R"(\)"; |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
240 #else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
241 return "/"; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
242 #endif |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
243 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
244 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
245 std::string dir_sep_chars (void) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
246 { |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
247 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) |
23804
8057d3f0673d
Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
248 return R"(/\)"; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
249 #else |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
250 return dir_sep_str (); |
5138 | 251 #endif |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
252 } |
6271 | 253 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23744
diff
changeset
|
254 tilde_expansion_hook tilde_expansion_preexpansion_hook = nullptr; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
255 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23744
diff
changeset
|
256 tilde_expansion_hook tilde_expansion_failure_hook = nullptr; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
257 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
258 string_vector tilde_additional_prefixes = default_prefixes; |
5138 | 259 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
260 string_vector tilde_additional_suffixes = default_suffixes; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
261 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
262 bool is_dev_sep (char c) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
263 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
264 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
265 return c == dev_sep_char (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
266 #else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
267 octave_unused_parameter (c); |
1802 | 268 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
269 return false; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
270 #endif |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
271 } |
2926 | 272 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
273 bool is_dir_sep (char c) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
274 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
275 std::string tmp = dir_sep_chars (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
276 return tmp.find (c) != std::string::npos; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
277 } |
3040 | 278 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
279 std::string tilde_expand (const std::string& name) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
280 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
281 if (name.find ('~') == std::string::npos) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
282 return std::string (name); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
283 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
284 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
285 std::string result; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
286 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
287 size_t name_len = name.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
288 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
289 // Scan through S expanding tildes as we come to them. |
3040 | 290 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
291 size_t pos = 0; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
292 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
293 while (1) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
294 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
295 if (pos > name_len) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
296 break; |
3040 | 297 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
298 size_t len; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
299 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
300 // Make START point to the tilde which starts the expansion. |
3040 | 301 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
302 size_t start = tilde_find_prefix (name.substr (pos), len); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
303 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
304 result.append (name.substr (pos, start)); |
3040 | 305 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
306 // Advance STRING to the starting tilde. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
307 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
308 pos += start; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
309 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
310 // Make FINI be the index of one after the last character of the |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
311 // username. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
312 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
313 size_t fini = tilde_find_suffix (name.substr (pos)); |
3040 | 314 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
315 // If both START and FINI are zero, we are all done. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
316 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
317 if (! (start || fini)) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
318 break; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
319 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
320 // Expand the entire tilde word, and copy it into RESULT. |
3040 | 321 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
322 std::string tilde_word = name.substr (pos, fini); |
3040 | 323 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
324 pos += fini; |
3040 | 325 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
326 std::string expansion = tilde_expand_word (tilde_word); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
327 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
328 result.append (expansion); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
329 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
330 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
331 return result; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
332 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
333 } |
3040 | 334 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
335 string_vector tilde_expand (const string_vector& names) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
336 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
337 int n = names.numel (); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
338 |
23812
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
339 string_vector retval (n); |
3040 | 340 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
341 for (int i = 0; i < n; i++) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
342 retval[i] = tilde_expand (names[i]); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
343 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
344 return retval; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
345 } |
3040 | 346 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
347 std::string concat (const std::string& dir, const std::string& file) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
348 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
349 return dir.empty () |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
350 ? file |
23812
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
351 : (is_dir_sep (dir.back ()) |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
352 ? dir + file |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
353 : dir + dir_sep_char () + file); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
354 } |
3040 | 355 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
356 std::string dirname (const std::string& path) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
357 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
358 size_t ipos = path.find_last_of (dir_sep_chars ()); |
3040 | 359 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
360 return (ipos != std::string::npos) ? path.substr (0, ipos) : ""; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
361 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
362 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
363 std::string tail (const std::string& path) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
364 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
365 size_t ipos = path.find_last_of (dir_sep_chars ()); |
3040 | 366 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
367 if (ipos != std::string::npos) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
368 ipos++; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
369 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
370 ipos = 0; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
371 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
372 return path.substr (ipos); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
373 } |
3040 | 374 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
375 std::string native_separator_path (const std::string& path) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
376 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
377 std::string retval; |
3040 | 378 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
379 if (dir_sep_char () == '/') |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
380 retval = path; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
381 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
382 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
383 size_t n = path.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
384 for (size_t i = 0; i < n; i++) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
385 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
386 if (path[i] == '/') |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
387 retval += dir_sep_char(); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
388 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
389 retval += path[i]; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
390 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
391 } |
3040 | 392 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
393 return retval; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
394 } |
3040 | 395 } |
396 | |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
397 int mkdir (const std::string& nm, mode_t md) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
398 { |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
399 std::string msg; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
400 return mkdir (nm, md, msg); |
21881
aea1bf9493c0
* file-ops.h, file-ops.cc (file_ops::file_ops): Now protected.
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
401 } |
aea1bf9493c0
* file-ops.h, file-ops.cc (file_ops::file_ops): Now protected.
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
402 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
403 int mkdir (const std::string& name, mode_t mode, std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
404 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
405 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
406 |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
407 int status = octave_mkdir_wrapper (name.c_str (), mode); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
408 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
409 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
410 msg = std::strerror (errno); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
411 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
412 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
413 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
414 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
415 int mkfifo (const std::string& nm, mode_t md) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
416 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
417 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
418 return mkfifo (nm, md, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
419 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
420 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
421 int mkfifo (const std::string& name, mode_t mode, std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
422 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
423 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
424 |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
425 int status = octave_mkfifo_wrapper (name.c_str (), mode); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
426 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
427 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
428 msg = std::strerror (errno); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
429 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
430 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
431 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
432 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
433 int link (const std::string& old_name, const std::string& new_name) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
434 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
435 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
436 return link (old_name, new_name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
437 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
438 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
439 int link (const std::string& old_name, const std::string& new_name, |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
440 std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
441 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
442 msg = ""; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
443 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
444 int status = -1; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
445 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
446 status = octave_link_wrapper (old_name.c_str (), new_name.c_str ()); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
447 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
448 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
449 msg = std::strerror (errno); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
450 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
451 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
452 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
453 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
454 int symlink (const std::string& old_name, const std::string& new_name) |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
455 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
456 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
457 return symlink (old_name, new_name, msg); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
458 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
459 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
460 int symlink (const std::string& old_name, const std::string& new_name, |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
461 std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
462 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
463 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
464 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
465 int status = -1; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
466 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
467 status = octave_symlink_wrapper (old_name.c_str (), new_name.c_str ()); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
468 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
469 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
470 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
471 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
472 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
473 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
474 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
475 int readlink (const std::string& path, std::string& result) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
476 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
477 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
478 return readlink (path, result, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
479 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
480 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
481 int readlink (const std::string& path, std::string& result, std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
482 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
483 int status = -1; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
484 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
485 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
486 |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
487 char *buf = octave_areadlink_wrapper (path.c_str ()); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
488 |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
489 if (! buf) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
490 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
491 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
492 { |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
493 result = buf; |
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
494 ::free (buf); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
495 status = 0; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
496 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
497 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
498 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
499 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
500 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
501 int rename (const std::string& from, const std::string& to) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
502 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
503 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
504 return rename (from, to, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
505 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
506 |
25624
815cfd72ddf5
Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
507 int rename (const std::string& from, const std::string& to, |
815cfd72ddf5
Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
508 std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
509 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
510 int status = -1; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
511 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
512 msg = ""; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
513 |
25624
815cfd72ddf5
Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
514 #if defined (OCTAVE_USE_WINDOWS_API) |
815cfd72ddf5
Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
515 status = _wrename (u8_to_wstring (from).c_str (), |
815cfd72ddf5
Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
516 u8_to_wstring (to).c_str ()); |
815cfd72ddf5
Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
517 #else |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
518 status = std::rename (from.c_str (), to.c_str ()); |
25624
815cfd72ddf5
Fix "rename" for files with non-ASCII chars on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
519 #endif |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
520 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
521 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
522 msg = std::strerror (errno); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
523 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
524 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
525 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
526 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
527 int rmdir (const std::string& name) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
528 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
529 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
530 return rmdir (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
531 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
532 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
533 int rmdir (const std::string& name, std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
534 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
535 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
536 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
537 int status = -1; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
538 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
539 status = octave_rmdir_wrapper (name.c_str ()); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
540 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
541 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
542 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
543 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
544 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
545 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
546 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
547 // And a version that works recursively. |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
548 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
549 int recursive_rmdir (const std::string& name) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
550 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
551 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
552 return recursive_rmdir (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
553 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
554 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
555 int recursive_rmdir (const std::string& name, std::string& msg) |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
556 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
557 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
558 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
559 int status = 0; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
560 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25438
diff
changeset
|
561 string_vector dirlist; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
562 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25438
diff
changeset
|
563 if (get_dirlist (name, dirlist, msg)) |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
564 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
565 for (octave_idx_type i = 0; i < dirlist.numel (); i++) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
566 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
567 octave_quit (); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
568 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
569 std::string nm = dirlist[i]; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
570 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
571 // Skip current directory and parent. |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
572 if (nm == "." || nm == "..") |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
573 continue; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
574 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
575 std::string fullnm = name + file_ops::dir_sep_str () + nm; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
576 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
577 // Get info about the file. Don't follow links. |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
578 file_stat fs (fullnm, false); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
579 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
580 if (fs) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
581 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
582 if (fs.is_dir ()) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
583 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
584 status = recursive_rmdir (fullnm, msg); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
585 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
586 if (status < 0) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
587 break; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
588 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
589 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
590 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
591 status = unlink (fullnm, msg); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
592 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
593 if (status < 0) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
594 break; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
595 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
596 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
597 else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
598 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
599 msg = fs.error (); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
600 break; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
601 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
602 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
603 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
604 if (status >= 0) |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25438
diff
changeset
|
605 status = rmdir (name, msg); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
606 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
607 else |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25438
diff
changeset
|
608 status = -1; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
609 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
610 return status; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
611 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
612 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
613 int umask (mode_t mode) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
614 { |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
615 return octave_umask_wrapper (mode); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
616 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
617 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
618 int unlink (const std::string& name) |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
619 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
620 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
621 return unlink (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
622 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
623 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
624 int unlink (const std::string& name, std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
625 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
626 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
627 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
628 int status = -1; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
629 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
630 status = octave_unlink_wrapper (name.c_str ()); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
631 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
632 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
633 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
634 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
635 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
636 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
637 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
638 std::string tempnam (const std::string& dir, const std::string& pfx) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
639 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
640 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
641 return tempnam (dir, pfx, msg); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
642 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
643 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
644 std::string tempnam (const std::string& dir, const std::string& pfx, |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
645 std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
646 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
647 msg = ""; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
648 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
649 std::string retval; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
650 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
651 // get dir path to use for template |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
652 std::string templatename; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
653 if (dir.empty ()) |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
654 templatename = env::get_temp_directory (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
655 else if (! file_stat (dir, false).is_dir ()) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
656 templatename = env::get_temp_directory (); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
657 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
658 templatename = dir; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
659 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
660 // add dir sep char if it is not there |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
661 if (*templatename.rbegin () != file_ops::dir_sep_char ()) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
662 templatename += file_ops::dir_sep_char (); |
19420
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
18412
diff
changeset
|
663 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
664 if (pfx.empty ()) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
665 templatename += "file"; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
666 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
667 templatename += pfx; |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19428
diff
changeset
|
668 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
669 // add the required XXXXXX for the template |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
670 templatename += "XXXXXX"; |
19428
eee9f111c164
Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents:
19420
diff
changeset
|
671 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
672 // create and copy template to char array for call to gen_tempname |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
673 char tname [templatename.length () + 1]; |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19458
diff
changeset
|
674 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
675 strcpy (tname, templatename.c_str ()); |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
676 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
677 if (octave_gen_tempname_wrapper (tname) == -1) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
678 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
679 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
680 retval = tname; |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
681 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
682 return retval; |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
683 } |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
684 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
685 std::string canonicalize_file_name (const std::string& name) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
686 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
687 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
688 return canonicalize_file_name (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
689 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
690 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
691 std::string canonicalize_file_name (const std::string& name, std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
692 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
693 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
694 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
695 std::string retval; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
696 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
697 char *tmp = octave_canonicalize_file_name_wrapper (name.c_str ()); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
698 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
699 if (tmp) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
700 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
701 retval = tmp; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
702 free (tmp); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
703 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
704 |
20503
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
705 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
706 // Canonical Windows file separator is backslash. |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
707 std::replace (retval.begin (), retval.end (), '/', '\\'); |
20503
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
708 #endif |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
709 |
27496
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
710 #if defined (OCTAVE_USE_WINDOWS_API) |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
711 // Get a more canonical name wrt case and full names |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
712 std::wstring w_tmp = L"\\\\?\\" + u8_to_wstring (retval); |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
713 wchar_t w_long[32767] = L""; |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
714 int w_len = GetLongPathNameW (w_tmp.c_str (), w_long, 32767); |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
715 if (w_len > 4) |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
716 retval = u8_from_wstring (std::wstring (w_long+4, w_len-4)); |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
717 if (retval[1] == ':') |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
718 retval[0] = toupper (retval[0]); |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
719 #endif |
def608acdfa9
Canonicalize case of file path on Windows file systems (bug #56267).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27102
diff
changeset
|
720 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
721 if (retval.empty ()) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
722 msg = std::strerror (errno); |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
723 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
724 return retval; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
725 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
726 } |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
727 } |