Mercurial > octave
annotate liboctave/system/file-ops.cc @ 23812:057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
* error.cc (maybe_extract_message): Use "back()" rather than "[length () -1]".
* input.cc (base_reader::octave_gets): Use "back()" rather than
"[length () -1]".
* ls-hdf5.cc (read_hdf5_data)): Use "clear()" rather than "resize (0)" to erase
string.
* ls-mat-ascii.cc (get_lines_and_columns): Reformat comment.
* ls-oct-binary.cc (read_binary_data): Use "clear()" rather than "resize (0)"
to erase string.
* oct-stream.cc (delimited_stream::getline): Declare and initialize only one
variable per line as per Octave coding convention.
* oct-stream.cc (textscan_format_list::read_first_row): Use back() and pop_back()
to potentially remove last character from string.
* strfns.cc (Fstrvcat): Use "empty()" rather than "length() > 0".
* sysdep.cc (w32_set_octav_home): Use back() and push_back() to potentially add
dir separator to string.
* gzip.cc (uchar_array): Space out code for readability.
* file-ops.cc (tilde_expand): Call string_vector constructor with size n rather
than resize.
* file-ops.cc (concat): Use "back()" rather than "[length () -1]".
* file-stat.cc (update_internal): Use "back()" rather than "[length () -1]".
Use pop_back() rather than resize() to remove last character.
* oct-env.cc (do_chdir): Use pop_back() rather than resize() to remove last
character.
* cmd-edit.cc (do_generate_filename_completions): Reformat comment.
* cmd-hist.cc (): Use back() and pop_back() to potentially remove "\n" from end
of string.
* data-conv.cc (strip_spaces): Initialize string with null character rather
than space.
* kpse.cc (kpse_tilde_expand): Use "back()" rather than "[length () -1]".
* kpse.cc (kpse_expand_kpse_dot, kpse_brace_expand, kpse_path_expand): Use
pop_back() to potentially remove last character.
* kpse.cc (kpse_brace_expand_element, kpse_element_dir): Use pop_back() to
remove last character.
* lo-utils.cc (octave_fgetl): Use "back()" rather than "[length () -1]".
Use pop_back() rather than resize() to remove last character.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 30 Jul 2017 09:21:58 -0700 |
parents | 8057d3f0673d |
children | 194eb4bd202b |
rev | line source |
---|---|
1765 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23207
diff
changeset
|
3 Copyright (C) 1996-2017 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 | |
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 |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
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 |
19 <http://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 |
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
35 |
3503 | 36 #include <iostream> |
4726 | 37 #include <vector> |
3040 | 38 |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
39 #include "areadlink-wrapper.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
40 #include "canonicalize-file-name-wrapper.h" |
5476 | 41 #include "dir-ops.h" |
1765 | 42 #include "file-ops.h" |
5476 | 43 #include "file-stat.h" |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
44 #include "gen-tempname-wrapper.h" |
2926 | 45 #include "oct-env.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
46 #include "oct-locbuf.h" |
2934 | 47 #include "oct-passwd.h" |
5476 | 48 #include "quit.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
49 #include "singleton-cleanup.h" |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
50 #include "stat-wrappers.h" |
2926 | 51 #include "str-vec.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
52 #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
|
53 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
54 // The following tilde-expansion code was stolen and adapted from |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
55 // readline. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
56 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
57 // The default value of tilde_additional_prefixes. This is set to |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
58 // whitespace preceding a tilde so that simple programs which do not |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
59 // perform any word separation get desired behavior. |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23744
diff
changeset
|
60 static const char *default_prefixes[] = { " ~", "\t~", ":~", nullptr }; |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
61 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
62 // The default value of tilde_additional_suffixes. This is set to |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
63 // whitespace or newline so that simple programs which do not perform |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
64 // any word separation get desired behavior. |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23744
diff
changeset
|
65 static const char *default_suffixes[] = { " ", "\n", ":", nullptr }; |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
66 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
67 static size_t |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
68 tilde_find_prefix (const std::string& s, size_t& len) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
69 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
70 len = 0; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
71 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
72 size_t s_len = s.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
73 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
74 if (s_len == 0 || s[0] == '~') |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
75 return 0; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
76 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
77 string_vector prefixes = octave::sys::file_ops::tilde_additional_prefixes; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
78 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
79 if (! prefixes.empty ()) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
80 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
81 for (size_t i = 0; i < s_len; i++) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
82 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
83 for (int j = 0; j < prefixes.numel (); j++) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
84 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
85 size_t pfx_len = prefixes[j].length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
86 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
87 if (prefixes[j] == s.substr (i, pfx_len)) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
88 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
89 len = pfx_len - 1; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
90 return i + len; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
91 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
92 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
93 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
94 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
95 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
96 return s_len; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
97 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
98 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
99 // Find the end of a tilde expansion in S, and return the index |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
100 // of the character which ends the tilde definition. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
101 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
102 static size_t |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
103 tilde_find_suffix (const std::string& s) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
104 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
105 size_t s_len = s.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
106 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
107 string_vector suffixes = octave::sys::file_ops::tilde_additional_suffixes; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
108 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
109 size_t i = 0; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
110 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
111 for ( ; i < s_len; i++) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
112 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
113 if (octave::sys::file_ops::is_dir_sep (s[i])) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
114 break; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
115 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
116 if (! suffixes.empty ()) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
117 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
118 for (int j = 0; j < suffixes.numel (); j++) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
119 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
120 size_t sfx_len = suffixes[j].length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
121 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
122 if (suffixes[j] == s.substr (i, sfx_len)) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
123 return i; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
124 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
125 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
126 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
127 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
128 return i; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
129 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
130 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
131 // Take FNAME and return the tilde prefix we want expanded. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
132 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
133 static std::string |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
134 isolate_tilde_prefix (const std::string& fname) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
135 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
136 size_t f_len = fname.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
137 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
138 size_t len = 1; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
139 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
140 while (len < f_len && ! octave::sys::file_ops::is_dir_sep (fname[len])) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
141 len++; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
142 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
143 return fname.substr (1, len); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
144 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
145 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
146 // Do the work of tilde expansion on FILENAME. FILENAME starts with a |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
147 // tilde. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
148 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
149 static std::string |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
150 tilde_expand_word (const std::string& filename) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
151 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
152 size_t f_len = filename.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
153 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
154 if (f_len == 0 || filename[0] != '~') |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
155 return std::string (filename); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
156 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
157 // A leading '~/' or a bare '~' is *always* translated to the value |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
158 // of $HOME or the home directory of the current user, regardless of |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
159 // any preexpansion hook. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
160 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
161 if (f_len == 1 || octave::sys::file_ops::is_dir_sep (filename[1])) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
162 return octave::sys::env::get_home_directory () + filename.substr (1); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
163 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
164 std::string username = isolate_tilde_prefix (filename); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
165 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
166 size_t user_len = username.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
167 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
168 std::string dirname; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
169 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
170 if (octave::sys::file_ops::tilde_expansion_preexpansion_hook) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
171 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
172 std::string expansion |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
173 = octave::sys::file_ops::tilde_expansion_preexpansion_hook (username); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
174 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
175 if (! expansion.empty ()) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
176 return expansion + filename.substr (user_len+1); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
177 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
178 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
179 // No preexpansion hook, or the preexpansion hook failed. Look in the |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
180 // password database. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
181 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
182 octave::sys::password pw = octave::sys::password::getpwnam (username); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
183 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
184 if (! pw) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
185 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
186 // If the calling program has a special syntax for expanding tildes, |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
187 // and we couldn't find a standard expansion, then let them try. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
188 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
189 if (octave::sys::file_ops::tilde_expansion_failure_hook) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
190 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
191 std::string expansion |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
192 = octave::sys::file_ops::tilde_expansion_failure_hook (username); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
193 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
194 if (! expansion.empty ()) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
195 dirname = expansion + filename.substr (user_len+1); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
196 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
197 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
198 // If we don't have a failure hook, or if the failure hook did not |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
199 // expand the tilde, return a copy of what we were passed. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
200 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
201 if (dirname.empty ()) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
202 dirname = filename; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
203 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
204 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
205 dirname = pw.dir () + filename.substr (user_len+1); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
206 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
207 return dirname; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
208 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
209 |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
210 namespace octave |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
211 { |
21734
11af9c03400c
write namespace keyword and name on same line in C++ files
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
212 namespace sys |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
213 { |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
214 namespace file_ops |
8007
a2ab20ba78f7
make file_ops a proper singleton class
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
215 { |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
216 char dev_sep_char (void) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
217 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
218 #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
|
219 return ':'; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
220 #else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
221 return 0; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
222 #endif |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
223 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
224 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
225 char dir_sep_char (void) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
226 { |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
227 #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
|
228 return '\\'; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
229 #else |
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 #endif |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
232 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
233 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
234 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
|
235 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
236 #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
|
237 return R"(\)"; |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
238 #else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
239 return "/"; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
240 #endif |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
241 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
242 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
243 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
|
244 { |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
245 #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
|
246 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
|
247 #else |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
248 return dir_sep_str (); |
5138 | 249 #endif |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
250 } |
6271 | 251 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23744
diff
changeset
|
252 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
|
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_failure_hook = nullptr; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
255 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
256 string_vector tilde_additional_prefixes = default_prefixes; |
5138 | 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_suffixes = default_suffixes; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
259 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
260 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
|
261 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
262 #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
|
263 return c == dev_sep_char (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
264 #else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
265 octave_unused_parameter (c); |
1802 | 266 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
267 return false; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
268 #endif |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
269 } |
2926 | 270 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
271 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
|
272 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
273 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
|
274 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
|
275 } |
3040 | 276 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
277 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
|
278 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
279 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
|
280 return std::string (name); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
281 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
282 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
283 std::string result; |
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 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
|
286 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
287 // Scan through S expanding tildes as we come to them. |
3040 | 288 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
289 size_t pos = 0; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
290 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
291 while (1) |
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 if (pos > name_len) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
294 break; |
3040 | 295 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
296 size_t len; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
297 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
298 // Make START point to the tilde which starts the expansion. |
3040 | 299 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
300 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
|
301 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
302 result.append (name.substr (pos, start)); |
3040 | 303 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
304 // 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
|
305 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
306 pos += start; |
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 // 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
|
309 // username. |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
310 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
311 size_t fini = tilde_find_suffix (name.substr (pos)); |
3040 | 312 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
313 // 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
|
314 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
315 if (! (start || fini)) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
316 break; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
317 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
318 // Expand the entire tilde word, and copy it into RESULT. |
3040 | 319 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
320 std::string tilde_word = name.substr (pos, fini); |
3040 | 321 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
322 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 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
|
325 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
326 result.append (expansion); |
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 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
329 return result; |
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 } |
3040 | 332 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
333 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
|
334 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
335 int n = names.numel (); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
336 |
23812
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
337 string_vector retval (n); |
3040 | 338 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
339 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
|
340 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
|
341 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
342 return retval; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
343 } |
3040 | 344 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
345 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
|
346 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
347 return dir.empty () |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
348 ? file |
23812
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
349 : (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
|
350 ? dir + file |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
351 : dir + dir_sep_char () + file); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
352 } |
3040 | 353 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
354 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
|
355 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
356 size_t ipos = path.find_last_of (dir_sep_chars ()); |
3040 | 357 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
358 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
|
359 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
360 |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
361 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
|
362 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
363 size_t ipos = path.find_last_of (dir_sep_chars ()); |
3040 | 364 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
365 if (ipos != std::string::npos) |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
366 ipos++; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
367 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
368 ipos = 0; |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
369 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
370 return path.substr (ipos); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
371 } |
3040 | 372 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
373 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
|
374 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
375 std::string retval; |
3040 | 376 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
377 if (dir_sep_char () == '/') |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
378 retval = path; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
379 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
380 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
381 size_t n = path.length (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
382 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
|
383 { |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
384 if (path[i] == '/') |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
385 retval += dir_sep_char(); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
386 else |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
387 retval += path[i]; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
388 } |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
389 } |
3040 | 390 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
391 return retval; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
392 } |
3040 | 393 } |
394 | |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
395 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
|
396 { |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
397 std::string msg; |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
398 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
|
399 } |
aea1bf9493c0
* file-ops.h, file-ops.cc (file_ops::file_ops): Now protected.
John W. Eaton <jwe@octave.org>
parents:
21852
diff
changeset
|
400 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
401 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
|
402 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
403 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
404 |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
405 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
|
406 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
407 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
408 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
|
409 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
410 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
411 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
412 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
413 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
|
414 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
415 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
416 return mkfifo (nm, md, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
417 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
418 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
419 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
|
420 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
421 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
422 |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
423 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
|
424 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
425 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
426 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
|
427 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
428 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
429 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
430 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
431 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
|
432 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
433 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
434 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
|
435 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
436 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
437 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
|
438 std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
439 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
440 msg = ""; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
441 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
442 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
|
443 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
444 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
|
445 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
446 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
447 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
|
448 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
449 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
450 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
451 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
452 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
|
453 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
454 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
455 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
|
456 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
457 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
458 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
|
459 std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
460 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
461 msg = ""; |
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 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
|
464 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
465 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
|
466 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
467 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
468 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
469 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
470 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
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 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
473 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
|
474 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
475 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
476 return readlink (path, result, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
477 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
478 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
479 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
|
480 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
481 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
|
482 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
483 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
484 |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
485 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
|
486 |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
487 if (! buf) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
488 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
489 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
490 { |
21896
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
491 result = buf; |
83c824c727c9
hide gnulib pathlen header
John W. Eaton <jwe@octave.org>
parents:
21890
diff
changeset
|
492 ::free (buf); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
493 status = 0; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
494 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
495 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
496 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
497 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
498 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
499 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
|
500 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
501 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
502 return rename (from, to, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
503 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
504 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
505 int rename (const std::string& from, const std::string& to, std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
506 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
507 int status = -1; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
508 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
509 msg = ""; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
510 |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
511 status = std::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
|
512 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
513 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
514 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
|
515 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
516 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
517 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
518 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
519 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
|
520 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
521 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
522 return rmdir (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
523 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
524 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
525 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
|
526 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
527 msg = ""; |
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 int status = -1; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
530 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
531 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
|
532 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
533 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
534 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
535 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
536 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
537 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
538 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
539 // 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
|
540 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
541 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
|
542 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
543 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
544 return recursive_rmdir (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
545 } |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
546 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
547 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
|
548 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
549 msg = ""; |
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 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
|
552 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
553 dir_entry dir (name); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
554 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
555 if (dir) |
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 string_vector dirlist = dir.read (); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
558 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
559 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
|
560 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
561 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
|
562 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
563 std::string nm = dirlist[i]; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
564 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
565 // Skip current directory and parent. |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
566 if (nm == "." || nm == "..") |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
567 continue; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
568 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
569 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
|
570 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
571 // 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
|
572 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
|
573 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
574 if (fs) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
575 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
576 if (fs.is_dir ()) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
577 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
578 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
|
579 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
580 if (status < 0) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
581 break; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
582 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
583 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
584 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
585 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
|
586 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
587 if (status < 0) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
588 break; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
589 } |
10197
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 else |
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 msg = fs.error (); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
594 break; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
595 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
596 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
597 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
598 if (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
|
599 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
600 dir.close (); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
601 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
|
602 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
603 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
604 else |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
605 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
606 status = -1; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
607 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
608 msg = dir.error (); |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
609 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
610 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
611 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
|
612 } |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
613 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
614 int umask (mode_t mode) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
615 { |
21909
d7cac41df82a
provide wrappers for some sys/stat functions
John W. Eaton <jwe@octave.org>
parents:
21896
diff
changeset
|
616 return octave_umask_wrapper (mode); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
617 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
618 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
619 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
|
620 { |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
621 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
622 return unlink (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
623 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
624 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
625 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
|
626 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
627 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
628 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
629 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
|
630 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21909
diff
changeset
|
631 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
|
632 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
633 if (status < 0) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
634 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
635 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
636 return status; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
637 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
638 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
639 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
|
640 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
641 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
642 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
|
643 } |
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
644 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
645 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
|
646 std::string& msg) |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
647 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
648 msg = ""; |
10197
4d433bd2d4dc
attempt to avoid trouble with gnulib #defines in a consistent way
John W. Eaton <jwe@octave.org>
parents:
10189
diff
changeset
|
649 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
650 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
|
651 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
652 // 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
|
653 std::string templatename; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
654 if (dir.empty ()) |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
655 templatename = env::get_temp_directory (); |
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
656 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
|
657 templatename = env::get_temp_directory (); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
658 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
659 templatename = dir; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
660 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
661 // 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
|
662 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
|
663 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
|
664 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
665 if (pfx.empty ()) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
666 templatename += "file"; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
667 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
668 templatename += pfx; |
19458
d8fd3842a507
Use gnulib gen_tempname to create temporary names (Bug #43872).
John Donoghue <john.donoghue@ieee.org>
parents:
19428
diff
changeset
|
669 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
670 // 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
|
671 templatename += "XXXXXX"; |
19428
eee9f111c164
Check if tempfile name exists when changing path of temporary file name (Bug #43872)
John Donoghue
parents:
19420
diff
changeset
|
672 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
673 // 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
|
674 char tname [templatename.length () + 1]; |
19597
db92e7e28e1f
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19458
diff
changeset
|
675 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
676 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
|
677 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
678 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
|
679 msg = std::strerror (errno); |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
680 else |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
681 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
|
682 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
683 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
|
684 } |
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
685 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
686 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
|
687 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
688 std::string msg; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
689 return canonicalize_file_name (name, msg); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
690 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
691 |
23744
ae74608b6a5d
don't use singleton pattern for file_ops
John W. Eaton <jwe@octave.org>
parents:
23696
diff
changeset
|
692 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
|
693 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
694 msg = ""; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
695 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
696 std::string retval; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
697 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21885
diff
changeset
|
698 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
|
699 |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
700 if (tmp) |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
701 { |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
702 retval = tmp; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
703 free (tmp); |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
704 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
705 |
20503
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
706 #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
|
707 // Canonical Windows file separator is backslash. |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
708 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
|
709 #endif |
0829b6ff3ac9
Use backslash as windows file separator for canonicalize_file_name (Bug #45816).
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
710 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
711 if (retval.empty ()) |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
712 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
|
713 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
714 return retval; |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
715 } |
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
716 } |
10252
2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
717 } |