[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH]: glob win32 compatibility fixes
From: |
Bruno Haible |
Subject: |
Re: [PATCH]: glob win32 compatibility fixes |
Date: |
Sat, 13 Sep 2008 12:23:17 +0200 |
User-agent: |
KMail/1.5.4 |
Yoann Vandoorselaere wrote:
> Thanks for the quick review, updated path attached!
I made the following modifications:
- Use WINDOWS32 macro instead of USE_WIN32. This minimizes the diffs with
glibc, for easier sync in the future.
- Use alloca() instead of a fixed-size buffer.
- Change to GNU coding style.
and applied this:
2008-09-13 Yoann Vandoorselaere <address@hidden>
Bruno Haible <address@hidden>
* lib/glob.c: Don't include <pwd.h> on native Windows.
(WINDOWS32): New macro.
(glob) [WINDOW32]: Provide a reasonable replacement for getenv("HOME").
*** lib/glob.c.orig 2008-09-13 12:22:48.000000000 +0200
--- lib/glob.c 2008-09-13 12:22:44.000000000 +0200
***************
*** 43,49 ****
# define POSIX
#endif
! #include <pwd.h>
#include <errno.h>
#ifndef __set_errno
--- 43,55 ----
# define POSIX
#endif
! #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
! # define WINDOWS32
! #endif
!
! #ifndef WINDOWS32
! # include <pwd.h>
! #endif
#include <errno.h>
#ifndef __set_errno
***************
*** 565,572 ****
home_dir = "SYS:";
# else
# ifdef WINDOWS32
if (home_dir == NULL || home_dir[0] == '\0')
! home_dir = "c:/users/default"; /* poor default */
# else
if (home_dir == NULL || home_dir[0] == '\0')
{
--- 571,596 ----
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')
! {
! 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')
{