GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_file_ops_h)
27 #define octave_file_ops_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 #include <sys/types.h>
34 
35 #include "str-vec.h"
36 
37 namespace octave
38 {
39  namespace sys
40  {
41  namespace file_ops
42  {
43  typedef std::string (*tilde_expansion_hook) (const std::string&);
44 
45  // If non-null, this contains the address of a function that the
46  // application wants called before trying the standard tilde
47  // expansions. The function is called with the text sans tilde, and
48  // returns a malloc()'ed string which is the expansion, or a NULL
49  // pointer if the expansion fails.
50 
52 
53  // If non-null, this contains the address of a function to call if the
54  // standard meaning for expanding a tilde fails. The function is
55  // called with the text (sans tilde, as in "foo"), and returns a
56  // malloc()'ed string which is the expansion, or a NULL pointer if
57  // there is no expansion.
58 
60 
61  // When non-null, this is a NULL terminated array of strings which are
62  // duplicates for a tilde prefix. Bash uses this to expand '=~' and
63  // ':~'.
64 
66 
67  // When non-null, this is a NULL terminated array of strings which
68  // match the end of a username, instead of just "/". Bash sets this
69  // to ':' and '=~'.
70 
72 
73  // Find the start of a tilde expansion in S, and return the index
74  // of the tilde which starts the expansion. Place the length of the
75  // text which identified this tilde starter in LEN, excluding the
76  // tilde itself.
77 
78  char dev_sep_char (void);
79 
80  bool is_dev_sep (char c);
81 
82  char dir_sep_char (void);
83 
84  std::string dir_sep_str (void);
85 
86  std::string dir_sep_chars (void);
87 
88  bool is_dir_sep (char c);
89 
90  // If NAME has a leading ~ or ~user, Unix-style, expand it to the
91  // user's home directory. If no ~, or no <pwd.h>, just return NAME.
92 
93  std::string tilde_expand (const std::string&);
94 
95  // A vector version of the above.
96 
98 
99  std::string concat (const std::string&, const std::string&);
100 
101  // Return the directory part of a filename or an empty string if
102  // there is no directory component. Does not check to see
103  // whether the file exists or is a directory.
104 
105  std::string dirname (const std::string& path);
106 
107  // Return the tail member of a filename.
108 
109  std::string tail (const std::string& path);
110 
111  // convert path from UNIX type separators to whatever is the system separators
112 
113  std::string native_separator_path (const std::string& path);
114  }
115 
116  extern OCTAVE_API int
117  mkdir (const std::string&, mode_t);
118 
119  extern OCTAVE_API int
120  mkdir (const std::string&, mode_t, std::string&);
121 
122  extern OCTAVE_API int
123  mkfifo (const std::string&, mode_t);
124 
125  extern OCTAVE_API int
126  mkfifo (const std::string&, mode_t, std::string&);
127 
128  extern OCTAVE_API int
129  link (const std::string&, const std::string&);
130 
131  extern OCTAVE_API int
132  link (const std::string&, const std::string&, std::string&);
133 
134  extern OCTAVE_API int
135  symlink (const std::string&, const std::string&);
136 
137  extern OCTAVE_API int
138  symlink (const std::string&, const std::string&, std::string&);
139 
140  extern OCTAVE_API int
141  readlink (const std::string&, std::string&);
142 
143  extern OCTAVE_API int
144  readlink (const std::string&, std::string&, std::string&);
145 
146  extern OCTAVE_API int
147  rename (const std::string&, const std::string&);
148 
149  extern OCTAVE_API int
150  rename (const std::string&, const std::string&, std::string&);
151 
152  extern OCTAVE_API int
153  rmdir (const std::string&);
154 
155  extern OCTAVE_API int
156  rmdir (const std::string&, std::string&);
157 
158  extern OCTAVE_API int
159  recursive_rmdir (const std::string&);
160 
161  extern OCTAVE_API int
162  recursive_rmdir (const std::string&, std::string&);
163 
164  extern OCTAVE_API int
165  umask (mode_t);
166 
167  extern OCTAVE_API int
168  unlink (const std::string&);
169 
170  extern OCTAVE_API int
171  unlink (const std::string&, std::string&);
172 
173  extern OCTAVE_API std::string
174  tempnam (const std::string&, const std::string&);
175 
176  extern OCTAVE_API std::string
177  tempnam (const std::string&, const std::string&, std::string&);
178 
179  extern OCTAVE_API std::string
180  canonicalize_file_name (const std::string&);
181 
182  extern OCTAVE_API std::string
183  canonicalize_file_name (const std::string&, std::string&);
184  }
185 }
186 
187 #endif
QString path
std::string dirname(const std::string &path)
Definition: file-ops.cc:363
string_vector tilde_additional_prefixes
Definition: file-ops.cc:265
string_vector tilde_additional_suffixes
Definition: file-ops.cc:267
char dev_sep_char(void)
Definition: file-ops.cc:225
char dir_sep_char(void)
Definition: file-ops.cc:234
tilde_expansion_hook tilde_expansion_preexpansion_hook
Definition: file-ops.cc:261
std::string(* tilde_expansion_hook)(const std::string &)
Definition: file-ops.h:43
std::string dir_sep_str(void)
Definition: file-ops.cc:243
bool is_dir_sep(char c)
Definition: file-ops.cc:280
std::string native_separator_path(const std::string &path)
Definition: file-ops.cc:382
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:286
tilde_expansion_hook tilde_expansion_failure_hook
Definition: file-ops.cc:263
std::string concat(const std::string &dir, const std::string &file)
Definition: file-ops.cc:354
bool is_dev_sep(char c)
Definition: file-ops.cc:269
std::string dir_sep_chars(void)
Definition: file-ops.cc:252
std::string tail(const std::string &path)
Definition: file-ops.cc:370
int link(const std::string &old_name, const std::string &new_name)
Definition: file-ops.cc:440
std::string tempnam(const std::string &dir, const std::string &pfx)
Definition: file-ops.cc:646
int readlink(const std::string &path, std::string &result)
Definition: file-ops.cc:482
std::string canonicalize_file_name(const std::string &name)
Definition: file-ops.cc:693
int rename(const std::string &from, const std::string &to)
Definition: file-ops.cc:508
int mkdir(const std::string &nm, mode_t md)
Definition: file-ops.cc:404
int symlink(const std::string &old_name, const std::string &new_name)
Definition: file-ops.cc:461
int rmdir(const std::string &name)
Definition: file-ops.cc:535
int recursive_rmdir(const std::string &name)
Definition: file-ops.cc:557
int umask(mode_t mode)
Definition: file-ops.cc:621
int unlink(const std::string &name)
Definition: file-ops.cc:626
int mkfifo(const std::string &nm, mode_t md)
Definition: file-ops.cc:422