26 #if defined (HAVE_CONFIG_H)
37 #if defined (OCTAVE_USE_WINDOWS_API)
42 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
83 size_t s_len = s.length ();
85 if (s_len == 0 || s[0] ==
'~')
90 if (! prefixes.
empty ())
92 for (
size_t i = 0; i < s_len; i++)
94 for (
int j = 0; j < prefixes.
numel (); j++)
96 size_t pfx_len = prefixes[j].length ();
98 if (prefixes[j] == s.substr (i, pfx_len))
116 size_t s_len = s.length ();
122 for ( ; i < s_len; i++)
127 if (! suffixes.
empty ())
129 for (
int j = 0; j < suffixes.
numel (); j++)
131 size_t sfx_len = suffixes[j].length ();
133 if (suffixes[j] == s.substr (i, sfx_len))
147 size_t f_len = fname.length ();
154 return fname.substr (1,
len);
163 size_t f_len = filename.length ();
165 if (f_len == 0 || filename[0] !=
'~')
166 return std::string (filename);
177 size_t user_len = username.length ();
183 std::string expansion
186 if (! expansion.empty ())
187 return expansion + filename.substr (user_len+1);
202 std::string expansion
205 if (! expansion.empty ())
206 dirname = expansion + filename.substr (user_len+1);
216 dirname = pw.
dir () + filename.substr (user_len+1);
227 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
236 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
245 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
254 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
271 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
274 octave_unused_parameter (c);
283 return tmp.find (c) != std::string::npos;
288 if (
name.find (
'~') == std::string::npos)
289 return std::string (
name);
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);
348 for (
int i = 0; i <
n; i++)
354 std::string
concat (
const std::string& dir,
const std::string& file)
367 return (ipos != std::string::npos) ?
path.substr (0, ipos) :
"";
374 if (ipos != std::string::npos)
379 return path.substr (ipos);
390 size_t n =
path.length ();
391 for (
size_t i = 0; i <
n; i++)
404 int mkdir (
const std::string& nm, mode_t md)
407 return mkdir (nm, md, msg);
410 int mkdir (
const std::string&
name, mode_t mode, std::string& msg)
417 msg = std::strerror (errno);
422 int mkfifo (
const std::string& nm, mode_t md)
425 return mkfifo (nm, md, msg);
428 int mkfifo (
const std::string&
name, mode_t mode, std::string& msg)
435 msg = std::strerror (errno);
440 int link (
const std::string& old_name,
const std::string& new_name)
443 return link (old_name, new_name, msg);
446 int link (
const std::string& old_name,
const std::string& new_name,
456 msg = std::strerror (errno);
461 int symlink (
const std::string& old_name,
const std::string& new_name)
464 return symlink (old_name, new_name, msg);
467 int symlink (
const std::string& old_name,
const std::string& new_name,
477 msg = std::strerror (errno);
488 int readlink (
const std::string&
path, std::string& result, std::string& msg)
497 msg = std::strerror (errno);
508 int rename (
const std::string& from,
const std::string& to)
511 return rename (from, to, msg);
514 int rename (
const std::string& from,
const std::string& to,
521 #if defined (OCTAVE_USE_WINDOWS_API)
524 status = _wrename (wfrom.c_str (), wto.c_str ());
530 msg = std::strerror (errno);
550 msg = std::strerror (errno);
577 std::string nm = dirlist[i];
580 if (nm ==
"." || nm ==
"..")
599 status =
unlink (fullnm, msg);
641 msg = std::strerror (errno);
646 std::string
tempnam (
const std::string& dir,
const std::string& pfx)
649 return tempnam (dir, pfx, msg);
652 std::string
tempnam (
const std::string& dir,
const std::string& pfx,
660 std::string templatename;
663 else if (!
file_stat (dir,
false).is_dir ())
673 templatename +=
"file";
678 templatename +=
"XXXXXX";
681 char tname [templatename.length () + 1];
683 strcpy (tname, templatename.c_str ());
686 msg = std::strerror (errno);
705 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
715 const uint8_t *name_u8 =
reinterpret_cast<const uint8_t *
>
730 char *tmp =
reinterpret_cast<char *
>
753 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
755 std::replace (
retval.begin (),
retval.end (),
'/',
'\\');
758 #if defined (OCTAVE_USE_WINDOWS_API)
760 bool strip_marker =
true;
765 std::string name_backsl =
name;
766 std::replace (name_backsl.begin (), name_backsl.end (),
'/',
'\\');
767 if (name_backsl.compare (0, 2,
"\\\\") == 0)
770 strip_marker =
false;
771 wchar_t canon_path[MAX_PATH];
772 if (PathCanonicalizeW (canon_path, w_tmp.c_str ()))
773 w_tmp = std::wstring (canon_path);
779 if (! w_tmp.empty ())
791 wchar_t buffer[32767] = L
"";
792 int w_len = GetShortPathNameW (w_tmp.c_str (), buffer, 32767);
793 w_len = GetLongPathNameW (buffer, buffer, 32767);
807 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)
const char * octave_locale_charset_wrapper(void)
std::string dirname(const std::string &path)
string_vector tilde_additional_prefixes
string_vector tilde_additional_suffixes
tilde_expansion_hook tilde_expansion_preexpansion_hook
std::string(* tilde_expansion_hook)(const std::string &)
std::string dir_sep_str(void)
std::string native_separator_path(const std::string &path)
std::string tilde_expand(const std::string &name)
tilde_expansion_hook tilde_expansion_failure_hook
std::string concat(const std::string &dir, const std::string &file)
std::string dir_sep_chars(void)
std::string tail(const std::string &path)
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)
int rename(const std::string &from, const std::string &to)
int mkdir(const std::string &nm, mode_t md)
std::string u8_from_wstring(const std::wstring &wchar_string)
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)
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)
std::wstring u8_to_wstring(const std::string &utf8_string)
int rename(const std::string &from, const std::string &to, std::string &msg)
static std::string tilde_expand_word(const std::string &filename)
static const char * default_suffixes[]
static size_t tilde_find_suffix(const std::string &s)
static size_t tilde_find_prefix(const std::string &s, size_t &len)
static std::string isolate_tilde_prefix(const std::string &fname)
static const char * default_prefixes[]
T::size_type strlen(const typename T::value_type *str)
octave_value::octave_value(const Array< char > &chm, char type) return retval
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)
uint8_t * octave_u8_conv_from_encoding(const char *fromcode, const char *src, size_t srclen, size_t *lengthp)
char * octave_u8_conv_to_encoding(const char *tocode, const uint8_t *src, size_t srclen, size_t *lengthp)
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)