~ chicken-core (master) 15b5e61de07728cc0d312259021177d8c67d4ab4
commit 15b5e61de07728cc0d312259021177d8c67d4ab4
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Mon Aug 4 19:00:59 2025 +0100
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Mon Aug 4 19:00:59 2025 +0100
convert paths from getcwd and readdir to use slashes, also handle executable-path
diff --git a/file.scm b/file.scm
index 045ac615..f3e62d13 100644
--- a/file.scm
+++ b/file.scm
@@ -82,8 +82,13 @@ static C_word C_rename(C_word old, C_word new) {
static C_word C_foundfile(C_word e,C_word b,C_word l) {
C_char *s = C_utf8(((struct _wdirent *)C_block_item(e, 0))->d_name);
+ C_char *p = s;
+ while(*p != 0) {
+ *p = *p == '\\' ? '/' : *p;
+ ++p;
+ }
C_strlcpy(C_c_string(b), s, C_unfix(l));
- return(C_fix(strlen(s)));
+ return(C_fix(C_strlen(s)));
}
# define C_readdir(h,e) C_set_block_item(e, 0, (C_word) _wreaddir((_WDIR *)C_block_item(h, 0)))
# define C_closedir(h) (_wclosedir((_WDIR *)C_block_item(h, 0)), C_SCHEME_UNDEFINED)
diff --git a/library.scm b/library.scm
index a95817a2..fd2b0620 100644
--- a/library.scm
+++ b/library.scm
@@ -6902,9 +6902,30 @@ EOF
;;; Accessing process information (cwd, environ, etc.)
#>
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <direct.h>
-#define C_chdir(str) C_fix(chdir(C_c_string(str)))
-#define C_curdir(buf, size) (getcwd(C_c_string(buf), size) ? C_fix(strlen(C_c_string(buf))) : C_SCHEME_FALSE)
+static C_word C_chdir(C_word str) {
+ return C_fix(_wchdir(C_utf16(str, 0)));
+}
+
+static C_word C_curdir(C_word buf, C_word size) {
+ C_WCHAR *cwd = _wgetcwd((C_WCHAR *)C_c_string(buf), C_unfix(size));
+ if(cwd == NULL) return C_SCHEME_FALSE;
+ C_char *up = C_utf8(cwd);
+ C_char *p = up;
+ while(*p) {
+ *p = *p == '\\' ? '/' : *p;
+ ++p;
+ }
+ int len = C_strlen(up);
+ C_memcpy(cwd, up, len + 1);
+ return C_fix(len);
+}
+#else
+# define C_chdir(str) C_fix(chdir(C_c_string(str)))
+# define C_curdir(buf, size) (getcwd(C_c_string(buf), size) ? C_fix(strlen(C_c_string(buf))) : C_SCHEME_FALSE)
+#endif
<#
diff --git a/runtime.c b/runtime.c
index 00cd6677..084c7a4f 100644
--- a/runtime.c
+++ b/runtime.c
@@ -12825,11 +12825,7 @@ C_executable_dirname() {
if((path = C_executable_pathname()) == NULL)
return NULL;
-#if defined(_WIN32) && !defined(__CYGWIN__)
- for(len = C_strlen(path); len >= 0 && path[len] != '\\'; len--);
-#else
- for(len = C_strlen(path); len >= 0 && path[len] != '/'; len--);
-#endif
+ for(len = C_strlen(path); len >= 0 && path[len] != '/' && path[len] != '\\'; len--);
path[len] = '\0';
return path;
@@ -12866,6 +12862,11 @@ C_resolve_executable_pathname(C_char *fname)
C_char *buf2 = C_strdup(C_utf8(buffer));
C_free(buffer);
+ C_char *p = buf2;
+ while(*p) {
+ *p = *p == '\\' ? '/' : *p;
+ ++p;
+ }
return buf2;
#elif defined(C_MACOSX)
C_char buf[C_MAX_PATH];
Trap