# HG changeset patch # User John W. Eaton # Date 1463637004 14400 # Node ID a99c2407f930f669d67a5f44cd863fb180f2eb68 # Parent ab6c639f0678a6cc85e9adef4c99d396f93db4fb use namespace for lo-sysdep.h functions * lo-sysdep.h, lo-sysdep.cc: Put octave_getcwd, octave_chdir, and octave_popen2 in namespace octave::sys. Change all uses. diff -r ab6c639f0678 -r a99c2407f930 liboctave/system/lo-sysdep.cc --- a/liboctave/system/lo-sysdep.cc Thu May 19 01:33:06 2016 -0400 +++ b/liboctave/system/lo-sysdep.cc Thu May 19 01:50:04 2016 -0400 @@ -45,105 +45,111 @@ #include "str-vec.h" #include "oct-locbuf.h" -std::string -octave_getcwd (void) +namespace octave { - std::string retval; + namespace sys + { + std::string + getcwd (void) + { + std::string retval; - // 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. - - char *tmp = gnulib::getcwd (0, 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 (! tmp) - (*current_liboctave_error_handler) ("unable to find current directory"); + char *tmp = gnulib::getcwd (0, 0); - retval = tmp; - free (tmp); + if (! tmp) + (*current_liboctave_error_handler) ("unable to find current directory"); + + retval = tmp; + free (tmp); - return retval; -} + return retval; + } -int -octave_chdir (const std::string& path_arg) -{ - std::string path = octave::sys::file_ops::tilde_expand (path_arg); + int + chdir (const std::string& path_arg) + { + std::string path = octave::sys::file_ops::tilde_expand (path_arg); #if defined (__WIN32__) && ! defined (__CYGWIN__) - if (path.length () == 2 && path[1] == ':') - path += "\\"; + if (path.length () == 2 && path[1] == ':') + path += "\\"; #endif - return gnulib::chdir (path.c_str ()); -} + return gnulib::chdir (path.c_str ()); + } #if defined (__WIN32__) && ! defined (__CYGWIN__) -pid_t -octave_popen2 (const std::string& cmd, const string_vector& args, - bool sync_mode, - int *fildes, std::string& msg) -{ - pid_t pid; - PROCESS_INFORMATION pi; - STARTUPINFO si; - std::string command = "\"" + cmd + "\""; - HANDLE hProcess = GetCurrentProcess (); - HANDLE childRead, childWrite, parentRead, parentWrite; - DWORD pipeMode; + pid_t + popen2 (const std::string& cmd, const string_vector& args, + bool sync_mode, int *fildes, std::string& msg) + { + pid_t pid; + PROCESS_INFORMATION pi; + STARTUPINFO si; + std::string command = "\"" + cmd + "\""; + HANDLE hProcess = GetCurrentProcess (); + HANDLE childRead, childWrite, parentRead, parentWrite; + DWORD pipeMode; + + ZeroMemory (&pi, sizeof (pi)); + ZeroMemory (&si, sizeof (si)); + si.cb = sizeof (si); - ZeroMemory (&pi, sizeof (pi)); - ZeroMemory (&si, sizeof (si)); - si.cb = sizeof (si); + if (! CreatePipe (&childRead, &parentWrite, 0, 0) + || ! DuplicateHandle (hProcess, childRead, hProcess, &childRead, + 0, TRUE, + DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) + { + msg = "popen2: pipe creation failed"; + return -1; + } + if (! CreatePipe (&parentRead, &childWrite, 0, 0) + || ! DuplicateHandle (hProcess, childWrite, hProcess, &childWrite, + 0, TRUE, + DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) + { + msg = "popen2: pipe creation failed"; + return -1; + } + if (! sync_mode) + { + pipeMode = PIPE_NOWAIT; + SetNamedPipeHandleState (parentRead, &pipeMode, 0, 0); + } + fildes[1] = _open_osfhandle (reinterpret_cast (parentRead), + _O_RDONLY | _O_BINARY); + fildes[0] = _open_osfhandle (reinterpret_cast (parentWrite), + _O_WRONLY | _O_BINARY); + si.dwFlags |= STARTF_USESTDHANDLES; + si.hStdInput = childRead; + si.hStdOutput = childWrite; - if (! CreatePipe (&childRead, &parentWrite, 0, 0) - || ! DuplicateHandle (hProcess, childRead, hProcess, &childRead, - 0, TRUE, - DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) - { - msg = "popen2: pipe creation failed"; - return -1; - } - if (! CreatePipe (&parentRead, &childWrite, 0, 0) - || ! DuplicateHandle (hProcess, childWrite, hProcess, &childWrite, - 0, TRUE, - DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) - { - msg = "popen2: pipe creation failed"; - return -1; + // Ignore first arg as it is the command + for (int k=1; k (parentRead), - _O_RDONLY | _O_BINARY); - fildes[0] = _open_osfhandle (reinterpret_cast (parentWrite), - _O_WRONLY | _O_BINARY); - si.dwFlags |= STARTF_USESTDHANDLES; - si.hStdInput = childRead; - si.hStdOutput = childWrite; - - // Ignore first arg as it is the command - for (int k=1; k #include "lo-ieee.h" + class string_vector; -extern std::string octave_getcwd (void); +namespace octave +{ + namespace sys + { + extern std::string getcwd (void); -extern int octave_chdir (const std::string&); + extern int chdir (const std::string&); #if defined (__WIN32__) && ! defined (__CYGWIN__) -extern pid_t octave_popen2 (const std::string&, const string_vector&, - bool, int *, std::string&); + extern pid_t popen2 (const std::string&, const string_vector&, + bool, int *, std::string&); +#endif + } +} + +#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) + +OCTAVE_DEPRECATED ("use octave::sys::getcwd instead") +const auto octave_getcwd = octave::sys::getcwd; + +OCTAVE_DEPRECATED ("use octave::sys::chdir instead") +const auto octave_chdir = octave::sys::chdir; + +#if defined (__WIN32__) && ! defined (__CYGWIN__) +OCTAVE_DEPRECATED ("use octave::sys:: instead") +const auto octave_popen2 = octave::sys::popen2; #endif #endif + +#endif diff -r ab6c639f0678 -r a99c2407f930 liboctave/system/oct-env.cc --- a/liboctave/system/oct-env.cc Thu May 19 01:33:06 2016 -0400 +++ b/liboctave/system/oct-env.cc Thu May 19 01:50:04 2016 -0400 @@ -456,7 +456,7 @@ current_directory = ""; if (verbatim_pwd || current_directory.empty ()) - current_directory = ::octave_getcwd (); + current_directory = octave::sys::getcwd (); return current_directory; } @@ -557,14 +557,14 @@ tmp.resize (len); } - if (! ::octave_chdir (tmp)) + if (! octave::sys::chdir (tmp)) { current_directory = tmp; retval = true; } } else - retval = (! ::octave_chdir (newdir)); + retval = (! octave::sys::chdir (newdir)); return retval; } diff -r ab6c639f0678 -r a99c2407f930 liboctave/system/oct-syscalls.cc --- a/liboctave/system/oct-syscalls.cc Thu May 19 01:33:06 2016 -0400 +++ b/liboctave/system/oct-syscalls.cc Thu May 19 01:50:04 2016 -0400 @@ -322,7 +322,7 @@ bool &interactive) { #if defined (__WIN32__) && ! defined (__CYGWIN__) - return ::octave_popen2 (cmd, args, sync_mode, fildes, msg); + return octave::sys::popen2 (cmd, args, sync_mode, fildes, msg); #else pid_t pid; int child_stdin[2], child_stdout[2];