[Ecls-list] Patch proposal for user-homedir-pathname on Windows

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Mon Aug 25 14:04:22 UTC 2008


Hi Claus,

thanks for your patch. I have slightly improved it so that it does not
use C to allocate objects, but rather the ECL functions. This has two
reasons: first, memory allocated with malloc() is not garbage
collected and may be leaked when the object is not reachable; second,
it is much simpler! You can use the full power of Common Lisp to
manipulate lisp objects without caring about low level details.

This patch has been committed and should be available in anonymous CVS
any time soon.

Juanjo

diff --git a/src/c/unixfsys.d b/src/c/unixfsys.d
index 9cc169f..9482711 100644
--- a/src/c/unixfsys.d
+++ b/src/c/unixfsys.d
@@ -483,12 +483,8 @@ ecl_homedir_pathname(cl_object user)
 {
 	cl_index i;
 	cl_object namestring;
-
-	if (Null(user)) {
-		char *h = getenv("HOME");
-		namestring = (h == NULL)? make_constant_base_string("/")
-			: make_base_string_copy(h);
-	} else {
+	const char *h, *d;
+	If (!Null(user)) {
 #ifdef HAVE_PWD_H
 		struct passwd *pwent = NULL;
 #endif
@@ -511,6 +507,17 @@ ecl_homedir_pathname(cl_object user)
 		namestring = make_base_string_copy(pwent->pw_dir);
 #endif
 		FEerror("Unknown user ~S.", 1, p);
+	} else if ((h = getenv("HOME"))) {
+		namestring = make_base_string_copy(h);
+#ifdef _MSC_VER
+	} else if ((h = getenv("HOMEPATH")) && (d = getenv("HOMEDRIVE"))) {
+		namestring =
+			si_base_string_concatenate(2,
+						   make_constant_base_string(h),
+						   make_constant_base_string(d));
+#endif
+	} else {
+		namestring = make_constant_base_string("/");
 	}
 	if (namestring->base_string.self[0] == '~') {
 		FEerror("Not a valid home pathname ~S", 1, namestring);

-- 
Instituto de Física Fundamental
CSIC, Serrano, 113, Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com


More information about the ecl-devel mailing list