26#if defined (HAVE_CONFIG_H)
37#if defined (OCTAVE_USE_WINDOWS_API)
78 std::size_t s_len = s.length ();
80 if (s_len == 0 || s[0] ==
'~')
85 if (! prefixes.
empty ())
87 for (std::size_t i = 0; i < s_len; i++)
89 for (
int j = 0; j < prefixes.
numel (); j++)
91 std::size_t pfx_len = prefixes[j].length ();
93 if (prefixes[j] == s.substr (i, pfx_len))
111 std::size_t s_len = s.length ();
117 for ( ; i < s_len; i++)
122 if (! suffixes.
empty ())
124 for (
int j = 0; j < suffixes.
numel (); j++)
126 std::size_t sfx_len = suffixes[j].length ();
128 if (suffixes[j] == s.substr (i, sfx_len))
142 std::size_t f_len = fname.length ();
149 return fname.substr (1,
len);
158 std::size_t f_len = filename.length ();
160 if (f_len == 0 || filename[0] !=
'~')
161 return std::string (filename);
172 std::size_t user_len = username.length ();
178 std::string expansion
181 if (! expansion.empty ())
182 return expansion + filename.substr (user_len+1);
197 std::string expansion
200 if (! expansion.empty ())
201 dirname = expansion + filename.substr (user_len+1);
211 dirname = pw.
dir () + filename.substr (user_len+1);
222#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
231#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
240#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
249#if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
266#if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
269 octave_unused_parameter (c);
278 return tmp.find (c) != std::string::npos;
283 if (
name.find (
'~') == std::string::npos)
284 return std::string (
name);
289 std::size_t name_len =
name.length ();
306 result.append (
name.substr (pos, start));
319 if (! (start || fini))
324 std::string tilde_word =
name.substr (pos, fini);
330 result.append (expansion);
339 int n = names.
numel ();
343 for (
int i = 0; i < n; i++)
349 std::string
concat (
const std::string& dir,
const std::string& file)
362 return (ipos != std::string::npos) ?
path.substr (0, ipos) :
"";
369 if (ipos != std::string::npos)
374 return path.substr (ipos);
385 std::size_t n =
path.length ();
386 for (std::size_t i = 0; i < n; i++)
399 int mkdir (
const std::string& nm, mode_t md)
402 return mkdir (nm, md, msg);
405 int mkdir (
const std::string&
name, mode_t mode, std::string& msg)
412 msg = std::strerror (errno);
417 int mkfifo (
const std::string& nm, mode_t md)
420 return mkfifo (nm, md, msg);
423 int mkfifo (
const std::string&
name, mode_t mode, std::string& msg)
430 msg = std::strerror (errno);
435 int link (
const std::string& old_name,
const std::string& new_name)
438 return link (old_name, new_name, msg);
441 int link (
const std::string& old_name,
const std::string& new_name,
451 msg = std::strerror (errno);
456 int symlink (
const std::string& old_name,
const std::string& new_name)
459 return symlink (old_name, new_name, msg);
462 int symlink (
const std::string& old_name,
const std::string& new_name,
472 msg = std::strerror (errno);
483 int readlink (
const std::string&
path, std::string& result, std::string& msg)
492 msg = std::strerror (errno);
503 int rename (
const std::string& from,
const std::string& to)
506 return rename (from, to, msg);
509 int rename (
const std::string& from,
const std::string& to,
516#if defined (OCTAVE_USE_WINDOWS_API)
519 status = _wrename (wfrom.c_str (), wto.c_str ());
525 msg = std::strerror (errno);
545 msg = std::strerror (errno);
572 std::string nm = dirlist[i];
575 if (nm ==
"." || nm ==
"..")
594 status =
unlink (fullnm, msg);
636 msg = std::strerror (errno);
641 std::string
tempnam (
const std::string& dir,
const std::string& pfx)
644 return tempnam (dir, pfx, msg);
647 std::string
tempnam (
const std::string& dir,
const std::string& pfx,
655 std::string templatename;
658 else if (!
file_stat (dir,
false).is_dir ())
668 templatename +=
"file";
673 templatename +=
"XXXXXX";
676 char tname [templatename.length () + 1];
678 strcpy (tname, templatename.c_str ());
681 msg = std::strerror (errno);
703#if defined (OCTAVE_USE_WINDOWS_API)
706 HANDLE h_file = CreateFileW (wname.c_str (), GENERIC_READ,
707 FILE_SHARE_READ,
nullptr, OPEN_EXISTING,
708 FILE_FLAG_BACKUP_SEMANTICS,
nullptr);
710 if (h_file == INVALID_HANDLE_VALUE)
712 msg =
"Unable to open file \"" +
name +
"\"";
718 const std::size_t buf_size = 32767;
719 wchar_t buffer[buf_size] = L
"";
722 DWORD
len = GetFinalPathNameByHandleW (h_file, buffer, buf_size,
723 FILE_NAME_NORMALIZED);
726 msg =
"Error querying normalized name for \"" +
name +
"\"";
735 if (retval.compare (0, 8, R
"(\\?\UNC\)") == 0)
736 retval = retval.erase (2, 6);
737 else if (retval.compare (0, 4, R
"(\\?\)") == 0)
738 retval = retval.erase (0, 4);
749 msg = std::strerror (errno);
char * octave_areadlink_wrapper(const char *name)
char * octave_canonicalize_file_name_wrapper(const char *name)
std::string error(void) const
static std::string get_temp_directory(void)
static std::string get_home_directory(void)
std::string dir(void) const
static password getpwnam(const std::string &nm)
octave_idx_type numel(void) const
int octave_gen_tempname_wrapper(char *tmpl)
std::string native_separator_path(const std::string &path)
string_vector tilde_additional_suffixes
tilde_expansion_hook tilde_expansion_failure_hook
std::string concat(const std::string &dir, const std::string &file)
std::string dirname(const std::string &path)
std::string(* tilde_expansion_hook)(const std::string &)
std::string tilde_expand(const std::string &name)
std::string dir_sep_chars(void)
std::string dir_sep_str(void)
tilde_expansion_hook tilde_expansion_preexpansion_hook
std::string tail(const std::string &path)
string_vector tilde_additional_prefixes
int link(const std::string &old_name, const std::string &new_name)
std::string tempnam(const std::string &dir, const std::string &pfx)
int readlink(const std::string &path, std::string &result)
std::string canonicalize_file_name(const std::string &name)
std::string u8_from_wstring(const std::wstring &wchar_string)
int rename(const std::string &from, const std::string &to)
int mkdir(const std::string &nm, mode_t md)
int symlink(const std::string &old_name, const std::string &new_name)
int rmdir(const std::string &name)
int recursive_rmdir(const std::string &name)
std::wstring u8_to_wstring(const std::string &utf8_string)
int unlink(const std::string &name)
int mkfifo(const std::string &nm, mode_t md)
bool get_dirlist(const std::string &dirname, string_vector &dirlist, std::string &msg)
int rename(const std::string &from, const std::string &to, std::string &msg)
static std::string tilde_expand_word(const std::string &filename)
static std::size_t tilde_find_suffix(const std::string &s)
static const char * default_suffixes[]
static std::size_t tilde_find_prefix(const std::string &s, std::size_t &len)
static std::string isolate_tilde_prefix(const std::string &fname)
static const char * default_prefixes[]
int octave_mkdir_wrapper(const char *name, mode_t mode)
int octave_mkfifo_wrapper(const char *name, mode_t mode)
int octave_umask_wrapper(mode_t mode)
int octave_rmdir_wrapper(const char *nm)
int octave_unlink_wrapper(const char *nm)
int octave_symlink_wrapper(const char *nm1, const char *nm2)
int octave_link_wrapper(const char *nm1, const char *nm2)