GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
file-ops.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software: you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_file_ops_h)
24 #define octave_file_ops_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 
30 #include <sys/types.h>
31 
32 #include "str-vec.h"
33 
34 namespace octave
35 {
36  namespace sys
37  {
38  namespace file_ops
39  {
41 
42  // If non-null, this contains the address of a function that the
43  // application wants called before trying the standard tilde
44  // expansions. The function is called with the text sans tilde, and
45  // returns a malloc()'ed string which is the expansion, or a NULL
46  // pointer if the expansion fails.
47 
49 
50  // If non-null, this contains the address of a function to call if the
51  // standard meaning for expanding a tilde fails. The function is
52  // called with the text (sans tilde, as in "foo"), and returns a
53  // malloc()'ed string which is the expansion, or a NULL pointer if
54  // there is no expansion.
55 
57 
58  // When non-null, this is a NULL terminated array of strings which are
59  // duplicates for a tilde prefix. Bash uses this to expand '=~' and
60  // ':~'.
61 
63 
64  // When non-null, this is a NULL terminated array of strings which
65  // match the end of a username, instead of just "/". Bash sets this
66  // to ':' and '=~'.
67 
69 
70  // Find the start of a tilde expansion in S, and return the index
71  // of the tilde which starts the expansion. Place the length of the
72  // text which identified this tilde starter in LEN, excluding the
73  // tilde itself.
74 
75  char dev_sep_char (void);
76 
77  bool is_dev_sep (char c);
78 
79  char dir_sep_char (void);
80 
81  std::string dir_sep_str (void);
82 
84 
85  bool is_dir_sep (char c);
86 
87  // If NAME has a leading ~ or ~user, Unix-style, expand it to the
88  // user's home directory. If no ~, or no <pwd.h>, just return NAME.
89 
91 
92  // A vector version of the above.
93 
95 
96  std::string concat (const std::string&, const std::string&);
97 
98  // Return the directory part of a filename or an empty string if
99  // there is no directory component. Does not check to see
100  // whether the file exists or is a directory.
101 
102  std::string dirname (const std::string& path);
103 
104  // Return the tail member of a filename.
105 
106  std::string tail (const std::string& path);
107 
108  // convert path from UNIX type separators to whatever is the system separators
109 
111  }
112 
113  extern OCTAVE_API int
114  mkdir (const std::string&, mode_t);
115 
116  extern OCTAVE_API int
117  mkdir (const std::string&, mode_t, std::string&);
118 
119  extern OCTAVE_API int
120  mkfifo (const std::string&, mode_t);
121 
122  extern OCTAVE_API int
123  mkfifo (const std::string&, mode_t, std::string&);
124 
125  extern OCTAVE_API int
126  link (const std::string&, const std::string&);
127 
128  extern OCTAVE_API int
129  link (const std::string&, const std::string&, std::string&);
130 
131  extern OCTAVE_API int
132  symlink (const std::string&, const std::string&);
133 
134  extern OCTAVE_API int
135  symlink (const std::string&, const std::string&, std::string&);
136 
137  extern OCTAVE_API int
138  readlink (const std::string&, std::string&);
139 
140  extern OCTAVE_API int
142 
143  extern OCTAVE_API int
144  rename (const std::string&, const std::string&);
145 
146  extern OCTAVE_API int
147  rename (const std::string&, const std::string&, std::string&);
148 
149  extern OCTAVE_API int
150  rmdir (const std::string&);
151 
152  extern OCTAVE_API int
153  rmdir (const std::string&, std::string&);
154 
155  extern OCTAVE_API int
156  recursive_rmdir (const std::string&);
157 
158  extern OCTAVE_API int
160 
161  extern OCTAVE_API int
162  umask (mode_t);
163 
164  extern OCTAVE_API int
165  unlink (const std::string&);
166 
167  extern OCTAVE_API int
168  unlink (const std::string&, std::string&);
169 
170  extern OCTAVE_API std::string
171  tempnam (const std::string&, const std::string&);
172 
173  extern OCTAVE_API std::string
174  tempnam (const std::string&, const std::string&, std::string&);
175 
176  extern OCTAVE_API std::string
178 
179  extern OCTAVE_API std::string
181  }
182 }
183 
184 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
185 
186 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::mkdir' instead")
187 inline int
188 octave_mkdir (const std::string& nm, mode_t md)
189 {
190  return octave::sys::mkdir (nm, md);
191 }
192 
193 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::mkdir' instead")
194 inline int
195 octave_mkdir (const std::string& nm, mode_t md, std::string& msg)
196 {
197  return octave::sys::mkdir (nm, md, msg);
198 }
199 
200 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::mkfifo' instead")
201 inline int
202 octave_mkfifo (const std::string& nm, mode_t md)
203 {
204  return octave::sys::mkfifo (nm, md);
205 }
206 
207 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::mkfifo' instead")
208 inline int
209 octave_mkfifo (const std::string& nm, mode_t md, std::string& msg)
210 {
211  return octave::sys::mkfifo (nm, md, msg);
212 }
213 
214 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::link' instead")
215 inline int
216 octave_link (const std::string& old_name, const std::string& new_name)
217 {
218  return octave::sys::link (old_name, new_name);
219 }
220 
221 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::link' instead")
222 inline int
223 octave_link (const std::string& old_name, const std::string& new_name,
224  std::string& msg)
225 {
226  return octave::sys::link (old_name, new_name, msg);
227 }
228 
229 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::symlink' instead")
230 inline int
231 octave_symlink (const std::string& old_name, const std::string& new_name)
232 {
233  return octave::sys::symlink (old_name, new_name);
234 }
235 
236 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::symlink' instead")
237 inline int
238 octave_symlink (const std::string& old_name, const std::string& new_name,
239  std::string& msg)
240 {
241  return octave::sys::symlink (old_name, new_name, msg);
242 }
243 
244 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::readlink' instead")
245 inline int
246 octave_readlink (const std::string& path, std::string& result)
247 {
248  return octave::sys::readlink (path, result);
249 }
250 
251 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::readlink' instead")
252 inline int
253 octave_readlink (const std::string& path, std::string& result, std::string& msg)
254 {
255  return octave::sys::readlink (path, result, msg);
256 }
257 
258 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::rename' instead")
259 inline int
260 octave_rename (const std::string& from, const std::string& to)
261 {
262  return octave::sys::rename (from, to);
263 }
264 
265 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::rename' instead")
266 inline int
267 octave_rename (const std::string& from, const std::string& to, std::string& msg)
268 {
269  return octave::sys::rename (from, to, msg);
270 }
271 
272 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::rmdir' instead")
273 inline int
274 octave_rmdir (const std::string& nm)
275 {
276  return octave::sys::rmdir (nm);
277 }
278 
279 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::rmdir' instead")
280 inline int
281 octave_rmdir (const std::string& nm, std::string& msg)
282 {
283  return octave::sys::rmdir (nm, msg);
284 }
285 
286 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::recursive_rmdir' instead")
287 inline int
288 octave_recursive_rmdir (const std::string& nm)
289 {
291 }
292 
293 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::recursive_rmdir' instead")
294 inline int
295 octave_recursive_rmdir (const std::string& nm, std::string& msg)
296 {
297  return octave::sys::recursive_rmdir (nm, msg);
298 }
299 
300 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::umask' instead")
301 inline int
302 octave_umask (mode_t md)
303 {
304  return octave::sys::umask (md);
305 }
306 
307 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::unlink' instead")
308 inline int
309 octave_unlink (const std::string& nm)
310 {
311  return octave::sys::unlink (nm);
312 }
313 
314 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::unlink' instead")
315 inline int
316 octave_unlink (const std::string& nm, std::string& msg)
317 {
318  return octave::sys::unlink (nm, msg);
319 }
320 
321 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::tempnam' instead")
322 inline std::string
323 octave_tempnam (const std::string& dir, const std::string& pfx)
324 {
325  return octave::sys::tempnam (dir, pfx);
326 }
327 
328 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::tempnam' instead")
329 inline std::string
330 octave_tempnam (const std::string& dir, const std::string& pfx,
331  std::string& msg)
332 {
333  return octave::sys::tempnam (dir, pfx, msg);
334 }
335 
336 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::canonicalize_file_name' instead")
337 inline std::string
338 octave_canonicalize_file_name (const std::string& nm)
339 {
341 }
342 
343 OCTAVE_DEPRECATED (4.2, "use 'octave::sys::canonicalize_file_name' instead")
344 inline std::string
345 octave_canonicalize_file_name (const std::string& nm, std::string& msg)
346 {
348 }
349 
350 #endif
351 
352 #endif
bool is_dev_sep(char c)
Definition: file-ops.cc:259
std::string canonicalize_file_name(const std::string &name)
Definition: file-ops.cc:685
int unlink(const std::string &name)
Definition: file-ops.cc:618
std::string dir_sep_chars(void)
Definition: file-ops.cc:242
int symlink(const std::string &old_name, const std::string &new_name)
Definition: file-ops.cc:451
std::string tempnam(const std::string &dir, const std::string &pfx)
Definition: file-ops.cc:638
std::string tail(const std::string &path)
Definition: file-ops.cc:360
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:276
std::string native_separator_path(const std::string &path)
Definition: file-ops.cc:372
STL namespace.
char dir_sep_char(void)
Definition: file-ops.cc:224
std::string dirname(const std::string &path)
Definition: file-ops.cc:353
string_vector tilde_additional_prefixes
Definition: file-ops.cc:255
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
tilde_expansion_hook tilde_expansion_failure_hook
Definition: file-ops.cc:253
std::string dir_sep_str(void)
Definition: file-ops.cc:233
int recursive_rmdir(const std::string &name)
Definition: file-ops.cc:540
int rename(const std::string &from, const std::string &to)
Definition: file-ops.cc:498
string_vector tilde_additional_suffixes
Definition: file-ops.cc:257
std::string concat(const std::string &dir, const std::string &file)
Definition: file-ops.cc:344
bool is_dir_sep(char c)
Definition: file-ops.cc:270
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:975
int link(const std::string &old_name, const std::string &new_name)
Definition: file-ops.cc:430
With real return the complex result
Definition: data.cc:3260
int umask(mode_t mode)
Definition: file-ops.cc:613
tilde_expansion_hook tilde_expansion_preexpansion_hook
Definition: file-ops.cc:251
int mkdir(const std::string &nm, mode_t md)
Definition: file-ops.cc:394
int rmdir(const std::string &name)
Definition: file-ops.cc:518
std::string(* tilde_expansion_hook)(const std::string &)
Definition: file-ops.h:40
int readlink(const std::string &path, std::string &result)
Definition: file-ops.cc:472
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
char dev_sep_char(void)
Definition: file-ops.cc:215
int mkfifo(const std::string &nm, mode_t md)
Definition: file-ops.cc:412