summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2008-09-13 12:23:29 +0200
committerBruno Haible <bruno@clisp.org>2008-09-13 12:23:29 +0200
commitde13d0db8009d9e97b55113fc5cf5dc1cde72ecd (patch)
treeb4cf3da94ff08a9283241e3cab50939e14efee53 /lib
parent9036fbd9f324256fee4b0f2259bdc8bb5a5eac04 (diff)
downloadgnulib-de13d0db8009d9e97b55113fc5cf5dc1cde72ecd.tar.gz
Make glob work on mingw.
Diffstat (limited to 'lib')
-rw-r--r--lib/glob.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/glob.c b/lib/glob.c
index 24aec87f91..c38ee4c3dd 100644
--- a/lib/glob.c
+++ b/lib/glob.c
@@ -43,7 +43,13 @@
# define POSIX
#endif
-#include <pwd.h>
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define WINDOWS32
+#endif
+
+#ifndef WINDOWS32
+# include <pwd.h>
+#endif
#include <errno.h>
#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')
{