Mercurial > octave
changeset 28102:4d021e0dcfee
fcntl: throw error if operation fails and nargout == 0 (bug #57830).
* syscalls.cc (Ffcntl): Add nargout to DEFUN macro invocation.
Add command calling form to documentation.
Rename "err" to "status" in documentation.
Document that status variable is -1 if an error is encountered.
Based on nargout variable, either throw an error if operation failed, or return
status and msg information.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 18 Feb 2020 16:46:15 -0800 |
parents | 43c2d9c03cc7 |
children | 1cb3c33f97dc |
files | libinterp/corefcn/syscalls.cc |
diffstat | 1 files changed, 20 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/syscalls.cc Tue Feb 18 16:31:02 2020 -0800 +++ b/libinterp/corefcn/syscalls.cc Tue Feb 18 16:46:15 2020 -0800 @@ -377,9 +377,10 @@ */ -DEFMETHODX ("fcntl", Ffcntl, interp, args, , +DEFMETHODX ("fcntl", Ffcntl, interp, args, nargout, doc: /* -*- texinfo -*- -@deftypefn {} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg}) +@deftypefn {} {} fcntl (@var{fid}, @var{request}, @var{arg}) +@deftypefnx {} {[@var{status}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg}) Change the properties of the open file @var{fid}. The following values may be passed as @var{request}: @@ -430,8 +431,8 @@ @w{@code{O_NONBLOCK}}. @end vtable -If successful, @var{err} is 0 and @var{msg} is an empty string. Otherwise, -@var{err} is nonzero and @var{msg} contains a system-dependent error +If successful, @var{status} is 0 and @var{msg} is an empty string. Otherwise, +@var{status} is -1 and @var{msg} contains a system-dependent error message. @seealso{fopen, dup2} @end deftypefn */) @@ -454,11 +455,25 @@ if (fid < 0) error ("fcntl: invalid file id"); + octave_value_list retval; std::string msg; int status = octave::sys::fcntl (fid, req, arg, msg); - return ovl (status, msg); + if (nargout == 0) + { + if (status < 0) + error ("fcntl: operation failed: %s", msg.c_str ()); + } + else + { + if (status < 0) + retval = ovl (-1.0, msg); + else + retval = ovl (0.0, ""); + } + + return retval; } DEFMETHODX ("fork", Ffork, interp, args, ,