Mercurial > hg > octave-lyh > gnulib-hg
changeset 10423:51c125f4cd8d
Make glob work on mingw.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 13 Sep 2008 12:23:29 +0200 |
parents | f52b084922aa |
children | bee99b6a668d |
files | ChangeLog lib/glob.c |
diffstat | 2 files changed, 33 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-09-13 Yoann Vandoorselaere <yoann.v@prelude-ids.com> + Bruno Haible <bruno@clisp.org> + + * lib/glob.c: Don't include <pwd.h> on native Windows. + (WINDOWS32): New macro. + (glob) [WINDOW32]: Provide a reasonable replacement for getenv("HOME"). + 2008-09-13 Bruno Haible <bruno@clisp.org> * lib/glthread/cond.h [USE_SOLARIS_THREADS]
--- 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 @@ 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') {