[Gnucash-changes] Move the conditionally compiled gnucash setenv/unsetenv functions to

David Hampton hampton at cvs.gnucash.org
Thu Sep 8 23:02:07 EDT 2005


Log Message:
-----------
Move the conditionally compiled gnucash setenv/unsetenv functions
to lib/libc a where they belong.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash:
        ChangeLog
        configure.in
    gnucash/lib/libc:
        Makefile.am
    gnucash/src/backend/file:
        sixtp-utils.c
    gnucash/src/backend/file/test:
        Makefile.am
        test-save-in-lang.c
    gnucash/src/core-utils:
        Makefile.am
        gw-core-utils-spec.scm
    gnucash/src/gnc-module:
        Makefile.am
        gnc-module.c

Added Files:
-----------
    gnucash/lib/libc:
        setenv.c
        setenv.h

Removed Files:
-------------
    gnucash/src/core-utils:
        core-utils.c
        core-utils.h

Revision Data
-------------
Index: configure.in
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/configure.in,v
retrieving revision 1.359.2.61
retrieving revision 1.359.2.62
diff -Lconfigure.in -Lconfigure.in -u -r1.359.2.61 -r1.359.2.62
--- configure.in
+++ configure.in
@@ -95,7 +95,12 @@
 AC_HEADER_STDC
 
 AC_CHECK_HEADERS(limits.h)
-AC_CHECK_FUNCS(stpcpy memcpy timegm towupper setenv putenv)
+AC_CHECK_FUNCS(stpcpy memcpy timegm towupper)
+AC_CHECK_FUNCS(setenv,,[
+  AC_CHECK_FUNCS(putenv,,[
+    AC_MSG_ERROR([Must have one of the setenv or putenv functions.])
+  ])
+])
 
 ## +jsled
 # copied from gnumeric
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.281
retrieving revision 1.1487.2.282
diff -LChangeLog -LChangeLog -u -r1.1487.2.281 -r1.1487.2.282
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,24 @@
+2005-09-08  David Hampton  <hampton at employees.org>
+
+	* lib/libc/Makefile.am:
+	* lib/libc/setenv.[ch]:
+	* src/core-utils/Makefile.am:
+	* src/core-utils/core-utils.[ch]: Move the gnucash
+	gnc_setenv/gnc_unsetenv functions to the library directory and
+	rename them to setenv/unsetenv.  These functions are only compiled
+	if not provided by the system libc library.
+
+	* configure.in: Enforce check for one of setenv() or putenv()
+	during configure, not compilation.
+
+	* src/backend/file/sixtp-utils.c:
+	* src/backend/file/test/Makefile.am:
+	* src/backend/file/test/test-save-in-lang.c:
+	* src/core-utils/gw-core-utils-spec.scm:
+	* src/gnc-module/Makefile.am:
+	* src/gnc-module/gnc-module.c: Cleanup for the rename of
+	setenv/unsetenv.
+
 2005-09-05  Derek Atkins  <derek at ihtfp.com>
 
 	* src/backend/file/sixtp-utils.c:  Revert change.. Make sure
Index: sixtp-utils.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/sixtp-utils.c,v
retrieving revision 1.7.4.7
retrieving revision 1.7.4.8
diff -Lsrc/backend/file/sixtp-utils.c -Lsrc/backend/file/sixtp-utils.c -u -r1.7.4.7 -r1.7.4.8
--- src/backend/file/sixtp-utils.c
+++ src/backend/file/sixtp-utils.c
@@ -41,14 +41,15 @@
 #include "gnc-engine-util.h"
 #include "gnc-numeric.h"
 #include "guid.h"
-/*
+#ifndef HAVE_SETENV
+#include "setenv.h"
+#endif
 #ifndef HAVE_STRPTIME
 #include "strptime.h"
 #endif
 #ifndef HAVE_LOCALTIME_R
 #include "localtime_r.h"
 #endif
-*/
 static short module = MOD_IO;
 
 gboolean
@@ -392,19 +393,19 @@
 
   old_tz = getenv ("TZ");
   /* FIXME: there's no way to report this error to the caller. */
-  if(gnc_setenv("TZ", "UTC", 1) != 0)
+  if(setenv("TZ", "UTC", 1) != 0)
     PERR ("couldn't switch the TZ.");
   result = mktime (tm);
   if(old_tz)
   {
     /* FIXME: there's no way to report this error to the caller. */
-    if(gnc_setenv("TZ", old_tz, 1) != 0)
+    if(setenv("TZ", old_tz, 1) != 0)
       PERR ("couldn't switch the TZ back.");
   }
   else
   {
     /* FIXME: there's no way to report this error to the caller. */
-    gnc_unsetenv("TZ");
+    unsetenv("TZ");
     if(errno != 0)
       PERR ("couldn't restore the TZ to undefined.");
   }
Index: test-save-in-lang.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/test/test-save-in-lang.c,v
retrieving revision 1.7.4.1
retrieving revision 1.7.4.2
diff -Lsrc/backend/file/test/test-save-in-lang.c -Lsrc/backend/file/test/test-save-in-lang.c -u -r1.7.4.1 -r1.7.4.2
--- src/backend/file/test/test-save-in-lang.c
+++ src/backend/file/test/test-save-in-lang.c
@@ -11,7 +11,9 @@
 #include "test-engine-stuff.h"
 #include "test-file-stuff.h"
 
-#include "core-utils.h"
+#ifndef HAVE_SETENV
+#include "setenv.h"
+#endif
 #include "qofbook.h"
 #include "gnc-engine.h"
 #include "TransLog.h"
@@ -93,8 +95,8 @@
             return g_strdup_printf("qof_session_load errorid %d", err);
         }
 
-        if(gnc_setenv("LANG", possible_envs[i], 1) != 0)
-          return g_strdup_printf("gnc_setenv for LANG");
+        if(setenv("LANG", possible_envs[i], 1) != 0)
+          return g_strdup_printf("setenv for LANG");
 
         new_session = qof_session_new();
         
@@ -165,10 +167,10 @@
                 break;
             }
 
-            if(gnc_setenv("LANG", base_env, 1) != 0)
+            if(setenv("LANG", base_env, 1) != 0)
             {
-              failure_args("gnc_setenv", __FILE__, __LINE__,
-                           "gnc_setenv of LANG failed");
+              failure_args("setenv", __FILE__, __LINE__,
+                           "setenv of LANG failed");
               g_free(filename);
               break;
             }
Index: Makefile.am
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/backend/file/test/Makefile.am,v
retrieving revision 1.28.4.3
retrieving revision 1.28.4.4
diff -Lsrc/backend/file/test/Makefile.am -Lsrc/backend/file/test/Makefile.am -u -r1.28.4.3 -r1.28.4.4
--- src/backend/file/test/Makefile.am
+++ src/backend/file/test/Makefile.am
@@ -57,9 +57,11 @@
         ${top_builddir}/src/engine/libgw-kvp.la \
         ${top_builddir}/src/engine/test-core/libgncmod-test-engine.la \
         ${top_builddir}/src/backend/file/libgncmod-backend-file.la \
-        ./libgnc-test-file-stuff.la 
+        ./libgnc-test-file-stuff.la \
+        ${top_builddir}/lib/libc/libc-missing.la
 
 AM_CFLAGS = \
+  -I${top_srcdir}/lib/libc \
   -I${top_srcdir}/src \
   -I${top_srcdir}/src/core-utils \
   -I${top_srcdir}/src/gnc-module \
--- src/core-utils/core-utils.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/********************************************************************\
- * File: core-utils.h
- *
- * Copyright (C) 2001 Linux Developers Group
- *
- * This program 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 2 of the
- * License, or (at your option) any later version.
- * 
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
-\********************************************************************/
-
-#ifndef GNC_CORE_UTILS_H
-#define GNC_CORE_UTILS_H
-
-#include "config.h"
-
-/* gnc_setenv() papers over the brokenness of of systems that only
- * have putenv() which takes ownership of the pointer you give it,
- * making it *very* difficult, if not impossible to avoid memory
- * leaks.  Note that right now, on systems that have setenv, this is
- * just setenv, and on other systems, we just leave the memory leak.
- * Later, we may try to make things a little better by keeping track
- * of the pointers we call putenv on in a hash table and if someone
- * calls gnc_setenv on an envt var that we've previously set, then
- * we'll free it after the change.  However, given the sloppy
- * semantics (or docs) for putenv, it's not even clear that this is
- * OK, since it's not clear that people aren't allowed to keep the
- * pointer from getenv around, as long as they don't try to modify
- * it... <shrug> */
-#ifdef HAVE_SETENV
-
-#define gnc_setenv setenv
-#define gnc_unsetenv unsetenv
-
-#elif defined HAVE_PUTENV
-
-int gnc_setenv(const char *name, const char *value, int overwrite);
-int gnc_unsetenv(const char *name);
-
-#else
-#error "Must have setenv or putenv."
-#endif
-
-#endif
Index: Makefile.am
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/core-utils/Makefile.am,v
retrieving revision 1.7.4.4
retrieving revision 1.7.4.5
diff -Lsrc/core-utils/Makefile.am -Lsrc/core-utils/Makefile.am -u -r1.7.4.4 -r1.7.4.5
--- src/core-utils/Makefile.am
+++ src/core-utils/Makefile.am
@@ -2,7 +2,6 @@
 lib_LTLIBRARIES = libcore-utils.la libgw-core-utils.la
 
 libcore_utils_la_SOURCES = \
-  core-utils.c \
   gnc-gconf-utils.c \
   gnc-gobject-utils.c
 
@@ -22,7 +21,6 @@
   ${GUILE_LIBS}
 
 noinst_HEADERS = \
-  core-utils.h \
   gnc-gconf-utils.h \
   gnc-gobject-utils.h \
   gw-core-utils.h
--- src/core-utils/core-utils.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/********************************************************************\
- * File: core-utils.c
- *
- * Copyright (C) 2001 Linux Developers Group
- *
- * This program 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 2 of the
- * License, or (at your option) any later version.
- * 
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
-\********************************************************************/
-
-#include <glib.h>
-
-#include "core-utils.h"
-
-#include <stdlib.h>
-#include <string.h>
-
-/********************************************************************\
- * see header for info.
-\********************************************************************/
-
-#ifndef HAVE_SETENV
-
-int
-gnc_setenv(const char *name, const char *value, int overwrite)
-{
-  const char *old_value = getenv(name);
-  int result = 0;
-
-  if ((name == NULL) || (value == NULL)) return -1;
-
-  if(overwrite || (!old_value))
-  {
-    char *new_value = g_strdup_printf("%s=%s", name, value);
-    if(putenv(new_value) != 0) result = -1;
-    if(old_value)
-    {
-      /* for now, do nothing, but it would be nice if we could figure
-         out a safe way to reclaim any memory that *we* allocated,
-         taking in to account whether or not other code (in other
-         system libs) is allowed to have cached a pointer into the
-         value via getenv -- is that kosher?
-         
-         Also we have to *know* that we allocated the memory.
-      */
-    }
-  }
-  return result;
-}
-
-int
-gnc_unsetenv(const char *name)
-{
-  int result = 0;
-  char *putenv_str;
-  
-  if(name == NULL) return -1;
-  if(strchr(name, '=') != NULL) return -1;
-  if(*name == '\0') return -1;
-  
-  putenv_str = g_strdup_printf("%s=", name);
-  if(!putenv_str) return -1;
-
-  result = putenv(putenv_str);
-  g_free(putenv_str);
-  return result;
-}
-
-#endif
Index: gw-core-utils-spec.scm
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/core-utils/gw-core-utils-spec.scm,v
retrieving revision 1.2.4.3
retrieving revision 1.2.4.4
diff -Lsrc/core-utils/gw-core-utils-spec.scm -Lsrc/core-utils/gw-core-utils-spec.scm -u -r1.2.4.3 -r1.2.4.4
--- src/core-utils/gw-core-utils-spec.scm
+++ src/core-utils/gw-core-utils-spec.scm
@@ -24,7 +24,6 @@
    ws
    (lambda (wrapset client-wrapset)
      (list
-      "#include <core-utils.h>\n"
       "#include <gnc-gconf-utils.h>\n")))
 
   (gw:wrap-function
--- /dev/null
+++ lib/libc/setenv.h
@@ -0,0 +1,33 @@
+/********************************************************************\
+ * File: setenv.h
+ * Renamed from: core-utils.h
+ *
+ * Copyright (C) 2001 Linux Developers Group
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+\********************************************************************/
+
+#ifndef GNC_CORE_UTILS_H
+#define GNC_CORE_UTILS_H
+
+#include "config.h"
+
+#ifndef HAVE_SETENV
+
+int setenv(const char *name, const char *value, int overwrite);
+int unsetenv(const char *name);
+
+#endif
--- /dev/null
+++ lib/libc/setenv.c
@@ -0,0 +1,88 @@
+/********************************************************************\
+ * File: setenv.c
+ * Renamed from: core-utils.c
+ *
+ * Copyright (C) 2001 Linux Developers Group
+ *
+ * This program 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 2 of the
+ * License, or (at your option) any later version.
+ * 
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+\********************************************************************/
+
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* This setenv() papers over the brokenness of of systems that only
+ * have putenv() which takes ownership of the pointer you give it,
+ * making it *very* difficult, if not impossible to avoid memory
+ * leaks.  Note that right now, on systems that have setenv, this is
+ * just setenv, and on other systems, we just leave the memory leak.
+ * Later, we may try to make things a little better by keeping track
+ * of the pointers we call putenv on in a hash table and if someone
+ * calls gnc_setenv on an envt var that we've previously set, then
+ * we'll free it after the change.  However, given the sloppy
+ * semantics (or docs) for putenv, it's not even clear that this is
+ * OK, since it's not clear that people aren't allowed to keep the
+ * pointer from getenv around, as long as they don't try to modify
+ * it... <shrug> */
+
+#ifndef HAVE_SETENV
+
+int
+setenv(const char *name, const char *value, int overwrite)
+{
+  const char *old_value = getenv(name);
+  int result = 0;
+
+  if ((name == NULL) || (value == NULL)) return -1;
+
+  if(overwrite || (!old_value))
+  {
+    char *new_value = g_strdup_printf("%s=%s", name, value);
+    if(putenv(new_value) != 0) result = -1;
+    if(old_value)
+    {
+      /* for now, do nothing, but it would be nice if we could figure
+         out a safe way to reclaim any memory that *we* allocated,
+         taking in to account whether or not other code (in other
+         system libs) is allowed to have cached a pointer into the
+         value via getenv -- is that kosher?
+         
+         Also we have to *know* that we allocated the memory.
+      */
+    }
+  }
+  return result;
+}
+
+int
+unsetenv(const char *name)
+{
+  int result = 0;
+  char *putenv_str;
+  
+  if(name == NULL) return -1;
+  if(strchr(name, '=') != NULL) return -1;
+  if(*name == '\0') return -1;
+  
+  putenv_str = g_strdup_printf("%s=", name);
+  if(!putenv_str) return -1;
+
+  result = putenv(putenv_str);
+  g_free(putenv_str);
+  return result;
+}
+
+#endif
Index: Makefile.am
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/lib/libc/Makefile.am,v
retrieving revision 1.6
retrieving revision 1.6.4.1
diff -Llib/libc/Makefile.am -Llib/libc/Makefile.am -u -r1.6 -r1.6.4.1
--- lib/libc/Makefile.am
+++ lib/libc/Makefile.am
@@ -2,12 +2,12 @@
 
 # All header files must be listed.
 noinst_HEADERS = \
-  localtime_r.h strptime.h
+  localtime_r.h setenv.h strptime.h
 
 # No sources should be listed.
 libc_missing_la_SOURCES = libc-missing-noop.c
 
-EXTRA_libc_missing_la_SOURCES = localtime_r.c strptime.c
+EXTRA_libc_missing_la_SOURCES = localtime_r.c setenv.c strptime.c
 
 # This will automatically be filled in with the necessary object file
 # names.  Configure does this based upon the AC_REPLACE_FUNCS macros.
Index: gnc-module.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnc-module/gnc-module.c,v
retrieving revision 1.20.4.2
retrieving revision 1.20.4.3
diff -Lsrc/gnc-module/gnc-module.c -Lsrc/gnc-module/gnc-module.c -u -r1.20.4.2 -r1.20.4.3
--- src/gnc-module/gnc-module.c
+++ src/gnc-module/gnc-module.c
@@ -14,8 +14,9 @@
 #include <sys/types.h>
 #include <dirent.h>
 
-
-#include "core-utils.h"
+#ifndef HAVE_SETENV
+#include "setenv.h"
+#endif
 #include "gnc-module.h"
 #include "gw-gnc-module.h"
 
@@ -132,7 +133,7 @@
     }
     g_list_free(dirs);
     
-    if(gnc_setenv("LD_LIBRARY_PATH", envt, 1) != 0)
+    if(setenv("LD_LIBRARY_PATH", envt, 1) != 0)
     {
       g_warning ("gnc-module failed to set LD_LIBRARY_PATH");
     }
Index: Makefile.am
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/gnc-module/Makefile.am,v
retrieving revision 1.24.4.1
retrieving revision 1.24.4.2
diff -Lsrc/gnc-module/Makefile.am -Lsrc/gnc-module/Makefile.am -u -r1.24.4.1 -r1.24.4.2
--- src/gnc-module/Makefile.am
+++ src/gnc-module/Makefile.am
@@ -1,6 +1,7 @@
 SUBDIRS = . test
 
 AM_CFLAGS = \
+   -I${top_srcdir}/lib/libc \
    -I${top_srcdir}/src \
    -I${top_srcdir}/src/core-utils \
    ${GLIB_CFLAGS} ${G_WRAP_COMPILE_ARGS} ${GUILE_INCS}
@@ -13,6 +14,7 @@
 libgncmodule_la_LIBADD = \
   ../core-utils/libcore-utils.la \
   ${G_WRAP_LINK_ARGS} \
+ ${top_builddir}/lib/libc/libc-missing.la \
   ${GLIB_LIBS} \
   -lltdl
 


More information about the gnucash-changes mailing list