26 #if defined (HAVE_CONFIG_H)
37 #if defined (OCTAVE_USE_WINDOWS_API)
80 std::size_t s_len = s.length ();
82 if (s_len == 0 || s[0] ==
'~')
87 if (! prefixes.
empty ())
89 for (std::size_t i = 0; i < s_len; i++)
91 for (
int j = 0; j < prefixes.
numel (); j++)
93 std::size_t pfx_len = prefixes[j].length ();
95 if (prefixes[j] == s.substr (i, pfx_len))
113 std::size_t s_len = s.length ();
119 for ( ; i < s_len; i++)
124 if (! suffixes.
empty ())
126 for (
int j = 0; j < suffixes.
numel (); j++)
128 std::size_t sfx_len = suffixes[j].length ();
130 if (suffixes[j] == s.substr (i, sfx_len))
144 std::size_t f_len = fname.length ();
151 return fname.substr (1,
len);
160 std::size_t f_len = filename.length ();
162 if (f_len == 0 || filename[0] !=
'~')
163 return std::string (filename);
170 return sys::env::get_home_directory () + filename.substr (1);
174 std::size_t user_len = username.length ();
180 std::string expansion
183 if (! expansion.empty ())
184 return expansion + filename.substr (user_len+1);
190 sys::password pw = sys::password::getpwnam (username);
199 std::string expansion
202 if (! expansion.empty ())
203 dirname = expansion + filename.substr (user_len+1);
213 dirname = pw.dir () + filename.substr (user_len+1);
224 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
233 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
242 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
251 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
268 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
271 octave_unused_parameter (c);
280 return tmp.find (c) != std::string::npos;
285 if (name.find (
'~') == std::string::npos)
286 return std::string (name);
291 std::size_t name_len = name.length ();
308 result.append (name.substr (pos, start));
321 if (! (start || fini))
326 std::string tilde_word = name.substr (pos, fini);
332 result.append (expansion);
345 for (
int i = 0; i <
n; i++)
351 std::string
concat (
const std::string& dir,
const std::string& file)
364 return (ipos != std::string::npos) ? path.substr (0, ipos) :
"";
367 std::string
tail (
const std::string& path)
371 if (ipos != std::string::npos)
376 return path.substr (ipos);
387 std::size_t
n = path.length ();
388 for (std::size_t i = 0; i <
n; i++)
402 int
mkdir (const std::
string& nm, mode_t md)
405 return mkdir (nm, md, msg);
408 int mkdir (
const std::string& name, mode_t mode, std::string& msg)
415 msg = std::strerror (errno);
431 #if defined (OCTAVE_USE_WINDOWS_API)
433 std::size_t skip_root = 0;
434 if (name.size () > 1)
456 while (delim != std::string::npos)
458 std::string base = name.substr (0, delim);
459 sys::file_stat fs (base);
462 status =
mkdir (base, mode, msg);
470 return mkdir (name, mode, msg);
473 int mkfifo (
const std::string& nm, mode_t md)
476 return mkfifo (nm, md, msg);
479 int mkfifo (
const std::string& name, mode_t mode, std::string& msg)
486 msg = std::strerror (errno);
491 int link (
const std::string& old_name,
const std::string& new_name)
494 return link (old_name, new_name, msg);
497 int link (
const std::string& old_name,
const std::string& new_name,
507 msg = std::strerror (errno);
512 int symlink (
const std::string& old_name,
const std::string& new_name)
515 return symlink (old_name, new_name, msg);
518 int symlink (
const std::string& old_name,
const std::string& new_name,
528 msg = std::strerror (errno);
533 int readlink (
const std::string& path, std::string& result)
536 return readlink (path, result, msg);
539 int readlink (
const std::string& path, std::string& result, std::string& msg)
548 msg = std::strerror (errno);
559 int rename (
const std::string& from,
const std::string& to)
562 return rename (from, to, msg);
565 int rename (
const std::string& from,
const std::string& to,
572 #if defined (OCTAVE_USE_WINDOWS_API)
575 status = _wrename (wfrom.c_str (), wto.c_str ());
581 msg = std::strerror (errno);
589 return rmdir (name, msg);
592 int rmdir (
const std::string& name, std::string& msg)
601 msg = std::strerror (errno);
628 std::string nm = dirlist[i];
631 if (nm ==
"." || nm ==
"..")
650 status =
unlink (fullnm, msg);
664 status =
rmdir (name, msg);
680 return unlink (name, msg);
683 int unlink (
const std::string& name, std::string& msg)
692 msg = std::strerror (errno);
697 std::string
tempnam (
const std::string& dir,
const std::string& pfx)
700 return tempnam (dir, pfx, msg);
703 std::string
tempnam (
const std::string& dir,
const std::string& pfx,
711 std::string templatename;
714 else if (!
file_stat (dir,
false).is_dir ())
724 templatename +=
"file";
729 templatename +=
"XXXXXX";
732 char tname [templatename.length () + 1];
734 strcpy (tname, templatename.c_str ());
737 msg = std::strerror (errno);
759 #if defined (OCTAVE_USE_WINDOWS_API)
762 HANDLE h_file = CreateFileW (wname.c_str (), GENERIC_READ,
763 FILE_SHARE_READ,
nullptr, OPEN_EXISTING,
764 FILE_FLAG_BACKUP_SEMANTICS,
nullptr);
770 if (h_file == INVALID_HANDLE_VALUE)
771 h_file = CreateFileW (wname.c_str (), GENERIC_READ,
772 FILE_SHARE_READ,
nullptr, OPEN_EXISTING,
773 FILE_FLAG_BACKUP_SEMANTICS
774 | FILE_FLAG_OPEN_REPARSE_POINT,
nullptr);
776 if (h_file == INVALID_HANDLE_VALUE)
778 msg =
"Unable to open file \"" + name +
"\"";
784 const std::size_t buf_size = 32767;
785 wchar_t buffer[buf_size] = L
"";
788 DWORD
len = GetFinalPathNameByHandleW (h_file, buffer, buf_size,
789 FILE_NAME_NORMALIZED);
792 msg =
"Error querying normalized name for \"" + name +
"\"";
801 if (retval.compare (0, 8, R
"(\\?\UNC\)") == 0)
803 retval = retval.erase (2, 6);
807 if (name.size () < 3 || name[1] !=
':')
811 std::wstring orig_map = wname.substr (0, 3);
813 HANDLE h_map = CreateFileW (orig_map.c_str (), GENERIC_READ,
814 FILE_SHARE_READ,
nullptr, OPEN_EXISTING,
815 FILE_FLAG_BACKUP_SEMANTICS
816 | FILE_FLAG_OPEN_REPARSE_POINT,
819 if (h_map == INVALID_HANDLE_VALUE)
824 len = GetFinalPathNameByHandleW (h_map, buffer, buf_size,
825 FILE_NAME_NORMALIZED);
827 std::string orig_root
830 if (orig_root.compare (0, 8, R
"(\\?\UNC\)"))
834 orig_root = orig_root.erase (2, 6);
837 while (file_seps.find (orig_root.back ()) != std::string::npos)
838 orig_root.pop_back ();
840 if (retval.compare (0, orig_root.size (), orig_root))
845 size_t sep_pos = orig_root.size ();
846 if (sep_pos != retval.size ())
847 retval = retval.substr (sep_pos-2);
850 retval[0] = std::toupper (name[0]);
853 else if (retval.compare (0, 4, R
"(\\?\)") == 0)
854 retval = retval.erase (0, 4);
865 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)
octave_idx_type numel(void) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
int unlink(const std::string &name)
static std::size_t tilde_find_suffix(const std::string &s)
static std::string isolate_tilde_prefix(const std::string &fname)
int rename(const std::string &from, const std::string &to)
static const char * default_suffixes[]
static std::string tilde_expand_word(const std::string &filename)
int symlink(const std::string &old_name, const std::string &new_name)
std::string concat(const std::string &dir, const std::string &file)
std::string canonicalize_file_name(const std::string &name)
int readlink(const std::string &path, std::string &result)
std::string native_separator_path(const std::string &path)
string_vector tilde_additional_suffixes
int rmdir(const std::string &name)
static const char * default_prefixes[]
int mkfifo(const std::string &nm, mode_t md)
std::string tempnam(const std::string &dir, const std::string &pfx)
std::string dirname(const std::string &path)
tilde_expansion_hook tilde_expansion_failure_hook
std::string dir_sep_chars(void)
static std::size_t tilde_find_prefix(const std::string &s, std::size_t &len)
int link(const std::string &old_name, const std::string &new_name)
std::string dir_sep_str(void)
tilde_expansion_hook tilde_expansion_preexpansion_hook
int recursive_mkdir(const std::string &name, mode_t mode)
string_vector tilde_additional_prefixes
int recursive_rmdir(const std::string &name)
int mkdir(const std::string &nm, mode_t md)
std::string tilde_expand(const std::string &name)
std::string tail(const std::string &path)
std::string(* tilde_expansion_hook)(const std::string &)
int octave_gen_tempname_wrapper(char *tmpl)
std::string u8_from_wstring(const std::wstring &wchar_string)
std::wstring u8_to_wstring(const std::string &utf8_string)
bool get_dirlist(const std::string &dirname, string_vector &dirlist, std::string &msg)
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)