changeset 21891:3ca0a5b1b313

hide gnulib progname.h header * liboctave/wrappers/set-program-name-wrapper.c, liboctave/wrappers/set-program-name-wrapper.h: New files. Wrap gnulib set_program_name function and hide gnulib header. * liboctave/wrappers/module.mk: Update. * oct-env.cc: Use new wrapper function.
author John W. Eaton <jwe@octave.org>
date Mon, 13 Jun 2016 20:06:51 -0400
parents 5dc59e7af536
children 8fcc81df840c
files liboctave/system/oct-env.cc liboctave/wrappers/module.mk liboctave/wrappers/set-program-name-wrapper.c liboctave/wrappers/set-program-name-wrapper.h
diffstat 4 files changed, 85 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/system/oct-env.cc	Mon Jun 13 18:42:02 2016 -0400
+++ b/liboctave/system/oct-env.cc	Mon Jun 13 20:06:51 2016 -0400
@@ -49,8 +49,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "progname.h"
-
 #include "file-ops.h"
 #include "lo-error.h"
 #include "lo-sysdep.h"
@@ -58,6 +56,7 @@
 #include "oct-env.h"
 #include "oct-passwd.h"
 #include "oct-syscalls.h"
+#include "set-program-name-wrapper.h"
 #include "singleton-cleanup.h"
 
 namespace octave
@@ -269,16 +268,17 @@
 
       if (! initialized)
         {
+          // octave_set_program_name_wrapper returns a cleaned up
+          // version of the program name (stripping libtool's "lt-"
+          // prefix, for example).
+
           // The string passed to gnulib's ::set_program_name function must
           // exist for the duration of the program so allocate a copy here
           // instead of passing S.c_str () which only exists as long as the
           // string object S.
 
-          // For gnulib.
-          ::set_program_name (strsave (s.c_str ()));
-
-          // Let gnulib strip off things like the "lt-" prefix from libtool.
-          prog_invocation_name = program_name;
+          prog_invocation_name
+            = octave_set_program_name_wrapper (strsave (s.c_str ()));
 
           size_t pos
             = prog_invocation_name.find_last_of (octave::sys::file_ops::dir_sep_chars ());
--- a/liboctave/wrappers/module.mk	Mon Jun 13 18:42:02 2016 -0400
+++ b/liboctave/wrappers/module.mk	Mon Jun 13 20:06:51 2016 -0400
@@ -6,6 +6,7 @@
   liboctave/wrappers/nanosleep-wrapper.h \
   liboctave/wrappers/nproc-wrapper.h \
   liboctave/wrappers/putenv-wrapper.h \
+  liboctave/wrappers/set-program-name-wrapper.h \
   liboctave/wrappers/strftime-wrapper.h \
   liboctave/wrappers/strptime-wrapper.h \
   liboctave/wrappers/unsetenv-wrapper.h \
@@ -19,6 +20,7 @@
   liboctave/wrappers/nanosleep-wrapper.c \
   liboctave/wrappers/nproc-wrapper.c \
   liboctave/wrappers/putenv-wrapper.c \
+  liboctave/wrappers/set-program-name-wrapper.c \
   liboctave/wrappers/strftime-wrapper.c \
   liboctave/wrappers/strptime-wrapper.c \
   liboctave/wrappers/unsetenv-wrapper.c \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/wrappers/set-program-name-wrapper.c	Mon Jun 13 20:06:51 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/>.
+
+*/
+
+// set_program_name is 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 "progname.h"
+
+char *
+octave_set_program_name_wrapper (const char *pname)
+{
+  set_program_name (pname);
+
+  // Let gnulib strip off things like the "lt-" prefix from libtool.
+  return program_name;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/liboctave/wrappers/set-program-name-wrapper.h	Mon Jun 13 20:06:51 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_set_program_name_wrapper_h)
+#define octave_set_program_name_wrapper_h 1
+
+#if defined __cplusplus
+extern "C" {
+#endif
+
+extern char *octave_set_program_name_wrapper (const char *pname);
+
+#if defined __cplusplus
+}
+#endif
+
+#endif