>From 23ef478b5cc2bdf97b30cd973ee5da21fbfb3d74 Mon Sep 17 00:00:00 2001 From: Mario Domenech Goulart Date: Sat, 9 Nov 2013 12:32:46 -0200 Subject: [PATCH] Fix unsetenv on Windows Environment variables were not really being unset on Windows. Assume the following code: (use posix) (setenv "FOO" "bar") (print "1 " (get-environment-variable "FOO")) (unsetenv "FOO") (print "2 " (get-environment-variable "FOO")) Before this patch, the output was: 1 bar 2 bar After this patch, the output is: 1 bar 2 #f as expected. This patch only affects Windows systems. --- NEWS | 1 + posixwin.scm | 4 +++- tests/posix-tests.scm | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 17a4f69..2f1e06d 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ use modules and forgot to require ports but use procedures from it. - Support has been added for the space-safe R7RS macro "delay-force". - Export file-type from the posix unit (thanks to Alan Post). + - unsetenv has been fixed on Windows - Platform support - CHICKEN can now be built on AIX (contributed by Erik Falor) diff --git a/posixwin.scm b/posixwin.scm index 753bd4b..d86dfb1 100644 --- a/posixwin.scm +++ b/posixwin.scm @@ -1384,7 +1384,9 @@ EOF (define (unsetenv var) (##sys#check-string var 'unsetenv) - (##core#inline "C_putenv" (##sys#make-c-string var 'unsetenv)) + (##core#inline "C_setenv" + (##sys#make-c-string var 'setenv) + (##sys#make-c-string "")) (##core#undefined) ) (define get-environment-variables diff --git a/tests/posix-tests.scm b/tests/posix-tests.scm index 6ee8993..f227397 100644 --- a/tests/posix-tests.scm +++ b/tests/posix-tests.scm @@ -50,3 +50,9 @@ (delete-directory tmp-dir 'recursively) (assert (not (directory-exists? tmp-dot))) (assert (not (directory-exists? tmp-dir)))) + +;; unsetenv +(setenv "FOO" "bar") +(assert (equal? (get-environment-variable "FOO") "bar")) +(unsetenv "FOO") +(assert (not (get-environment-variable "FOO"))) -- 1.7.10.4