Mercurial > hg > octave-terminal
changeset 10250:2d47356a7a1a
use gnulib getcwd module
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2010 03:07:06 -0500 |
parents | 14eba566f9f0 |
children | 28e5a5f826bc |
files | ChangeLog bootstrap.conf configure.ac liboctave/ChangeLog liboctave/cmd-edit.cc liboctave/file-ops.cc liboctave/lo-sysdep.cc liboctave/oct-env.cc liboctave/oct-env.h src/ChangeLog src/DLD-FUNCTIONS/md5sum.cc src/DLD-FUNCTIONS/urlwrite.cc src/dirfns.cc src/file-io.cc src/load-path.cc src/load-save.cc src/ls-mat5.cc src/oct-parse.yy src/octave.cc src/ov-fcn-handle.cc src/utils.cc |
diffstat | 21 files changed, 86 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * configure.ac: Don't check for getcwd. + * bootstrap.conf (gnulib_modules): Include getcwd in the list. + 2010-02-02 John W. Eaton <jwe@octave.org> * configure.ac: Assume signal.h provides sigset_t and sig_atomic_t.
--- a/bootstrap.conf +++ b/bootstrap.conf @@ -21,6 +21,7 @@ c-strcase crypto/md5 fnmatch + getcwd getopt-gnu gettimeofday glob
--- a/configure.ac +++ b/configure.ac @@ -1489,7 +1489,7 @@ ### Checks for functions and variables. AC_CHECK_FUNCS(basename canonicalize_file_name \ - chmod dup2 endgrent endpwent execvp expm1 expm1f fcntl fork getcwd \ + chmod dup2 endgrent endpwent execvp expm1 expm1f fcntl fork \ getegid geteuid getgid getgrent getgrgid getgrnam getpgrp getpid \ getppid getpwent getpwuid getuid getwd _kbhit kill \ lgamma lgammaf lgamma_r lgammaf_r localtime_r log1p log1pf \
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,16 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * file-ops.cc (canonicalize_file_name): + Don't pass current directory to octave_env::make_absolute. + * cmd-edit.cc (do_decode_prompt_string): Likewise. + + * oct-env.h (octave_env::get_current_directory): + Rename from octave_env::getcwd. + (octave_env::make_absolute): Provide default value for second arg. + + * lo-sysdep.cc (octave_getcwd): Assume we are using gnulib + getcwd module. + 2010-02-02 John W. Eaton <jwe@octave.org> * oct-time.h: Include <ctime>, not "systime.h".
--- a/liboctave/cmd-edit.cc +++ b/liboctave/cmd-edit.cc @@ -1386,7 +1386,7 @@ case 'w': case 'W': { - temp = octave_env::getcwd (); + temp = octave_env::get_current_directory (); std::string home_dir = octave_env::get_home_directory ();
--- a/liboctave/file-ops.cc +++ b/liboctave/file-ops.cc @@ -403,8 +403,7 @@ // 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 ()); + std::string absolute_name = octave_env::make_absolute (name); size_t resolved_size = absolute_name.length ();
--- a/liboctave/lo-sysdep.cc +++ b/liboctave/lo-sysdep.cc @@ -55,20 +55,17 @@ { std::string retval; - char buf[MAXPATHLEN]; - - char *tmp = 0; + // Using the gnulib getcwd module ensures that we have a getcwd that + // will allocate a buffer as large as necessary if buf and size are + // both 0. -#if defined (__EMX__) - tmp = _getcwd2 (buf, MAXPATHLEN); -#elif defined (HAVE_GETCWD) - tmp = getcwd (buf, MAXPATHLEN); -#elif defined (HAVE_GETWD) - tmp = getwd (buf); -#endif + char *tmp = getcwd (0, 0); if (tmp) - retval = tmp; + { + retval = tmp; + free (tmp); + } else (*current_liboctave_error_handler) ("unable to find current directory");
--- a/liboctave/oct-env.cc +++ b/liboctave/oct-env.cc @@ -129,7 +129,7 @@ } std::string -octave_env::getcwd () +octave_env::get_current_directory () { return (instance_ok ()) ? instance->do_getcwd () : std::string ();
--- a/liboctave/oct-env.h +++ b/liboctave/oct-env.h @@ -43,10 +43,11 @@ static std::string base_pathname (const std::string& s); - static std::string make_absolute (const std::string& s, - const std::string& dot_path); + static std::string + make_absolute (const std::string& s, + const std::string& dot_path = get_current_directory ()); - static std::string getcwd (void); + static std::string get_current_directory (void); static std::string get_home_directory (void);
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,24 @@ +2010-02-03 John W. Eaton <jwe@octave.org> + + * dirfns.cc (Fpwd): Call octave_env::get_current_directory, not + octave_env::getcwd. + + * utils.cc (search_path_for_file, search_path_for_all_files, + make_absolute, Ffile_in_loadpath, Ffile_in_path, file_in_path, + contents_file_in_path, Fmake_absolute_filename): + Don't pass current directory to octave_env::make_absolute. + * ov-fcn-handle.cc (octave_fcn_handle::set_fcn): Likewise. + * octave.cc (execute_startup_files): Likewise. + * ls-mat5.cc (read_mat5_binary_element): Likewise. + * load-save.cc (find_file_to_load): Likewise. + * load-path.cc (load_path::dir_info::update, + load_path::dir_info::initialize, load_path::do_find_dir, + load_path::do_find_matching_dirs): Likewise. + * file-io.cc (do_stream_open): Likewise. + * oct-parse.yy (load_fcn_from_file, Fautoload): Likewise. + * DLD-FUNCTIONS/md5sum.cc (Fmd5sum): Likewise. + * DLD-FUNCTIONS/urlwrite.cc (Furlwrite): Likewise. + 2010-02-02 John W. Eaton <jwe@octave.org> * syscalls.cc (Fcanonicalize_file_name): Use DEFUNX instead of DEFUN.
--- a/src/DLD-FUNCTIONS/md5sum.cc +++ b/src/DLD-FUNCTIONS/md5sum.cc @@ -68,8 +68,8 @@ if (! fs.exists ()) { - std::string tmp = octave_env::make_absolute - (load_path::find_file (str), octave_env::getcwd ()); + std::string tmp + = octave_env::make_absolute (load_path::find_file (str)); if (! tmp.empty ()) {
--- a/src/DLD-FUNCTIONS/urlwrite.cc +++ b/src/DLD-FUNCTIONS/urlwrite.cc @@ -825,7 +825,7 @@ { retval(2) = std::string (); retval(1) = true; - retval(0) = octave_env::make_absolute (filename, octave_env::getcwd ()); + retval(0) = octave_env::make_absolute (filename); } else {
--- a/src/dirfns.cc +++ b/src/dirfns.cc @@ -150,7 +150,7 @@ @seealso{dir, ls}\n\ @end deftypefn") { - return octave_value (octave_env::getcwd ()); + return octave_value (octave_env::get_current_directory ()); } DEFUN (readdir, args, ,
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -460,8 +460,8 @@ { if (! fs.exists ()) { - std::string tmp = octave_env::make_absolute - (load_path::find_file (fname), octave_env::getcwd ()); + std::string tmp + = octave_env::make_absolute (load_path::find_file (fname)); if (! tmp.empty ()) {
--- a/src/load-path.cc +++ b/src/load-path.cc @@ -60,8 +60,7 @@ { try { - std::string abs_name - = octave_env::make_absolute (dir_name, octave_env::getcwd ()); + std::string abs_name = octave_env::make_absolute (dir_name); abs_dir_cache_iterator p = abs_dir_cache.find (abs_name); @@ -124,8 +123,7 @@ try { - std::string abs_name - = octave_env::make_absolute (dir_name, octave_env::getcwd ()); + std::string abs_name = octave_env::make_absolute (dir_name); // FIXME -- nothing is ever removed from this cache of // directory information, so there could be some resource @@ -1170,8 +1168,7 @@ p != dir_info_list.end (); p++) { - std::string dname - = octave_env::make_absolute (p->dir_name, octave_env::getcwd ()); + std::string dname = octave_env::make_absolute (p->dir_name); size_t dname_len = dname.length (); @@ -1218,8 +1215,7 @@ p != dir_info_list.end (); p++) { - std::string dname - = octave_env::make_absolute (p->dir_name, octave_env::getcwd ()); + std::string dname = octave_env::make_absolute (p->dir_name); size_t dname_len = dname.length ();
--- a/src/load-save.cc +++ b/src/load-save.cc @@ -489,8 +489,8 @@ if (! (fs.exists () && fs.is_reg ())) { - std::string tmp = octave_env::make_absolute - (load_path::find_file (fname), octave_env::getcwd ()); + std::string tmp + = octave_env::make_absolute (load_path::find_file (fname)); if (! tmp.empty ()) {
--- a/src/ls-mat5.cc +++ b/src/ls-mat5.cc @@ -804,8 +804,7 @@ dir_path p (load_path::system_path ()); - str = octave_env::make_absolute - (p.find_first_of (names), octave_env::getcwd ()); + str = octave_env::make_absolute (p.find_first_of (names)); size_t xpos = str.find_last_of (file_ops::dir_sep_chars ());
--- a/src/oct-parse.yy +++ b/src/oct-parse.yy @@ -3702,7 +3702,7 @@ fcn_file_from_relative_lookup = ! octave_env::absolute_pathname (file); - file = octave_env::make_absolute (file, octave_env::getcwd ()); + file = octave_env::make_absolute (file); int len = file.length (); @@ -3822,7 +3822,7 @@ if (! fname.empty ()) { - fname = octave_env::make_absolute (fname, octave_env::getcwd ()); + fname = octave_env::make_absolute (fname); fname = fname.substr (0, fname.find_last_of (file_ops::dir_sep_str ()) + 1); file_stat fs (fname + nm);
--- a/src/octave.cc +++ b/src/octave.cc @@ -335,9 +335,7 @@ // We want to check for curr_dir after executing home_rc // because doing that may change the working directory. - std::string curr_dir = octave_env::getcwd (); - - local_rc = octave_env::make_absolute (initfile, curr_dir); + local_rc = octave_env::make_absolute (initfile); home_rc_already_executed = same_file (home_rc, local_rc); } @@ -346,11 +344,7 @@ if (! home_rc_already_executed) { if (local_rc.empty ()) - { - std::string curr_dir = octave_env::getcwd (); - - local_rc = octave_env::make_absolute (initfile, curr_dir); - } + local_rc = octave_env::make_absolute (initfile); source_file (local_rc, context, verbose, require_file); }
--- a/src/ov-fcn-handle.cc +++ b/src/ov-fcn-handle.cc @@ -223,8 +223,7 @@ dir_path p (load_path::system_path ()); - str = octave_env::make_absolute - (p.find_first_of (names), octave_env::getcwd ()); + str = octave_env::make_absolute (p.find_first_of (names)); size_t xpos = str.find_last_of (file_ops::dir_sep_chars ());
--- a/src/utils.cc +++ b/src/utils.cc @@ -236,8 +236,7 @@ { dir_path p (path); - return octave_env::make_absolute (p.find_first_of (names), - octave_env::getcwd ()); + return octave_env::make_absolute (p.find_first_of (names)); } // Find all locations of the given file in the path. @@ -252,7 +251,7 @@ octave_idx_type len = sv.length (); for (octave_idx_type i = 0; i < len; i++) - sv[i] = octave_env::make_absolute (sv[i], octave_env::getcwd ()); + sv[i] = octave_env::make_absolute (sv[i]); return sv; } @@ -265,7 +264,7 @@ string_vector retval (len); for (octave_idx_type i = 0; i < len; i++) - retval[i] = octave_env::make_absolute (sv[i], octave_env::getcwd ()); + retval[i] = octave_env::make_absolute (sv[i]); return retval; } @@ -301,8 +300,8 @@ { if (nargin == 1) { - std::string fname = octave_env::make_absolute - (load_path::find_first_of (names), octave_env::getcwd ()); + std::string fname + = octave_env::make_absolute (load_path::find_first_of (names)); if (fname.empty ()) retval = Matrix (); @@ -314,7 +313,8 @@ std::string opt = args(1).string_value (); if (! error_state && opt == "all") - retval = Cell (make_absolute (load_path::find_all_first_of (names))); + retval = Cell (make_absolute + (load_path::find_all_first_of (names))); else error ("file_in_loadpath: invalid option"); } @@ -382,7 +382,8 @@ std::string opt = args(2).string_value (); if (! error_state && opt == "all") - retval = Cell (make_absolute (search_path_for_all_files (path, names))); + retval = Cell (make_absolute + (search_path_for_all_files (path, names))); else error ("file_in_path: invalid option"); } @@ -407,8 +408,7 @@ if (! suffix.empty ()) nm.append (suffix); - return octave_env::make_absolute - (load_path::find_file (nm), octave_env::getcwd ()); + return octave_env::make_absolute (load_path::find_file (nm)); } // See if there is an function file in the path. If so, return the @@ -462,7 +462,7 @@ file_stat fs (tcontents); if (fs.exists ()) - retval = octave_env::make_absolute (tcontents, octave_env::getcwd ()); + retval = octave_env::make_absolute (tcontents); } return retval; @@ -786,7 +786,7 @@ std::string nm = args(0).string_value (); if (! error_state) - retval = octave_env::make_absolute (nm, octave_env::getcwd ()); + retval = octave_env::make_absolute (nm); else error ("make_absolute_filename: expecting argument to be a file name"); }