Mercurial > octave
changeset 27143:64ff1053ffbf
F__open_with_system_app__: Consistent return value for all platforms.
* libinterp/corefcn/sysdep.cc (F__open_with_system_app__): On all platforms
this internal function returns 1 on success, that is if the system open call
(not the called operation itself) was successful, and 0 otherwise.
The previous undocumented check on macOS and Unix `PID == 0`
(tmp(0).double_value () == 0) does not make sense and PID > 1 is more likely
in case of success. See https://octave.org/doc/v5.1.0/XREFsystem.html for
details.
Reduce code duplication by using a new local marco `FSYSTEM_OPEN_STR`.
Add documentation regarding the return value.
author | Kai T. Ohlhus <k.ohlhus@gmail.com> |
---|---|
date | Tue, 04 Jun 2019 22:07:45 +0200 |
parents | f26b13c80e45 |
children | 3de14d9a2303 |
files | libinterp/corefcn/sysdep.cc |
diffstat | 1 files changed, 16 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/sysdep.cc Tue Jun 04 09:44:58 2019 -0700 +++ b/libinterp/corefcn/sysdep.cc Tue Jun 04 22:07:45 2019 +0200 @@ -206,7 +206,7 @@ DEFUN (__open_with_system_app__, args, , doc: /* -*- texinfo -*- @deftypefn {} {} __open_with_system_app__ (@var{file}) -Undocumented internal function. +Internal function. Returns 1 on successful system call and 0 otherwise. @end deftypefn */) { if (args.length () != 1) @@ -214,32 +214,29 @@ std::string file = args(0).xstring_value ("__open_with_system_app__: argument must be a filename"); - octave_value retval; - #if defined (OCTAVE_USE_WINDOWS_API) - HINSTANCE status = ShellExecuteW (0, 0, - octave::sys::u8_to_wstring (file).c_str (), - 0, 0, SW_SHOWNORMAL); + HINSTANCE status + = ShellExecuteW (0, 0, octave::sys::u8_to_wstring (file).c_str (), + 0, 0, SW_SHOWNORMAL); // ShellExecute returns a value greater than 32 if successful. - retval = (reinterpret_cast<ptrdiff_t> (status) > 32); -#elif defined (__APPLE__) + return octave_value (reinterpret_cast<ptrdiff_t> (status) > 32); +#else +# if defined (__APPLE__) +# define FSYSTEM_OPEN_STR "open " +# else +# define FSYSTEM_OPEN_STR "xdg-open " +# endif octave_value_list tmp - = Fsystem (ovl ("open " + file + " 2> /dev/null", + = Fsystem (ovl (FSYSTEM_OPEN_STR + file + " 2> /dev/null", false, "async"), 1); +# undef FSYSTEM_OPEN_STR - retval = (tmp(0).double_value () == 0); -#else - octave_value_list tmp - = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null", - false, "async"), - 1); - - retval = (tmp(0).double_value () == 0); + // Asynchronous Fsystem calls return the new child process identifier, + // which must be greater than 1 if successful. + return octave_value (tmp(0).double_value () > 1); #endif - - return retval; } namespace octave