From: Jan Nieuwenhuizen <jann...@gnu.org> It does not look like this will be fixed any time soon in gnulib.
2011-02-04 Jan Nieuwenhuizen <jann...@gnu.org> * libguile/filesys.h: * libguile/filesys.c (mingw_canonicalize_file_name)[__MINGW32__]: Add minimal implementation of canonicalize_file_name for Mingw. --- libguile/filesys.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ libguile/filesys.h | 6 ++++ 2 files changed, 74 insertions(+), 0 deletions(-) diff --git a/libguile/filesys.c b/libguile/filesys.c index 68d90d9..93b0ce2 100644 --- a/libguile/filesys.c +++ b/libguile/filesys.c @@ -1631,6 +1631,74 @@ SCM_DEFINE (scm_basename, "basename", 1, 1, 0, } #undef FUNC_NAME +#ifdef __MINGW32__ +/* gnulib's canonicalize_file_name silently fails on Mingw. */ +#include <ctype.h> +#include <direct.h> +#include <windows.h> + +static char const * +slashify (char const *str) +{ + char *p = (char*)str; + + while (*p) + { + if (*p == '\\') + *p = '/'; + p++; + } + return str; +} + +static char const * +strlower (char const *str) +{ + char *p = str; + while (*p) + { + *p = (char)tolower (*p); + p++; + } + return str; +} + +static char * +mingw_realpath (char const *name, char *resolved) +{ + char *rpath = NULL; + + if (name == NULL || name[0] == '\0') + return NULL; + + if (resolved == NULL) + { + rpath = malloc (PATH_MAX + 1); + if (rpath == NULL) + return NULL; + } + else + rpath = resolved; + + GetFullPathName (name, PATH_MAX, rpath, NULL); + strlower (slashify (rpath)); + struct stat st; + if (lstat (rpath, &st) < 0) + { + if (resolved == NULL) + free (rpath); + return NULL; + } + return rpath; +} + +char * +mingw_canonicalize_file_name (char const *name) +{ + return mingw_realpath (name, NULL); +} +#endif /* __MINGW32__ */ + SCM_DEFINE (scm_canonicalize_path, "canonicalize-path", 1, 0, 0, (SCM path), "Return the canonical path of @var{path}. A canonical path has\n" diff --git a/libguile/filesys.h b/libguile/filesys.h index 967ce74..2f11e85 100644 --- a/libguile/filesys.h +++ b/libguile/filesys.h @@ -27,6 +27,12 @@ +#ifdef __MINGW32__ +extern char *mingw_canonicalize_file_name (char const *name); +#undef canonicalize_file_name +#define canonicalize_file_name mingw_canonicalize_file_name +#endif /* __MINGW32__ */ + SCM_API scm_t_bits scm_tc16_dir; #define SCM_DIR_FLAG_OPEN (1L << 0) -- 1.7.1 -- Jan Nieuwenhuizen <jann...@gnu.org> | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | Avatar® http://AvatarAcademy.nl