changeset 21909:d7cac41df82a

provide wrappers for some sys/stat functions * liboctave/wrappers/stat-wrappers.c, liboctave/wrappers/stat-wrappers.h: New files. * liboctave/wrappers/module.mk: Update. * file-ops.cc: Use new wrappers for mkfifo, mkdir, and umask.
author John W. Eaton <jwe@octave.org>
date Tue, 14 Jun 2016 16:31:34 -0400
parents 74d60f5e37be
children 4d723ba06b4a
files liboctave/system/file-ops.cc liboctave/wrappers/module.mk liboctave/wrappers/stat-wrappers.c liboctave/wrappers/stat-wrappers.h
diffstat 4 files changed, 98 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/system/file-ops.cc	Wed Jun 15 10:47:33 2016 -0700
+++ b/liboctave/system/file-ops.cc	Tue Jun 14 16:31:34 2016 -0400
@@ -36,8 +36,6 @@
 #include <iostream>
 #include <vector>
 
-#include <sys/stat.h>
-
 #include <sys/types.h>
 #include <unistd.h>
 
@@ -52,6 +50,7 @@
 #include "oct-passwd.h"
 #include "quit.h"
 #include "singleton-cleanup.h"
+#include "stat-wrappers.h"
 #include "str-vec.h"
 
 namespace octave
@@ -414,9 +413,7 @@
     {
       msg = "";
 
-      int status = -1;
-
-      status = gnulib::mkdir (name.c_str (), mode);
+      int status = octave_mkdir_wrapper (name.c_str (), mode);
 
       if (status < 0)
         msg = gnulib::strerror (errno);
@@ -436,13 +433,7 @@
     {
       msg = "";
 
-      int status = -1;
-
-      // With gnulib we will always have mkfifo, but some systems like MinGW
-      // don't have working mkfifo functions.  On those systems, mkfifo will
-      // always return -1 and set errno.
-
-      status = gnulib::mkfifo (name.c_str (), mode);
+      int status = octave_mkfifo_wrapper (name.c_str (), mode);
 
       if (status < 0)
         msg = gnulib::strerror (errno);
@@ -648,11 +639,7 @@
     int
     umask (mode_t mode)
     {
-#if defined (HAVE_UMASK)
-      return ::umask (mode);
-#else
-      return 0;
-#endif
+      return octave_umask_wrapper (mode);
     }
 
     int
--- a/liboctave/wrappers/module.mk	Wed Jun 15 10:47:33 2016 -0700
+++ b/liboctave/wrappers/module.mk	Tue Jun 14 16:31:34 2016 -0400
@@ -10,6 +10,7 @@
   liboctave/wrappers/nproc-wrapper.h \
   liboctave/wrappers/putenv-wrapper.h \
   liboctave/wrappers/set-program-name-wrapper.h \
+  liboctave/wrappers/stat-wrappers.h \
   liboctave/wrappers/strftime-wrapper.h \
   liboctave/wrappers/strmode-wrapper.h \
   liboctave/wrappers/strptime-wrapper.h \
@@ -30,6 +31,7 @@
   liboctave/wrappers/nproc-wrapper.c \
   liboctave/wrappers/putenv-wrapper.c \
   liboctave/wrappers/set-program-name-wrapper.c \
+  liboctave/wrappers/stat-wrappers.c \
   liboctave/wrappers/strftime-wrapper.c \
   liboctave/wrappers/strmode-wrapper.c \
   liboctave/wrappers/strptime-wrapper.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/wrappers/stat-wrappers.c	Tue Jun 14 16:31:34 2016 -0400
@@ -0,0 +1,52 @@
+/*
+
+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/>.
+
+*/
+
+// These functions 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.
+
+#if defined (HAVE_CONFIG_H)
+#  include "config.h"
+#endif
+
+#include <sys/stat.h>
+
+#include "stat-wrappers.h"
+
+int
+octave_mkdir_wrapper (const char *name, mode_t mode)
+{
+  return mkdir (name, mode);
+}
+
+int
+octave_mkfifo_wrapper (const char *name, mode_t mode)
+{
+  return mkfifo (name, mode);
+}
+
+int
+octave_umask_wrapper (mode_t mode)
+{
+  return umask (mode);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/wrappers/stat-wrappers.h	Tue Jun 14 16:31:34 2016 -0400
@@ -0,0 +1,40 @@
+/*
+
+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_stat_wrappers_h)
+#define octave_stat_wrappers_h 1
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+extern int octave_mkdir_wrapper (const char *name, mode_t mode);
+
+extern int octave_mkfifo_wrapper (const char *name, mode_t mode);
+
+extern int octave_umask_wrapper (mode_t mode);
+
+#if defined __cplusplus
+}
+#endif
+
+#endif