On 18-Jan-2007, Alexander Barth wrote:
| On my system (Linux), it returns an absolute filename (which I think
| is the correct behavior, or not?). I think this is the problem which
| prevents you to install packages with relative filenames.
The function that is eventually called to perform this task is
file_ops::canonicalize_file_name, which is defined in
liboctave/file-ops.cc. Here it is:
std::string
file_ops::canonicalize_file_name (const std::string& name, std::string& msg)
{
msg = std::string ();
std::string retval;
#if defined (HAVE_CANONICALIZE_FILE_NAME)
char *tmp = ::canonicalize_file_name (name.c_str ());
if (tmp)
{
retval = tmp;
::free (tmp);
}
#elif defined (HAVE_RESOLVEPATH)
#if !defined (errno)
extern int errno;
#endif
#if !defined (__set_errno)
# define __set_errno(Val) errno = (Val)
#endif
if (name.empty ())
{
__set_errno (ENOENT);
return retval;
}
// All known hosts with resolvepath (e.g. Solaris 7) don't turn
// relative names into absolute ones, so prepend the working
// directory if the path is not absolute.
std::string absolute_name
= octave_env::make_absolute (name, octave_env::getcwd ());
size_t resolved_size = absolute_name.length ();
while (true)
{
resolved_size = 2 * resolved_size + 1;
OCTAVE_LOCAL_BUFFER (char, resolved, resolved_size);
int resolved_len
= ::resolvepath (absolute_name.c_str (), resolved, resolved_size);
if (resolved_len < 0)
break;
if (resolved_len < resolved_size)
{
retval = resolved;
break;
}
}
#elif defined (__WIN32__)
int n = 1024;
std::string win_path (n, '\0');
while (true)
{
int status = GetFullPathName (name.c_str (), n, &win_path[0], NULL);
if (status == 0)
break;
else if (status < n)
{
win_path.resize (status);
retval = win_path;
break;
}
else
{
n *= 2;
win_path.resize (n);
}
}
#else
// FIXME -- provide replacement here...
retval = name;
#endif
if (retval.empty ())
{
using namespace std;
msg = ::strerror (errno);
}
return retval;
}
I suspect you are ending up in the FIXME part. So I think if people
want this to work, someone needs to write the code for systems that
are note Windows and that also are missing either the
canonicalize_file_name or resolvepath functions.
I see that an implementation of canonicalize_file_name is in gnulib,
so that might be a good place to start. I see that it also uses
resolvepath if that is available, so we could do away with a good
portion of our implementation above if we used the code from gnulib.
There are other functions in gnulib that would probably be useful for
Octave, so coming up with a clean way to use gnulib sources in Octave
would be useful.
Thanks,
jwe