changeset 21944:4b2eab5d2a6a

provide wrapper for strdup * liboctave/wrappers/strdup-wrapper.c, liboctave/wrappers/strdup-wrapper.h: New files. * liboctave/wrappers/module.mk: Update. * bootstrap.conf: Include strdup module in the list. * cmd-edit.cc, main.in.cc: Use wrapper function.
author John W. Eaton <jwe@octave.org>
date Fri, 17 Jun 2016 16:51:09 -0400
parents 2fc1ce5deae4
children e9765b62d4e8
files bootstrap.conf liboctave/util/cmd-edit.cc liboctave/wrappers/module.mk liboctave/wrappers/strdup-wrapper.c liboctave/wrappers/strdup-wrapper.h src/main.in.cc
diffstat 6 files changed, 82 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/bootstrap.conf	Fri Jun 17 14:39:59 2016 -0400
+++ b/bootstrap.conf	Fri Jun 17 16:51:09 2016 -0400
@@ -95,6 +95,7 @@
   stddef
   stdint
   stdio
+  strdup
   strerror
   strftime
   strptime
--- a/liboctave/util/cmd-edit.cc	Fri Jun 17 14:39:59 2016 -0400
+++ b/liboctave/util/cmd-edit.cc	Fri Jun 17 16:51:09 2016 -0400
@@ -40,6 +40,7 @@
 #include "oct-time.h"
 #include "quit.h"
 #include "singleton-cleanup.h"
+#include "strdup-wrapper.h"
 #include "unistd-wrappers.h"
 
 #if defined (USE_READLINE)
@@ -568,7 +569,7 @@
   char *
   gnu_readline::do_completer_word_break_hook ()
   {
-    static char *dir_sep = strdup (" '\"");
+    static char *dir_sep = octave_strdup_wrapper (" '\"");
 
     std::string word;
     std::string line = get_line_buffer ();
--- a/liboctave/wrappers/module.mk	Fri Jun 17 14:39:59 2016 -0400
+++ b/liboctave/wrappers/module.mk	Fri Jun 17 16:51:09 2016 -0400
@@ -17,6 +17,7 @@
   liboctave/wrappers/set-program-name-wrapper.h \
   liboctave/wrappers/signal-wrappers.h \
   liboctave/wrappers/stat-wrappers.h \
+  liboctave/wrappers/strdup-wrapper.h \
   liboctave/wrappers/strftime-wrapper.h \
   liboctave/wrappers/strmode-wrapper.h \
   liboctave/wrappers/strptime-wrapper.h \
@@ -47,6 +48,7 @@
   liboctave/wrappers/set-program-name-wrapper.c \
   liboctave/wrappers/signal-wrappers.c \
   liboctave/wrappers/stat-wrappers.c \
+  liboctave/wrappers/strdup-wrapper.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/strdup-wrapper.c	Fri Jun 17 16:51:09 2016 -0400
@@ -0,0 +1,39 @@
+/*
+
+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/>.
+
+*/
+
+// strdup 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 <string.h>
+
+#include "strdup-wrapper.h"
+
+char *
+octave_strdup_wrapper (const char *str)
+{
+  return strdup (str);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/wrappers/strdup-wrapper.h	Fri Jun 17 16:51:09 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_strdup_wrapper_h)
+#define octave_strdup_wrapper_h 1
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+extern char *octave_strdup_wrapper (const char *str);
+
+#if defined __cplusplus
+}
+#endif
+
+#endif
--- a/src/main.in.cc	Fri Jun 17 14:39:59 2016 -0400
+++ b/src/main.in.cc	Fri Jun 17 16:51:09 2016 -0400
@@ -41,6 +41,7 @@
 
 #include "fcntl-wrappers.h"
 #include "signal-wrappers.h"
+#include "strdup-wrapper.h"
 #include "unistd-wrappers.h"
 #include "wait-wrappers.h"
 
@@ -236,7 +237,7 @@
       const char *string = argv[i];
 
       if (string[0] == '\0')
-        new_argv[i] = strdup ("\"\"");
+        new_argv[i] = octave_strdup_wrapper ("\"\"");
       else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)
         {
           int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);