Mercurial > octave
changeset 21939:034b15e9c262
hide some preprocessor macros in wrapper functions
* unistd-wrappers.c, unistd-wrappers.h (octave_have_fork,
octave_have_vfork): New functions.
* oct-syscalls.cc: Use new wrapper functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 17 Jun 2016 06:41:08 -0400 |
parents | da9b960b1b2d |
children | 70824a0dd009 |
files | liboctave/system/oct-syscalls.cc liboctave/wrappers/unistd-wrappers.c liboctave/wrappers/unistd-wrappers.h |
diffstat | 3 files changed, 55 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/system/oct-syscalls.cc Fri Jun 17 06:42:28 2016 -0400 +++ b/liboctave/system/oct-syscalls.cc Fri Jun 17 06:41:08 2016 -0400 @@ -101,14 +101,15 @@ { pid_t status = -1; -#if defined (HAVE_FORK) - status = octave_fork_wrapper (); + if (octave_have_fork ()) + { + status = octave_fork_wrapper (); - if (status < 0) - msg = gnulib::strerror (errno); -#else - msg = NOT_SUPPORTED ("vfork"); -#endif + if (status < 0) + msg = gnulib::strerror (errno); + } + else + msg = NOT_SUPPORTED ("fork"); return status; } @@ -118,18 +119,18 @@ { pid_t status = -1; -#if defined (HAVE_VFORK) || defined (HAVE_FORK) -# if defined (HAVE_VFORK) - status = octave_vfork_wrapper (); -# else - status = octave_fork_wrapper (); -# endif + if (octave_have_vfork () || octave_have_fork ()) + { + if (octave_have_vfork ()) + status = octave_vfork_wrapper (); + else + status = octave_fork_wrapper (); - if (status < 0) - msg = gnulib::strerror (errno); -#else - msg = NOT_SUPPORTED ("vfork"); -#endif + if (status < 0) + msg = gnulib::strerror (errno); + } + else + msg = NOT_SUPPORTED ("vfork"); return status; }
--- a/liboctave/wrappers/unistd-wrappers.c Fri Jun 17 06:42:28 2016 -0400 +++ b/liboctave/wrappers/unistd-wrappers.c Fri Jun 17 06:41:08 2016 -0400 @@ -111,7 +111,11 @@ pid_t octave_fork_wrapper (void) { +#if defined (HAVE_FORK) return fork (); +#else + return -1; +#endif } int @@ -231,5 +235,29 @@ pid_t octave_vfork_wrapper (void) { +#if defined (HAVE_VFORK) return vfork (); +#else + return -1; +#endif } + +bool +octave_have_fork (void) +{ +#if defined (HAVE_FORK) + return true; +#else + return false; +#endif +} + +bool +octave_have_vfork (void) +{ +#if defined (HAVE_VFORK) + return true; +#else + return false; +#endif +}
--- a/liboctave/wrappers/unistd-wrappers.h Fri Jun 17 06:42:28 2016 -0400 +++ b/liboctave/wrappers/unistd-wrappers.h Fri Jun 17 06:41:08 2016 -0400 @@ -23,6 +23,10 @@ #if ! defined (octave_unistd_wrappers_h) #define octave_unistd_wrappers_h 1 +#if ! defined (__cplusplus) +# include <stdbool.h> +#endif + #if defined __cplusplus extern "C" { #endif @@ -91,6 +95,10 @@ extern pid_t octave_vfork_wrapper (void); +extern bool octave_have_fork (void); + +extern bool octave_have_vfork (void); + #if defined __cplusplus } #endif