Mercurial > octave-nkf
annotate liboctave/system/file-ops.cc @ 20538:0829b6ff3ac9 stable
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
* file-ops.cc (octave_canonicalize_file_name): call std::replace to change all
'/' to '\' on Windows platforms.
author | Rik <rik@octave.org> |
---|---|
date | Wed, 02 Sep 2015 12:19:48 -0700 |
parents | 4197fc428c7d |
children | 3aea4200da40 |
rev | line source |
---|---|
1765 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19631
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
1765 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1765 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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 |
19 <http://www.gnu.org/licenses/>. | |
1765 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
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 |
3503 | 32 #include <iostream> |
4726 | 33 #include <vector> |
3040 | 34 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
35 #include <sys/stat.h> |
1765 | 36 #include <sys/types.h> |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
37 #include <unistd.h> |
2926 | 38 |
10279 | 39 #include "pathmax.h" |
15409
c898dbe14e1d
build: Update imported module list from gnulib.
Rik <rik@octave.org>
parents:
15271
diff
changeset
|
40 #include "canonicalize.h" |
1765 | 41 |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
42 extern "C" { |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
43 #include <tempname.h> |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
44 } |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
45 |
5476 | 46 #include "dir-ops.h" |
1765 | 47 #include "file-ops.h" |
5476 | 48 #include "file-stat.h" |
2926 | 49 #include "oct-env.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
50 #include "oct-locbuf.h" |
2934 | 51 #include "oct-passwd.h" |
3710 | 52 #include "pathlen.h" |
5476 | 53 #include "quit.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
54 #include "singleton-cleanup.h" |
2926 | 55 #include "str-vec.h" |
1765 | 56 |
20538
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
57 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
58 #include <algorithm> |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
59 #endif |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
60 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
61 file_ops *file_ops::instance = 0; |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
62 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
63 bool |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
64 file_ops::instance_ok (void) |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
65 { |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
66 bool retval = true; |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
67 |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
68 if (! instance) |
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
69 { |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
70 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
71 char system_dir_sep_char = '\\'; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
72 std::string system_dir_sep_str = "\\"; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
73 #else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
74 char system_dir_sep_char = '/'; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
75 std::string system_dir_sep_str = "/"; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
76 #endif |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
77 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
78 std::string system_dir_sep_chars = "/\\"; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
79 #else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
80 std::string system_dir_sep_chars = system_dir_sep_str; |
5138 | 81 #endif |
82 | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
83 instance = new file_ops (system_dir_sep_char, system_dir_sep_str, |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
84 system_dir_sep_chars); |
6271 | 85 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
86 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
87 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
88 } |
5138 | 89 |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
90 if (! instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
91 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
92 (*current_liboctave_error_handler) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
93 ("unable to create file_ops object!"); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
94 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
95 retval = false; |
3504 | 96 } |
1802 | 97 |
98 return retval; | |
99 } | |
100 | |
3040 | 101 // The following tilde-expansion code was stolen and adapted from |
102 // readline. | |
2926 | 103 |
3040 | 104 // The default value of tilde_additional_prefixes. This is set to |
105 // whitespace preceding a tilde so that simple programs which do not | |
106 // perform any word separation get desired behaviour. | |
107 static const char *default_prefixes[] = { " ~", "\t~", ":~", 0 }; | |
108 | |
109 // The default value of tilde_additional_suffixes. This is set to | |
110 // whitespace or newline so that simple programs which do not perform | |
111 // any word separation get desired behaviour. | |
112 static const char *default_suffixes[] = { " ", "\n", ":", 0 }; | |
113 | |
114 // If non-null, this contains the address of a function that the | |
115 // application wants called before trying the standard tilde | |
116 // expansions. The function is called with the text sans tilde, and | |
117 // returns a malloc()'ed string which is the expansion, or a NULL | |
118 // pointer if the expansion fails. | |
119 file_ops::tilde_expansion_hook file_ops::tilde_expansion_preexpansion_hook = 0; | |
120 | |
121 // If non-null, this contains the address of a function to call if the | |
122 // standard meaning for expanding a tilde fails. The function is | |
123 // called with the text (sans tilde, as in "foo"), and returns a | |
124 // malloc()'ed string which is the expansion, or a NULL pointer if | |
125 // there is no expansion. | |
126 file_ops::tilde_expansion_hook file_ops::tilde_expansion_failure_hook = 0; | |
127 | |
128 // When non-null, this is a NULL terminated array of strings which are | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
129 // duplicates for a tilde prefix. Bash uses this to expand '=~' and |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
130 // ':~'. |
3040 | 131 string_vector file_ops::tilde_additional_prefixes = default_prefixes; |
132 | |
133 // When non-null, this is a NULL terminated array of strings which | |
134 // match the end of a username, instead of just "/". Bash sets this | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
135 // to ':' and '=~'. |
3040 | 136 string_vector file_ops::tilde_additional_suffixes = default_suffixes; |
137 | |
138 // Find the start of a tilde expansion in S, and return the index | |
139 // of the tilde which starts the expansion. Place the length of the | |
140 // text which identified this tilde starter in LEN, excluding the | |
141 // tilde itself. | |
142 | |
143 static size_t | |
3504 | 144 tilde_find_prefix (const std::string& s, size_t& len) |
3040 | 145 { |
146 len = 0; | |
147 | |
148 size_t s_len = s.length (); | |
149 | |
150 if (s_len == 0 || s[0] == '~') | |
151 return 0; | |
152 | |
153 string_vector prefixes = file_ops::tilde_additional_prefixes; | |
154 | |
155 if (! prefixes.empty ()) | |
156 { | |
157 for (size_t i = 0; i < s_len; i++) | |
10180 | 158 { |
159 for (int j = 0; j < prefixes.length (); j++) | |
160 { | |
161 size_t pfx_len = prefixes[j].length (); | |
3040 | 162 |
10180 | 163 if (prefixes[j].compare (s.substr (i, pfx_len)) == 0) |
164 { | |
165 len = pfx_len - 1; | |
166 return i + len; | |
167 } | |
168 } | |
169 } | |
3040 | 170 } |
171 | |
172 return s_len; | |
173 } | |
174 | |
175 // Find the end of a tilde expansion in S, and return the index | |
176 // of the character which ends the tilde definition. | |
177 | |
178 static size_t | |
3504 | 179 tilde_find_suffix (const std::string& s) |
3040 | 180 { |
181 size_t s_len = s.length (); | |
182 | |
183 string_vector suffixes = file_ops::tilde_additional_suffixes; | |
184 | |
185 size_t i = 0; | |
186 | |
187 for ( ; i < s_len; i++) | |
188 { | |
6694 | 189 if (file_ops::is_dir_sep (s[i])) |
10180 | 190 break; |
3040 | 191 |
192 if (! suffixes.empty ()) | |
10180 | 193 { |
194 for (int j = 0; j < suffixes.length (); j++) | |
195 { | |
196 size_t sfx_len = suffixes[j].length (); | |
3040 | 197 |
10180 | 198 if (suffixes[j].compare (s.substr (i, sfx_len)) == 0) |
199 return i; | |
200 } | |
201 } | |
3040 | 202 } |
203 | |
204 return i; | |
205 } | |
206 | |
207 // Take FNAME and return the tilde prefix we want expanded. | |
208 | |
3504 | 209 static std::string |
210 isolate_tilde_prefix (const std::string& fname) | |
3040 | 211 { |
212 size_t f_len = fname.length (); | |
213 | |
214 size_t len = 1; | |
215 | |
6694 | 216 while (len < f_len && ! file_ops::is_dir_sep (fname[len])) |
3040 | 217 len++; |
218 | |
219 return fname.substr (1, len); | |
220 } | |
221 | |
222 // Do the work of tilde expansion on FILENAME. FILENAME starts with a | |
223 // tilde. | |
224 | |
3504 | 225 static std::string |
226 tilde_expand_word (const std::string& filename) | |
3040 | 227 { |
228 size_t f_len = filename.length (); | |
229 | |
230 if (f_len == 0 || filename[0] != '~') | |
231 return filename; | |
232 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
233 // A leading '~/' or a bare '~' is *always* translated to the value |
3040 | 234 // of $HOME or the home directory of the current user, regardless of |
235 // any preexpansion hook. | |
236 | |
6694 | 237 if (f_len == 1 || file_ops::is_dir_sep (filename[1])) |
3040 | 238 return octave_env::get_home_directory () + filename.substr (1); |
239 | |
3504 | 240 std::string username = isolate_tilde_prefix (filename); |
3040 | 241 |
242 size_t user_len = username.length (); | |
243 | |
3504 | 244 std::string dirname; |
3040 | 245 |
246 if (file_ops::tilde_expansion_preexpansion_hook) | |
247 { | |
3504 | 248 std::string expansion |
10180 | 249 = file_ops::tilde_expansion_preexpansion_hook (username); |
3040 | 250 |
251 if (! expansion.empty ()) | |
10180 | 252 return expansion + filename.substr (user_len+1); |
3040 | 253 } |
254 | |
255 // No preexpansion hook, or the preexpansion hook failed. Look in the | |
256 // password database. | |
257 | |
258 octave_passwd pw = octave_passwd::getpwnam (username); | |
259 | |
260 if (! pw) | |
261 { | |
262 // If the calling program has a special syntax for expanding tildes, | |
263 // and we couldn't find a standard expansion, then let them try. | |
264 | |
265 if (file_ops::tilde_expansion_failure_hook) | |
10180 | 266 { |
267 std::string expansion | |
268 = file_ops::tilde_expansion_failure_hook (username); | |
3040 | 269 |
10180 | 270 if (! expansion.empty ()) |
271 dirname = expansion + filename.substr (user_len+1); | |
272 } | |
3040 | 273 |
274 // If we don't have a failure hook, or if the failure hook did not | |
275 // expand the tilde, return a copy of what we were passed. | |
276 | |
277 if (dirname.length () == 0) | |
10180 | 278 dirname = filename; |
3040 | 279 } |
280 else | |
3074 | 281 dirname = pw.dir () + filename.substr (user_len+1); |
3040 | 282 |
283 return dirname; | |
284 } | |
285 | |
286 // If NAME has a leading ~ or ~user, Unix-style, expand it to the | |
287 // user's home directory. If no ~, or no <pwd.h>, just return NAME. | |
288 | |
3504 | 289 std::string |
290 file_ops::tilde_expand (const std::string& name) | |
2926 | 291 { |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
292 if (name.find ('~') == std::string::npos) |
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
293 return name; |
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
294 else |
3040 | 295 { |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
296 std::string result; |
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
297 |
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
298 size_t name_len = name.length (); |
2926 | 299 |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
300 // Scan through S expanding tildes as we come to them. |
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
301 |
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
302 size_t pos = 0; |
3040 | 303 |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
304 while (1) |
10180 | 305 { |
306 if (pos > name_len) | |
307 break; | |
3040 | 308 |
10180 | 309 size_t len; |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
310 |
10180 | 311 // Make START point to the tilde which starts the expansion. |
2926 | 312 |
10180 | 313 size_t start = tilde_find_prefix (name.substr (pos), len); |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
314 |
10180 | 315 result.append (name.substr (pos, start)); |
3040 | 316 |
10180 | 317 // Advance STRING to the starting tilde. |
2926 | 318 |
10180 | 319 pos += start; |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
320 |
10180 | 321 // Make FINI be the index of one after the last character of the |
322 // username. | |
2926 | 323 |
10180 | 324 size_t fini = tilde_find_suffix (name.substr (pos)); |
2926 | 325 |
10180 | 326 // If both START and FINI are zero, we are all done. |
2926 | 327 |
10180 | 328 if (! (start || fini)) |
329 break; | |
2926 | 330 |
10180 | 331 // Expand the entire tilde word, and copy it into RESULT. |
2947 | 332 |
10180 | 333 std::string tilde_word = name.substr (pos, fini); |
3040 | 334 |
10180 | 335 pos += fini; |
2926 | 336 |
10180 | 337 std::string expansion = tilde_expand_word (tilde_word); |
3040 | 338 |
10180 | 339 result.append (expansion); |
340 } | |
8327
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
341 |
4a7a943581d0
Fast return case for file_ops::tilde_expand
David Bateman <dbateman@free.fr>
parents:
8009
diff
changeset
|
342 return result; |
2926 | 343 } |
344 } | |
345 | |
346 // A vector version of the above. | |
347 | |
348 string_vector | |
349 file_ops::tilde_expand (const string_vector& names) | |
350 { | |
351 string_vector retval; | |
352 | |
353 int n = names.length (); | |
354 | |
355 retval.resize (n); | |
356 | |
357 for (int i = 0; i < n; i++) | |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
358 retval[i] = tilde_expand (names[i]); |
2926 | 359 |
360 return retval; | |
361 } | |
1802 | 362 |
7272 | 363 std::string |
364 file_ops::concat (const std::string& dir, const std::string& file) | |
365 { | |
366 return dir.empty () | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
367 ? file |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
368 : (is_dir_sep (dir[dir.length ()-1]) |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
369 ? dir + file |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
370 : dir + dir_sep_char () + file); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
371 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
372 |
18410
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
373 std::string |
18412
f74c6aaa6d0f
Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents:
18410
diff
changeset
|
374 file_ops::native_separator_path (const std::string& path) |
18410
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
375 { |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
376 std::string retval; |
18412
f74c6aaa6d0f
Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents:
18410
diff
changeset
|
377 |
f74c6aaa6d0f
Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents:
18410
diff
changeset
|
378 if (dir_sep_char () == '/') |
18410
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
379 retval = path; |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
380 else |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
381 { |
18412
f74c6aaa6d0f
Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents:
18410
diff
changeset
|
382 size_t n = path.length (); |
f74c6aaa6d0f
Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents:
18410
diff
changeset
|
383 for (size_t i = 0; i < n; i++) |
18410
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
384 { |
18412
f74c6aaa6d0f
Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents:
18410
diff
changeset
|
385 if (path[i] == '/') |
18410
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
386 retval += dir_sep_char(); |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
387 else |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
388 retval += path[i]; |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
389 } |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
390 } |
18412
f74c6aaa6d0f
Use size_t instead of int in cset 073fbe7e6a3a.
Rik <rik@octave.org>
parents:
18410
diff
changeset
|
391 |
18410
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
392 return retval; |
073fbe7e6a3a
Use native separatos in __fltk_getfile__
John Donoghue <john.donoghue@ieee.org>
parents:
18066
diff
changeset
|
393 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
394 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
395 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
396 octave_mkdir (const std::string& nm, mode_t md) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
397 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
398 std::string msg; |
14741
0ab3dd0fad18
Backout changeset a543ed02e673: mkdir-p
John W. Eaton <jwe@octave.org>
parents:
14679
diff
changeset
|
399 return octave_mkdir (nm, md, msg); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
400 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
401 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
402 int |
14741
0ab3dd0fad18
Backout changeset a543ed02e673: mkdir-p
John W. Eaton <jwe@octave.org>
parents:
14679
diff
changeset
|
403 octave_mkdir (const std::string& name, mode_t mode, 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
|
404 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
405 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
406 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
407 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
408 |
14741
0ab3dd0fad18
Backout changeset a543ed02e673: mkdir-p
John W. Eaton <jwe@octave.org>
parents:
14679
diff
changeset
|
409 status = gnulib::mkdir (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
|
410 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
411 if (status < 0) |
10411 | 412 msg = gnulib::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
|
413 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
414 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
415 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
416 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
417 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
418 octave_mkfifo (const std::string& nm, mode_t md) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
419 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
420 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
421 return octave_mkfifo (nm, md, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
422 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
423 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
424 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
425 octave_mkfifo (const std::string& name, mode_t mode, std::string& msg) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
426 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
427 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
428 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
429 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
430 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
431 // With gnulib we will always have mkfifo, but some systems like MinGW |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
432 // don't have working mkfifo functions. On those systems, mkfifo will |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
433 // always return -1 and set errno. |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
434 |
10411 | 435 status = gnulib::mkfifo (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
|
436 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
437 if (status < 0) |
10411 | 438 msg = gnulib::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
|
439 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
440 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
441 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
442 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
443 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
444 octave_link (const std::string& old_name, const std::string& new_name) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
445 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
446 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
447 return octave_link (old_name, new_name, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
448 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
449 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
450 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
451 octave_link (const std::string& old_name, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
452 const std::string& new_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
|
453 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
454 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
455 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
456 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
457 |
10411 | 458 status = gnulib::link (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
|
459 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
460 if (status < 0) |
10411 | 461 msg = gnulib::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
|
462 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
463 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
464 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
465 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
466 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
467 octave_symlink (const std::string& old_name, const std::string& new_name) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
468 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
469 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
470 return octave_symlink (old_name, new_name, msg); |
7272 | 471 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
472 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
473 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
474 octave_symlink (const std::string& old_name, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
475 const std::string& new_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
|
476 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
477 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
478 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
479 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
480 |
10411 | 481 status = gnulib::symlink (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
|
482 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
483 if (status < 0) |
10411 | 484 msg = gnulib::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
|
485 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
486 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
487 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
488 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
489 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
490 octave_readlink (const std::string& path, std::string& result) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
491 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
492 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
493 return octave_readlink (path, result, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
494 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
495 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
496 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
497 octave_readlink (const std::string& path, std::string& result, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
498 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
|
499 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
500 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
501 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
502 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
503 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
504 char buf[MAXPATHLEN+1]; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
505 |
10411 | 506 status = gnulib::readlink (path.c_str (), buf, MAXPATHLEN); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
507 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
508 if (status < 0) |
10411 | 509 msg = gnulib::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
|
510 else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
511 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
512 buf[status] = '\0'; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
513 result = std::string (buf); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
514 status = 0; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
515 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
516 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
517 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
518 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
519 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
520 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
521 octave_rename (const std::string& from, const std::string& to) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
522 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
523 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
524 return octave_rename (from, to, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
525 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
526 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
527 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
528 octave_rename (const std::string& from, const std::string& to, |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
529 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
|
530 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
531 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
532 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
533 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
534 |
10411 | 535 status = gnulib::rename (from.c_str (), to.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
|
536 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
537 if (status < 0) |
10411 | 538 msg = gnulib::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
|
539 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
540 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
541 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
542 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
543 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
544 octave_rmdir (const std::string& name) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
545 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
546 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
547 return octave_rmdir (name, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
548 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
549 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
550 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
551 octave_rmdir (const std::string& name, std::string& msg) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
552 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
553 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
554 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
555 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
556 |
10411 | 557 status = gnulib::rmdir (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
|
558 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
559 if (status < 0) |
10411 | 560 msg = gnulib::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
|
561 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
562 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
563 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
564 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
565 // And a version that works recursively. |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
566 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
567 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
568 octave_recursive_rmdir (const std::string& name) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
569 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
570 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
571 return octave_recursive_rmdir (name, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
572 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
573 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
574 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
575 octave_recursive_rmdir (const std::string& name, std::string& msg) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
576 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
577 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
578 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
579 int status = 0; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
580 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
581 dir_entry dir (name); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
582 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
583 if (dir) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
584 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
585 string_vector dirlist = dir.read (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
586 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
587 for (octave_idx_type i = 0; i < dirlist.length (); i++) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
588 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
589 octave_quit (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
590 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
591 std::string nm = dirlist[i]; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
592 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
593 // Skip current directory and parent. |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
594 if (nm == "." || nm == "..") |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
595 continue; |
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 std::string fullnm = name + file_ops::dir_sep_str () + nm; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
598 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
599 // Get info about the file. Don't follow links. |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
600 file_stat fs (fullnm, false); |
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 if (fs) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
603 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
604 if (fs.is_dir ()) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
605 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
606 status = octave_recursive_rmdir (fullnm, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
607 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
608 if (status < 0) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
609 break; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
610 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
611 else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
612 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
613 status = octave_unlink (fullnm, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
614 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
615 if (status < 0) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
616 break; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
617 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
618 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
619 else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
620 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
621 msg = fs.error (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
622 break; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
623 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
624 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
625 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
626 if (status >= 0) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
627 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
628 dir.close (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
629 status = octave_rmdir (name, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
630 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
631 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
632 else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
633 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
634 status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
635 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
636 msg = dir.error (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
637 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
638 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
639 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
640 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
641 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
642 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
643 octave_umask (mode_t mode) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
644 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
645 #if defined (HAVE_UMASK) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
646 return umask (mode); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
647 #else |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
648 return 0; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
649 #endif |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
650 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
651 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
652 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
653 octave_unlink (const std::string& name) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
654 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
655 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
656 return octave_unlink (name, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
657 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
658 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
659 int |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
660 octave_unlink (const std::string& name, std::string& msg) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
661 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
662 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
663 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
664 int status = -1; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
665 |
10411 | 666 status = gnulib::unlink (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
|
667 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
668 if (status < 0) |
10411 | 669 msg = gnulib::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
|
670 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
671 return status; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
672 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
673 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
674 std::string |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
675 octave_tempnam (const std::string& dir, const std::string& pfx) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
676 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
677 std::string msg; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
678 return octave_tempnam (dir, pfx, msg); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
679 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
680 |
10198
025564630c8d
file-ops.cc: don't tag functions with OCTAVE_API i source file
John W. Eaton <jwe@octave.org>
parents:
10197
diff
changeset
|
681 std::string |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
682 octave_tempnam (const std::string& dir, const std::string& pfx, |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
683 std::string& msg) |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
684 { |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
685 msg = std::string (); |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
686 |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
687 std::string retval; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
688 |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
689 // get dir path to use for template |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
690 std::string templatename; |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
691 if (dir.empty ()) |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
692 templatename = octave_env::get_temp_directory (); |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
693 else if (! file_stat (dir, false).is_dir ()) |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
694 templatename = octave_env::get_temp_directory (); |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
695 else |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
696 templatename = dir; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
697 |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
698 // add dir sep char if it is not there |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
699 if (*templatename.rbegin () != file_ops::dir_sep_char ()) |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
700 templatename += file_ops::dir_sep_char (); |
19454
82f2a3437e02
Fix tempname so it prioritizes user input dir rather than TMPDIR (bug #43844).
Rik <rik@octave.org>
parents:
18412
diff
changeset
|
701 |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
702 if (pfx.empty ()) |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
703 templatename += "file"; |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
704 else |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
705 templatename += pfx; |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
706 |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
707 // add the required XXXXXX for the template |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
708 templatename += "XXXXXX"; |
19462
eee9f111c164
Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents:
19454
diff
changeset
|
709 |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
710 // create and copy template to char array for call to gen_tempname |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
711 char tname [templatename.length () + 1]; |
19462
eee9f111c164
Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents:
19454
diff
changeset
|
712 |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
713 strcpy (tname, templatename.c_str ()); |
19462
eee9f111c164
Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents:
19454
diff
changeset
|
714 |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
715 if (gen_tempname (tname, 0, 0, GT_NOCREATE) == -1) |
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
716 msg = gnulib::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
|
717 else |
19492
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19462
diff
changeset
|
718 retval = tname; |
19631
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19492
diff
changeset
|
719 |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
720 return retval; |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
721 } |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
722 |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
723 std::string |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
724 octave_canonicalize_file_name (const std::string& name) |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
725 { |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
726 std::string msg; |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
727 return octave_canonicalize_file_name (name, msg); |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
728 } |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
729 |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
730 std::string |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
731 octave_canonicalize_file_name (const std::string& name, std::string& msg) |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
732 { |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
733 msg = std::string (); |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
734 |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
735 std::string retval; |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
736 |
10411 | 737 char *tmp = gnulib::canonicalize_file_name (name.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
|
738 |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
739 if (tmp) |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
740 { |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
741 retval = tmp; |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
742 free (tmp); |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
743 } |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
744 |
20538
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
745 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
746 // Canonical Windows file separator is backslash. |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
747 std::replace (retval.begin (), retval.end (), '/', '\\'); |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
748 #endif |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
749 |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
750 if (retval.empty ()) |
10411 | 751 msg = gnulib::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
|
752 |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
753 return retval; |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
754 } |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
755 |