Mercurial > octave
changeset 21899:7c053ad1c7ba
hide sys/select header
* liboctave/wrappers/wait-for-input.c,
liboctave/wrappers/wait-for-input.h: New files.
* liboctave/wrappers/module.mk: Update.
* toplev.cc: Use new octave_wait_for_input function.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 Jun 2016 13:43:17 -0400 |
parents | b5313b6cbe72 |
children | d25e9f85ffb4 |
files | libinterp/corefcn/toplev.cc liboctave/wrappers/module.mk liboctave/wrappers/wait-for-input.c liboctave/wrappers/wait-for-input.h |
diffstat | 4 files changed, 100 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/toplev.cc Tue Jun 14 10:32:24 2016 -0700 +++ b/libinterp/corefcn/toplev.cc Tue Jun 14 13:43:17 2016 -0400 @@ -35,8 +35,6 @@ #include <sstream> #include <string> -#include <sys/select.h> - #include "cmd-edit.h" #include "cmd-hist.h" #include "file-ops.h" @@ -48,6 +46,7 @@ #include "quit.h" #include "singleton-cleanup.h" #include "str-vec.h" +#include "wait-for-input.h" #include "build-env.h" #include "liboctinterp-build-info.h" @@ -992,28 +991,6 @@ // Execute a shell command. -static int -wait_for_input (int fid) -{ - int retval = -1; - -#if defined (HAVE_SELECT) - if (fid >= 0) - { - fd_set set; - - FD_ZERO (&set); - FD_SET (fid, &set); - - retval = gnulib::select (FD_SETSIZE, &set, 0, 0, 0); - } -#else - retval = 1; -#endif - - return retval; -} - static octave_value_list run_command_and_return_output (const std::string& cmd_str) { @@ -1044,7 +1021,7 @@ { cmd->clear (); - if (wait_for_input (fid) != 1) + if (octave_wait_for_input (fid) != 1) break; } else
--- a/liboctave/wrappers/module.mk Tue Jun 14 10:32:24 2016 -0700 +++ b/liboctave/wrappers/module.mk Tue Jun 14 13:43:17 2016 -0400 @@ -14,7 +14,8 @@ liboctave/wrappers/strptime-wrapper.h \ liboctave/wrappers/uname-wrapper.h \ liboctave/wrappers/unsetenv-wrapper.h \ - liboctave/wrappers/vasprintf-wrapper.h + liboctave/wrappers/vasprintf-wrapper.h \ + liboctave/wrappers/wait-for-input.h WRAPPERS_SRC = \ liboctave/wrappers/areadlink-wrapper.c \ @@ -32,7 +33,8 @@ liboctave/wrappers/strptime-wrapper.c \ liboctave/wrappers/uname-wrapper.c \ liboctave/wrappers/unsetenv-wrapper.c \ - liboctave/wrappers/vasprintf-wrapper.c + liboctave/wrappers/vasprintf-wrapper.c \ + liboctave/wrappers/wait-for-input.c noinst_LTLIBRARIES += liboctave/wrappers/libwrappers.la
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/wait-for-input.c Tue Jun 14 13:43:17 2016 -0400 @@ -0,0 +1,58 @@ +/* + +Copyright (C) 2016 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +// select may be provided by gnulib. We don't include gnulib headers +// directly in Octave's C++ source files to avoid problems that may be +// caused by the way that gnulib overrides standard library functions. + +// We don't need select directly, we just need to use it to wait for +// input on an open file descriptor. + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include <sys/select.h> + +#include "wait-for-input.h" + +int +octave_wait_for_input (int fid) +{ + int retval = -1; + +#if defined (HAVE_SELECT) + if (fid >= 0) + { + fd_set set; + + FD_ZERO (&set); + FD_SET (fid, &set); + + retval = select (FD_SETSIZE, &set, 0, 0, 0); + } +#else + retval = 1; +#endif + + return retval; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/wrappers/wait-for-input.h Tue Jun 14 13:43:17 2016 -0400 @@ -0,0 +1,36 @@ +/* + +Copyright (C) 2016 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +*/ + +#if ! defined (octave_wait_for_input_h) +#define octave_wait_for_input_h 1 + +#if defined __cplusplus +extern "C" { +#endif + +extern int octave_wait_for_input (int fid); + +#if defined __cplusplus +} +#endif + +#endif