36 #include <sys/types.h>
40 #include "canonicalize.h"
62 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM))
63 char system_dir_sep_char =
'\\';
64 std::string system_dir_sep_str =
"\\";
66 char system_dir_sep_char =
'/';
67 std::string system_dir_sep_str =
"/";
69 #if defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM)
70 std::string system_dir_sep_chars =
"/\\";
72 std::string system_dir_sep_chars = system_dir_sep_str;
76 system_dir_sep_chars);
84 (*current_liboctave_error_handler)
85 (
"unable to create file_ops object!");
140 size_t s_len = s.length ();
142 if (s_len == 0 || s[0] ==
'~')
147 if (! prefixes.
empty ())
149 for (
size_t i = 0; i < s_len; i++)
151 for (
int j = 0; j < prefixes.
length (); j++)
153 size_t pfx_len = prefixes[j].
length ();
155 if (prefixes[j].compare (s.substr (i, pfx_len)) == 0)
173 size_t s_len = s.length ();
179 for ( ; i < s_len; i++)
184 if (! suffixes.
empty ())
186 for (
int j = 0; j < suffixes.
length (); j++)
188 size_t sfx_len = suffixes[j].
length ();
190 if (suffixes[j].compare (s.substr (i, sfx_len)) == 0)
204 size_t f_len = fname.length ();
211 return fname.substr (1, len);
220 size_t f_len = filename.length ();
222 if (f_len == 0 || filename[0] !=
'~')
234 size_t user_len = username.length ();
240 std::string expansion
243 if (! expansion.empty ())
244 return expansion + filename.substr (user_len+1);
259 std::string expansion
262 if (! expansion.empty ())
263 dirname = expansion + filename.substr (user_len+1);
269 if (dirname.length () == 0)
273 dirname = pw.
dir () + filename.substr (user_len+1);
284 if (name.find (
'~') == std::string::npos)
290 size_t name_len = name.length ();
307 result.append (name.substr (pos, start));
320 if (! (start || fini))
325 std::string tilde_word = name.substr (pos, fini);
331 result.append (expansion);
349 for (
int i = 0; i < n; i++)
376 msg = std::string ();
380 status = gnulib::mkdir (name.c_str (), mode);
383 msg = gnulib::strerror (errno);
398 msg = std::string ();
406 status = gnulib::mkfifo (name.c_str (), mode);
409 msg = gnulib::strerror (errno);
415 octave_link (
const std::string& old_name,
const std::string& new_name)
423 const std::string& new_name, std::string& msg)
425 msg = std::string ();
429 status =
gnulib::link (old_name.c_str (), new_name.c_str ());
432 msg = gnulib::strerror (errno);
446 const std::string& new_name, std::string& msg)
448 msg = std::string ();
452 status = gnulib::symlink (old_name.c_str (), new_name.c_str ());
455 msg = gnulib::strerror (errno);
473 msg = std::string ();
477 status = gnulib::readlink (path.c_str (), buf,
MAXPATHLEN);
480 msg = gnulib::strerror (errno);
484 result = std::string (buf);
504 msg = std::string ();
506 status = gnulib::rename (from.c_str (), to.c_str ());
509 msg = gnulib::strerror (errno);
524 msg = std::string ();
528 status = gnulib::rmdir (name.c_str ());
531 msg = gnulib::strerror (errno);
548 msg = std::string ();
562 std::string nm = dirlist[i];
565 if (nm ==
"." || nm ==
"..")
616 #if defined (HAVE_UMASK)
633 msg = std::string ();
637 status = gnulib::unlink (name.c_str ());
640 msg = gnulib::strerror (errno);
656 msg = std::string ();
660 const char *pdir = dir.empty () ? 0 : dir.c_str ();
662 const char *ppfx = pfx.empty () ? 0 : pfx.c_str ();
664 char *tmp =
tempnam (pdir, ppfx);
673 msg = gnulib::strerror (errno);
688 msg = std::string ();
692 #if defined (HAVE_CANONICALIZE_FILE_NAME)
694 char *tmp = gnulib::canonicalize_file_name (name.c_str ());
702 #elif defined (HAVE_RESOLVEPATH)
708 #if !defined (__set_errno)
709 # define __set_errno(Val) errno = (Val)
714 __set_errno (ENOENT);
724 size_t resolved_size = absolute_name.length ();
728 resolved_size = 2 * resolved_size + 1;
733 = resolvepath (absolute_name.c_str (), resolved, resolved_size);
735 if (resolved_len < 0)
738 if (resolved_len < resolved_size)
745 #elif defined (__WIN32__)
749 std::string win_path (n,
'\0');
753 int status = GetFullPathName (name.c_str (), n, &win_path[0], 0);
759 win_path.resize (status);
770 #elif defined (HAVE_REALPATH)
772 #if !defined (__set_errno)
773 # define __set_errno(Val) errno = (Val)
778 __set_errno (ENOENT);
784 if (::realpath (name.c_str (), buf))
795 msg = gnulib::strerror (errno);