Mercurial > hg > octave-avbm
changeset 10252:2fcc927a8757
liboctave/file-ops.h: avoid gnulib #define for canonicalize_file_name
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 03:42:08 -0500 |
parents | 28e5a5f826bc |
children | 8cf32587d8f1 |
files | liboctave/ChangeLog liboctave/file-ops.cc liboctave/file-ops.h src/ChangeLog src/syscalls.cc |
diffstat | 5 files changed, 144 insertions(+), 130 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,8 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * file-ops.h (octave_canonicalize_file_name): Rename from + file_ops::canonicalize_file_name. + 2010-02-03 John W. Eaton <jwe@octave.org> * file-ops.cc (canonicalize_file_name):
--- a/liboctave/file-ops.cc +++ b/liboctave/file-ops.cc @@ -359,131 +359,6 @@ } -std::string -file_ops::canonicalize_file_name (const std::string& name) -{ - std::string msg; - return canonicalize_file_name (name, msg); -} - -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); - - 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], 0); - - if (status == 0) - break; - else if (status < n) - { - win_path.resize (status); - retval = win_path; - break; - } - else - { - n *= 2; - win_path.resize (n); - } - } - -#elif defined (HAVE_REALPATH) - -#if !defined (__set_errno) -# define __set_errno(Val) errno = (Val) -#endif - - if (name.empty ()) - { - __set_errno (ENOENT); - return retval; - } - - OCTAVE_LOCAL_BUFFER (char, buf, PATH_MAX); - - if (::realpath (name.c_str (), buf)) - retval = buf; - -#else - - // FIXME -- provide replacement here... - retval = name; - -#endif - - if (retval.empty ()) - { - using namespace std; - msg = strerror (errno); - } - - return retval; -} - int octave_mkdir (const std::string& nm, mode_t md) { @@ -822,3 +697,129 @@ return retval; } + +std::string +octave_canonicalize_file_name (const std::string& name) +{ + std::string msg; + return octave_canonicalize_file_name (name, msg); +} + +std::string +octave_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); + + 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], 0); + + if (status == 0) + break; + else if (status < n) + { + win_path.resize (status); + retval = win_path; + break; + } + else + { + n *= 2; + win_path.resize (n); + } + } + +#elif defined (HAVE_REALPATH) + +#if !defined (__set_errno) +# define __set_errno(Val) errno = (Val) +#endif + + if (name.empty ()) + { + __set_errno (ENOENT); + return retval; + } + + OCTAVE_LOCAL_BUFFER (char, buf, PATH_MAX); + + if (::realpath (name.c_str (), buf)) + retval = buf; + +#else + + // FIXME -- provide replacement here... + retval = name; + +#endif + + if (retval.empty ()) + { + using namespace std; + msg = strerror (errno); + } + + return retval; +} +
--- a/liboctave/file-ops.h +++ b/liboctave/file-ops.h @@ -95,10 +95,6 @@ return path.substr (ipos); } - static std::string canonicalize_file_name (const std::string&); - - static std::string canonicalize_file_name (const std::string&, std::string&); - private: static file_ops *instance; @@ -183,4 +179,10 @@ extern OCTAVE_API std::string octave_tempnam (const std::string&, const std::string&, std::string&); +extern OCTAVE_API std::string +octave_canonicalize_file_name (const std::string&); + +extern OCTAVE_API std::string +octave_canonicalize_file_name (const std::string&, std::string&); + #endif
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * syscalls.cc (Fcanonicalize_file_name): + Call octave_canonicalize_file_name instead of + file_ops::canonicalize_file_name. + 2010-02-03 John W. Eaton <jwe@octave.org> * dirfns.cc (Fpwd): Call octave_env::get_current_directory, not