From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jan Nieuwenhuizen Newsgroups: gmane.lisp.guile.devel Subject: [PATCH 1/5] [mingw]: Add implementation of canonicalize_file_name. Date: Tue, 15 Feb 2011 16:34:59 +0100 Message-ID: <1297784103-18322-2-git-send-email-janneke-list@xs4all.nl> References: <1297784103-18322-1-git-send-email-janneke-list@xs4all.nl> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1297784125 13983 80.91.229.12 (15 Feb 2011 15:35:25 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 15 Feb 2011 15:35:25 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Feb 15 16:35:21 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PpMvs-0007rX-Mp for guile-devel@m.gmane.org; Tue, 15 Feb 2011 16:35:16 +0100 Original-Received: from localhost ([127.0.0.1]:49692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpMvr-0002H9-Qu for guile-devel@m.gmane.org; Tue, 15 Feb 2011 10:35:15 -0500 Original-Received: from [140.186.70.92] (port=56890 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PpMvo-0002Gb-3M for guile-devel@gnu.org; Tue, 15 Feb 2011 10:35:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PpMvm-0005sr-RS for guile-devel@gnu.org; Tue, 15 Feb 2011 10:35:11 -0500 Original-Received: from smtp-vbr19.xs4all.nl ([194.109.24.39]:2914) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PpMvm-0005s6-E1 for guile-devel@gnu.org; Tue, 15 Feb 2011 10:35:10 -0500 Original-Received: from vuurvlieg.flower (peder.onsbrabantnet.nl [88.159.206.46] (may be forged)) (authenticated bits=0) by smtp-vbr19.xs4all.nl (8.13.8/8.13.8) with ESMTP id p1FFZ8QX082257 for ; Tue, 15 Feb 2011 16:35:09 +0100 (CET) (envelope-from janneke-list@xs4all.nl) X-Mailer: git-send-email 1.7.1 In-Reply-To: <1297784103-18322-1-git-send-email-janneke-list@xs4all.nl> X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-operating-system: by eggs.gnu.org: FreeBSD 4.6-4.9 X-Received-From: 194.109.24.39 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11642 Archived-At: From: Jan Nieuwenhuizen It does not look like this will be fixed any time soon in gnulib. 2011-02-04 Jan Nieuwenhuizen * 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 +#include +#include + +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 | GNU LilyPond http://lilypond.org Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.nl