From 1edd51e77982ebce33b165e481da8df3f7ec813a Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Mon, 30 Aug 2021 12:20:03 +0200 Subject: [PATCH] Drop custom opendir/readdir implementation in Windows Windows doesn't have these functions, but MinGW provides them as part of its crt library. Our own stub implementation had some issues which caused an error to trigger a loop which resulted in a hanging process when running chicken-install -update-db --- NEWS | 3 ++- file.scm | 82 ++------------------------------------------------------ 2 files changed, 4 insertions(+), 81 deletions(-) diff --git a/NEWS b/NEWS index c30c4395..00e79659 100644 --- a/NEWS +++ b/NEWS @@ -3,7 +3,8 @@ - Core libraries - The srfi-17 module now exports the `getter-with-setter` and `setter` procedures, not just the set! macro (thanks to Lassi Kortela) - + - Fix hang in chicken-install -update-db on Windows (thanks to Mark + Fisher for reporting and Jani Hakala for debugging and patch). 5.3.0rc1 diff --git a/file.scm b/file.scm index 18ce00f1..56e4c909 100644 --- a/file.scm +++ b/file.scm @@ -65,86 +65,8 @@ # define C_mkdir(str) C_fix(mkdir(C_c_string(str))) #endif -#if !defined(_WIN32) || defined(__CYGWIN__) -# include -# include -#else -struct dirent -{ - char * d_name; -}; - -typedef struct -{ - struct _finddata_t fdata; - int handle; - struct dirent current; -} DIR; - -static DIR * C_fcall -opendir(const char *name) -{ - int name_len = strlen(name); - int what_len = name_len + 3; - DIR *dir = (DIR *)malloc(sizeof(DIR)); - char *what; - if (!dir) - { - errno = ENOMEM; - return NULL; - } - what = (char *)malloc(what_len); - if (!what) - { - free(dir); - errno = ENOMEM; - return NULL; - } - C_strlcpy(what, name, what_len); - if (strchr("\\/", name[name_len - 1])) - C_strlcat(what, "*", what_len); - else - C_strlcat(what, "\\*", what_len); - - dir->handle = _findfirst(what, &dir->fdata); - if (dir->handle == -1) - { - free(what); - free(dir); - return NULL; - } - dir->current.d_name = NULL; /* as the first-time indicator */ - free(what); - return dir; -} - -static int C_fcall -closedir(DIR * dir) -{ - if (dir) - { - int res = _findclose(dir->handle); - free(dir); - return res; - } - return -1; -} - -static struct dirent * C_fcall -readdir(DIR * dir) -{ - if (dir) - { - if (!dir->current.d_name /* first time after opendir */ - || _findnext(dir->handle, &dir->fdata) != -1) - { - dir->current.d_name = dir->fdata.name; - return &dir->current; - } - } - return NULL; -} -#endif +#include +#include #define C_opendir(s,h) C_set_block_item(h, 0, (C_word) opendir(C_c_string(s))) #define C_readdir(h,e) C_set_block_item(e, 0, (C_word) readdir((DIR *)C_block_item(h, 0))) -- 2.31.1