changeset 10259:65b41bc71f09

use gnulib fcntl module
author John W. Eaton <jwe@octave.org>
date Wed, 03 Feb 2010 17:05:02 -0500
parents e317791645c4
children 14d5fee02b3b
files ChangeLog bootstrap.conf configure.ac liboctave/ChangeLog liboctave/cmd-hist.cc liboctave/lo-sysdep.cc liboctave/oct-syscalls.cc liboctave/oct-syscalls.h src/ChangeLog src/file-io.cc src/syscalls.cc
diffstat 11 files changed, 59 insertions(+), 53 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-02-03  John W. Eaton  <jwe@octave.org>
+
+	* configure.ac: Don't check for fcntl.h or fcntl.
+	* bootstrap.conf (gnulib_modules): Include fcntl in the list.
+
 2010-02-03  John W. Eaton  <jwe@octave.org>
 
 	* acinclude.m4 (OCTAVE_HAVE_C99_VSNPRINTF): Delete.
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -20,6 +20,7 @@
 gnulib_modules="
   c-strcase
   crypto/md5
+  fcntl
   fnmatch
   getcwd
   getopt-gnu
--- a/configure.ac
+++ b/configure.ac
@@ -1448,7 +1448,7 @@
 
 ### C headers
 
-AC_CHECK_HEADERS(curses.h direct.h dlfcn.h fcntl.h \
+AC_CHECK_HEADERS(curses.h direct.h dlfcn.h \
   floatingpoint.h grp.h ieeefp.h inttypes.h locale.h memory.h nan.h \
   ncurses.h poll.h pthread.h pwd.h sunmath.h sys/ioctl.h \
   sys/param.h sys/poll.h sys/resource.h sys/select.h \
@@ -1489,7 +1489,7 @@
 ### Checks for functions and variables.
 
 AC_CHECK_FUNCS(basename canonicalize_file_name \
-  chmod dup2 endgrent endpwent execvp expm1 expm1f fcntl fork \
+  chmod dup2 endgrent endpwent execvp expm1 expm1f fork \
   getegid geteuid getgid getgrent getgrgid getgrnam getpgrp getpid \
   getppid getpwent getpwuid getuid getwd _kbhit kill \
   lgamma lgammaf lgamma_r lgammaf_r localtime_r log1p log1pf \
--- a/liboctave/ChangeLog
+++ b/liboctave/ChangeLog
@@ -1,3 +1,11 @@
+2010-02-03  John W. Eaton  <jwe@octave.org>
+
+	* oct-syscalls.h, oct-syscalls.cc (octave_fcntl): Assume fcntl exists.
+	Rename from octave_syscalls::fcntl.
+	(octave_syscalls::popen2): Call octave_fcntl, not fcntl.
+	* cmd-hist.cc, lo-sysdep.cc, oct-syscalls.cc:
+	Include <fcntl.h> unconditionally.
+
 2010-02-03  John W. Eaton  <jwe@octave.org>
 
 	* dbleSVD.cc (SVD::init): Ensure args to std::max are the same type.
--- a/liboctave/cmd-hist.cc
+++ b/liboctave/cmd-hist.cc
@@ -42,13 +42,11 @@
 
 #include <cstdlib>
 
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
-
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <fcntl.h>
+
 #include "oct-rl-hist.h"
 
 #include "file-stat.h"
--- a/liboctave/lo-sysdep.cc
+++ b/liboctave/lo-sysdep.cc
@@ -31,9 +31,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif
 
 #if defined (__WIN32__) && ! defined (__CYGWIN__)
 #include <windows.h>
--- a/liboctave/oct-syscalls.cc
+++ b/liboctave/oct-syscalls.cc
@@ -33,9 +33,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif
 
 // We can't use csignal as kill is not in the std namespace, and picky
 // compiler runtimes will also exclude it from global scope as well.
@@ -113,35 +111,6 @@
   return status;
 }
 
-int
-octave_syscalls::fcntl (int fd, int cmd, long arg)
-{
-  std::string msg;
-  return fcntl (fd, cmd, arg, msg);
-}
-
-int
-octave_syscalls::fcntl (int fd, int cmd, long arg, std::string& msg)
-{
-  msg = std::string ();
-
-  int status = -1;
-
-#if defined (HAVE_FCNTL)
-  status = ::fcntl (fd, cmd, arg);
-
-  if (status < 0)
-    {
-      using namespace std;
-      msg = ::strerror (errno);
-    }
-#else
-  msg = NOT_SUPPORTED ("fcntl");
-#endif
-
-  return status;
-}
-
 pid_t
 octave_syscalls::fork (std::string& msg)
 {
@@ -422,7 +391,7 @@
               ::close (child_stdin[0]);
               ::close (child_stdout[1]);
 #if defined (F_SETFL) && defined (O_NONBLOCK)
-              if (! sync_mode && fcntl (child_stdout[0], F_SETFL, O_NONBLOCK, msg) < 0)
+              if (! sync_mode && octave_fcntl (child_stdout[0], F_SETFL, O_NONBLOCK, msg) < 0)
                 msg = "popen2: error setting file mode -- " + msg;
               else
 #endif
@@ -446,3 +415,28 @@
   return -1;
 #endif
 }
+
+int
+octave_fcntl (int fd, int cmd, long arg)
+{
+  std::string msg;
+  return octave_fcntl (fd, cmd, arg, msg);
+}
+
+int
+octave_fcntl (int fd, int cmd, long arg, std::string& msg)
+{
+  msg = std::string ();
+
+  int status = -1;
+
+  status = ::fcntl (fd, cmd, arg);
+
+  if (status < 0)
+    {
+      using namespace std;
+      msg = ::strerror (errno);
+    }
+
+  return status;
+}
--- a/liboctave/oct-syscalls.h
+++ b/liboctave/oct-syscalls.h
@@ -40,9 +40,6 @@
   static int execvp (const std::string&, const string_vector&);
   static int execvp (const std::string&, const string_vector&, std::string&);
 
-  static int fcntl (int, int, long);
-  static int fcntl (int, int, long, std::string&);
-
   static pid_t fork (std::string&);
   static pid_t vfork (std::string&);
 
@@ -72,3 +69,6 @@
 };
 
 #endif
+
+extern OCTAVE_API int octave_fcntl (int, int, long);
+extern OCTAVE_API int octave_fcntl (int, int, long, std::string&);
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2010-02-03  John W. Eaton  <jwe@octave.org>
+
+	* file-io.cc: Assume we have fcntl.h and sys/stat.h.
+
+	* syscalls.cc: Assume we have fcntl.h and fcntl.
+	(Ffcntl): Use DEFUNX, not DEFUN.  Call octave_fcntl, not
+	octave_syscalls::fcntl.
+
 2010-02-03  John W. Eaton  <jwe@octave.org>
 
 	* DLD-FUNCTIONS/sub2ind.cc (get_dim_vector):
--- a/src/file-io.cc
+++ b/src/file-io.cc
@@ -1953,12 +1953,8 @@
 #endif
 
 #if ! defined (HAVE_MKSTEMP) && ! defined (HAVE_MKSTEMPS) && defined (_MSC_VER)
-# if defined (HAVE_FCNTL_H)
-#  include <fcntl.h>
-# endif
-# if defined (HAVE_SYS_STAT_H)
-#  include <sys/stat.h>
-# endif
+#include <fcntl.h>
+#include <sys/stat.h>
 int mkstemp (char *tmpl)
 {
   int ret=-1;
--- a/src/syscalls.cc
+++ b/src/syscalls.cc
@@ -36,9 +36,7 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif
 
 #include "file-ops.h"
 #include "file-stat.h"
@@ -390,7 +388,7 @@
 
 */
 
-DEFUN (fcntl, args, ,
+DEFUNX ("fcntl", Ffcntl, args, ,
  "-*- texinfo -*-\n\
 @deftypefn {Built-in Function} {[@var{err}, @var{msg}] =} fcntl (@var{fid}, @var{request}, @var{arg})\n\
 Change the properties of the open file @var{fid}.  The following values\n\
@@ -474,7 +472,7 @@
 		{
 		  std::string msg;
 
-		  int status = octave_syscalls::fcntl (fid, req, arg, msg);
+		  int status = octave_fcntl (fid, req, arg, msg);
 
 		  retval(0) = status;
 		  retval(1) = msg;