36 #include <sys/types.h>
40 #include "canonicalize.h"
66 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
67 char system_dir_sep_char =
'\\';
68 std::string system_dir_sep_str =
"\\";
70 char system_dir_sep_char =
'/';
71 std::string system_dir_sep_str =
"/";
73 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
74 std::string system_dir_sep_chars =
"/\\";
76 std::string system_dir_sep_chars = system_dir_sep_str;
80 system_dir_sep_chars);
88 (*current_liboctave_error_handler)
89 (
"unable to create file_ops object!");
144 size_t s_len = s.length ();
146 if (s_len == 0 || s[0] ==
'~')
151 if (! prefixes.
empty ())
153 for (
size_t i = 0; i < s_len; i++)
155 for (
int j = 0; j < prefixes.
length (); j++)
157 size_t pfx_len = prefixes[j].
length ();
159 if (prefixes[j].compare (s.substr (i, pfx_len)) == 0)
177 size_t s_len = s.length ();
183 for ( ; i < s_len; i++)
188 if (! suffixes.
empty ())
190 for (
int j = 0; j < suffixes.
length (); j++)
192 size_t sfx_len = suffixes[j].
length ();
194 if (suffixes[j].compare (s.substr (i, sfx_len)) == 0)
208 size_t f_len = fname.length ();
215 return fname.substr (1, len);
224 size_t f_len = filename.length ();
226 if (f_len == 0 || filename[0] !=
'~')
238 size_t user_len = username.length ();
244 std::string expansion
247 if (! expansion.empty ())
248 return expansion + filename.substr (user_len+1);
263 std::string expansion
266 if (! expansion.empty ())
267 dirname = expansion + filename.substr (user_len+1);
273 if (dirname.length () == 0)
277 dirname = pw.
dir () + filename.substr (user_len+1);
288 if (name.find (
'~') == std::string::npos)
294 size_t name_len = name.length ();
311 result.append (name.substr (pos, start));
324 if (! (start || fini))
329 std::string tilde_word = name.substr (pos, fini);
335 result.append (expansion);
353 for (
int i = 0; i < n; i++)
378 size_t n = path.length ();
379 for (
size_t i = 0; i < n; i++)
401 msg = std::string ();
405 status = gnulib::mkdir (name.c_str (), mode);
408 msg = gnulib::strerror (errno);
423 msg = std::string ();
431 status = gnulib::mkfifo (name.c_str (), mode);
434 msg = gnulib::strerror (errno);
440 octave_link (
const std::string& old_name,
const std::string& new_name)
448 const std::string& new_name, std::string& msg)
450 msg = std::string ();
454 status =
gnulib::link (old_name.c_str (), new_name.c_str ());
457 msg = gnulib::strerror (errno);
471 const std::string& new_name, std::string& msg)
473 msg = std::string ();
477 status = gnulib::symlink (old_name.c_str (), new_name.c_str ());
480 msg = gnulib::strerror (errno);
498 msg = std::string ();
502 status = gnulib::readlink (path.c_str (), buf,
MAXPATHLEN);
505 msg = gnulib::strerror (errno);
509 result = std::string (buf);
529 msg = std::string ();
531 status = gnulib::rename (from.c_str (), to.c_str ());
534 msg = gnulib::strerror (errno);
549 msg = std::string ();
553 status = gnulib::rmdir (name.c_str ());
556 msg = gnulib::strerror (errno);
573 msg = std::string ();
587 std::string nm = dirlist[i];
590 if (nm ==
"." || nm ==
"..")
641 #if defined (HAVE_UMASK)
658 msg = std::string ();
662 status = gnulib::unlink (name.c_str ());
665 msg = gnulib::strerror (errno);
681 msg = std::string ();
686 std::string templatename;
699 templatename +=
"file";
704 templatename +=
"XXXXXX";
707 char tname [templatename.length () + 1];
709 strcpy (tname, templatename.c_str ());
711 if (gen_tempname (tname, 0, 0, GT_NOCREATE) == -1)
712 msg = gnulib::strerror (errno);
729 msg = std::string ();
733 char *tmp = gnulib::canonicalize_file_name (name.c_str ());
742 msg = gnulib::strerror (errno);
int octave_unlink(const std::string &name)
int octave_rename(const std::string &from, const std::string &to)
std::string error(void) const
static tilde_expansion_hook tilde_expansion_preexpansion_hook
static std::string native_separator_path(const std::string &path)
int octave_mkfifo(const std::string &nm, mode_t md)
static size_t tilde_find_suffix(const std::string &s)
int octave_symlink(const std::string &old_name, const std::string &new_name)
int octave_link(const std::string &old_name, const std::string &new_name)
static string_vector names(const map_type &lst)
int octave_mkdir(const std::string &nm, mode_t md)
std::string dir(void) const
static std::string tilde_expand(const std::string &)
static octave_idx_type link(octave_idx_type s, octave_idx_type t, octave_idx_type *pp)
static std::string concat(const std::string &, const std::string &)
static tilde_expansion_hook tilde_expansion_failure_hook
static const char * default_suffixes[]
void resize(octave_idx_type n, const std::string &rfv=std::string())
static const char * default_prefixes[]
static size_t tilde_find_prefix(const std::string &s, size_t &len)
static std::string tilde_expand_word(const std::string &filename)
static void cleanup_instance(void)
static file_ops * instance
std::string octave_canonicalize_file_name(const std::string &name)
static std::string isolate_tilde_prefix(const std::string &fname)
static string_vector tilde_additional_suffixes
int octave_readlink(const std::string &path, std::string &result)
int octave_umask(mode_t mode)
std::string error(void) const
octave_idx_type length(void) const
Number of elements in the array.
std::string(* tilde_expansion_hook)(const std::string &)
static string_vector tilde_additional_prefixes
static bool is_dir_sep(char c)
int octave_rmdir(const std::string &name)
static bool instance_ok(void)
static std::string dir_sep_str(void)
static octave_passwd getpwnam(const std::string &nm)
static std::string get_temp_directory(void)
std::string octave_tempnam(const std::string &dir, const std::string &pfx)
int octave_recursive_rmdir(const std::string &name)
file_ops(char dir_sep_char_arg=0, const std::string &dir_sep_str_arg=std::string("/"), const std::string &dir_sep_chars_arg=std::string("/"))
static char dir_sep_char(void)
static std::string get_home_directory(void)