From: Bruno Haible Date: Sat, 13 Sep 2008 10:23:29 +0000 (+0200) Subject: Make glob work on mingw. X-Git-Tag: v0.1~7059 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=de13d0db8009d9e97b55113fc5cf5dc1cde72ecd;p=gnulib.git Make glob work on mingw. --- diff --git a/ChangeLog b/ChangeLog index 74acd3532..fa4447556 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-09-13 Yoann Vandoorselaere + Bruno Haible + + * lib/glob.c: Don't include on native Windows. + (WINDOWS32): New macro. + (glob) [WINDOW32]: Provide a reasonable replacement for getenv("HOME"). + 2008-09-13 Bruno Haible * lib/glthread/cond.h [USE_SOLARIS_THREADS] diff --git a/lib/glob.c b/lib/glob.c index 24aec87f9..c38ee4c3d 100644 --- a/lib/glob.c +++ b/lib/glob.c @@ -43,7 +43,13 @@ # define POSIX #endif -#include +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +# define WINDOWS32 +#endif + +#ifndef WINDOWS32 +# include +#endif #include #ifndef __set_errno @@ -565,8 +571,26 @@ glob (pattern, flags, errfunc, pglob) home_dir = "SYS:"; # else # ifdef WINDOWS32 + /* Windows NT defines HOMEDRIVE and HOMEPATH. But give preference + to HOME, because the user can change HOME. */ if (home_dir == NULL || home_dir[0] == '\0') - home_dir = "c:/users/default"; /* poor default */ + { + const char *home_drive = getenv ("HOMEDRIVE"); + const char *home_path = getenv ("HOMEPATH"); + + if (home_drive != NULL && home_path != NULL) + { + size_t home_drive_len = strlen (home_drive); + size_t home_path_len = strlen (home_path); + char *mem = alloca (home_drive_len + home_path_len + 1); + + memcpy (mem, home_drive, home_drive_len); + memcpy (mem + home_drive_len, home_path, home_path_len + 1); + home_dir = mem; + } + else + home_dir = "c:/users/default"; /* poor default */ + } # else if (home_dir == NULL || home_dir[0] == '\0') {