Subject: | segmentation fault on solaris 10 and up |
Env-C assumes that there are no native functions for manipulating the
environment on Solaris 10, and this results in a segmentation fault when
running the test script.
The attached patch detects solaris versions that have these functions in
libc by doing the same thing that the stdlib.h header does to reveal the
prototype. Ideally the Makefile.PL would detect the functions using a
compiler check, but this seems like the simplest approach for the moment.
Subject: | Env-C.diff |
diff -ur C.xs ../C.xs
--- C.xs Mon May 23 14:00:29 2005
+++ C.xs Sat Aug 30 05:58:14 2008
@@ -6,6 +6,27 @@
#include <stdlib.h> /* setenv/getenv */
#include <stdio.h> /* sprintf */
+/* configure-less detection of unsetenv for solaris */
+#if defined(sun)
+# if defined(__EXTENSIONS__) ||\
+ (!defined(_STRICT_STDC) && !defined(__XOPEN_OR_POSIX)) || \
+ defined(_XPG6)
+# define HAVE_UNSETENV 1
+# define HAVE_SETENV 1
+# endif
+#endif
+
+#ifndef HAVE_UNSETENV
+# if !defined(WIN32) && !defined(sun) && !defined(_AIX)
+# define HAVE_UNSETENV 1
+# endif
+#endif
+#ifndef HAVE_SETENV
+# if !defined(WIN32) && !defined(sun)
+# define HAVE_SETENV 1
+# endif
+#endif
+
MODULE = Env::C PACKAGE = Env::C PREFIX = env_c_
char *
@@ -27,7 +48,7 @@
int override
CODE:
-#if defined(WIN32) || defined(sun)
+#if !HAVE_SETENV
if (override || getenv(key) == NULL) {
char *old_env = getenv( key );
char *buff = malloc(strlen(key) + strlen(val) + 2);
@@ -80,7 +101,7 @@
_putenv(buff);
free(buff);
#else
-#if !defined( sun ) && !defined( _AIX )
+#if HAVE_UNSETENV
unsetenv(key);
#else
key_len = strlen(key);
@@ -120,10 +141,3 @@
OUTPUT:
RETVAL
-
-
-
-
-
-
-
diff -ur test.pl ../test.pl
--- test.pl Tue Mar 1 20:15:44 2005
+++ test.pl Sat Aug 30 05:58:43 2008
@@ -1,27 +1,25 @@
use strict;
#use warnings;
-use Test;
-
-BEGIN { plan tests => 6 };
+use Test::More tests => 5;
use Env::C;
-ok 1 ;
# getenv
my $key = "USER";
my $val_orig = Env::C::getenv($key) || '';
-print "# [$key] '$val_orig'\n";
-ok $val_orig eq $ENV{$key} ? 1 : 0;
+is $val_orig, $ENV{$key}, "getenv matches perl ENV for $key";
# unsetenv
+diag "unsetting an env";
Env::C::unsetenv($key);
-my $val = Env::C::getenv($key) || '';
-print "# [$key] expecting '', got '$val'\n";
-ok $val eq '' ? 1 : 0;
+diag "getting it";
+my $val = Env::C::getenv($key);
+is $val, undef, "$key is no longer set in C env";
# setenv
my $val_new = "foobar";
Env::C::setenv($key, $val_new);
+diag "called setenv";
$val = Env::C::getenv($key) || '';
print "# [$key] expecting '$val_new', got '$val'\n";
ok $val eq $val_new ? 1 : 0;