You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mt...@apache.org on 2021/12/02 21:45:47 UTC

svn commit: r1895509 - in /apr/apr/trunk: locks/win32/proc_mutex.c misc/win32/env.c time/win32/time.c user/win32/userinfo.c

Author: mturk
Date: Thu Dec  2 21:45:47 2021
New Revision: 1895509

URL: http://svn.apache.org/viewvc?rev=1895509&view=rev
Log:
Stage 1 in cleaning win95 code ... cleanup utils

Modified:
    apr/apr/trunk/locks/win32/proc_mutex.c
    apr/apr/trunk/misc/win32/env.c
    apr/apr/trunk/time/win32/time.c
    apr/apr/trunk/user/win32/userinfo.c

Modified: apr/apr/trunk/locks/win32/proc_mutex.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/locks/win32/proc_mutex.c?rev=1895509&r1=1895508&r2=1895509&view=diff
==============================================================================
--- apr/apr/trunk/locks/win32/proc_mutex.c (original)
+++ apr/apr/trunk/locks/win32/proc_mutex.c Thu Dec  2 21:45:47 2021
@@ -58,19 +58,7 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
         mutexkey = NULL;
     }
 
-#if APR_HAS_UNICODE_FS
-    IF_WIN_OS_IS_UNICODE
-    {
-        hMutex = CreateMutexW(NULL, FALSE, mutexkey);
-    }
-#endif
-#if APR_HAS_ANSI_FS
-    ELSE_WIN_OS_IS_ANSI
-    {
-        hMutex = CreateMutexA(NULL, FALSE, mutexkey);
-    }
-#endif
-
+    hMutex = CreateMutexW(NULL, FALSE, mutexkey);
     if (!hMutex) {
         return apr_get_os_error();
     }
@@ -102,19 +90,7 @@ APR_DECLARE(apr_status_t) apr_proc_mutex
      */
     mutexkey = res_name_from_filename(fname, 1, pool);
 
-#if APR_HAS_UNICODE_FS
-    IF_WIN_OS_IS_UNICODE
-    {
-        hMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, mutexkey);
-    }
-#endif
-#if APR_HAS_ANSI_FS
-    ELSE_WIN_OS_IS_ANSI
-    {
-        hMutex = OpenMutexA(MUTEX_ALL_ACCESS, FALSE, mutexkey);
-    }
-#endif
-
+    hMutex = OpenMutexW(MUTEX_ALL_ACCESS, FALSE, mutexkey);
     if (!hMutex) {
         return apr_get_os_error();
     }

Modified: apr/apr/trunk/misc/win32/env.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/misc/win32/env.c?rev=1895509&r1=1895508&r2=1895509&view=diff
==============================================================================
--- apr/apr/trunk/misc/win32/env.c (original)
+++ apr/apr/trunk/misc/win32/env.c Thu Dec  2 21:45:47 2021
@@ -24,7 +24,6 @@
 #include "apr_pools.h"
 #include "apr_strings.h"
 
-#if APR_HAS_UNICODE_FS
 static apr_status_t widen_envvar_name (apr_wchar_t *buffer,
                                        apr_size_t bufflen,
                                        const char *envvar)
@@ -39,7 +38,6 @@ static apr_status_t widen_envvar_name (a
 
     return status;
 }
-#endif
 
 
 APR_DECLARE(apr_status_t) apr_env_get(char **value,
@@ -48,66 +46,36 @@ APR_DECLARE(apr_status_t) apr_env_get(ch
 {
     char *val = NULL;
     DWORD size;
-
-#if APR_HAS_UNICODE_FS
-    IF_WIN_OS_IS_UNICODE
-    {
-        apr_wchar_t wenvvar[APR_PATH_MAX];
-        apr_size_t inchars, outchars;
-        apr_wchar_t *wvalue, dummy;
-        apr_status_t status;
-
-        status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
-        if (status)
-            return status;
-
-        SetLastError(0);
-        size = GetEnvironmentVariableW(wenvvar, &dummy, 0);
-        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
-            /* The environment variable doesn't exist. */
-            return APR_ENOENT;
-
-        if (size == 0) {
-            /* The environment value exists, but is zero-length. */
-            *value = apr_pstrdup(pool, "");
-            return APR_SUCCESS;
-        }
-
-        wvalue = apr_palloc(pool, size * sizeof(*wvalue));
-        size = GetEnvironmentVariableW(wenvvar, wvalue, size);
-
-        inchars = wcslen(wvalue) + 1;
-        outchars = 3 * inchars; /* Enough for any UTF-8 representation */
-        val = apr_palloc(pool, outchars);
-        status = apr_conv_utf16_to_utf8(wvalue, &inchars, val, &outchars);
-        if (status)
-            return status;
-    }
-#endif
-#if APR_HAS_ANSI_FS
-    ELSE_WIN_OS_IS_ANSI
-    {
-        char dummy;
-
-        SetLastError(0);
-        size = GetEnvironmentVariableA(envvar, &dummy, 0);
-        if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
-            /* The environment variable doesn't exist. */
-            return APR_ENOENT;
-
-        if (size == 0) {
-            /* The environment value exists, but is zero-length. */
-            *value = apr_pstrdup(pool, "");
-            return APR_SUCCESS;
-        }
-
-        val = apr_palloc(pool, size);
-        size = GetEnvironmentVariableA(envvar, val, size);
-        if (size == 0)
-            /* Mid-air collision?. Somebody must've changed the env. var. */
-            return APR_INCOMPLETE;
-    }
-#endif
+	apr_wchar_t wenvvar[APR_PATH_MAX];
+	apr_size_t inchars, outchars;
+	apr_wchar_t *wvalue, dummy;
+	apr_status_t status;
+
+	status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
+	if (status)
+		return status;
+
+	SetLastError(0);
+	size = GetEnvironmentVariableW(wenvvar, &dummy, 0);
+	if (GetLastError() == ERROR_ENVVAR_NOT_FOUND)
+		/* The environment variable doesn't exist. */
+		return APR_ENOENT;
+
+	if (size == 0) {
+		/* The environment value exists, but is zero-length. */
+		*value = apr_pstrdup(pool, "");
+		return APR_SUCCESS;
+	}
+
+	wvalue = apr_palloc(pool, size * sizeof(*wvalue));
+	size = GetEnvironmentVariableW(wenvvar, wvalue, size);
+
+	inchars = wcslen(wvalue) + 1;
+	outchars = 3 * inchars; /* Enough for any UTF-8 representation */
+	val = apr_palloc(pool, outchars);
+	status = apr_conv_utf16_to_utf8(wvalue, &inchars, val, &outchars);
+	if (status)
+		return status;
 
     *value = val;
     return APR_SUCCESS;
@@ -118,35 +86,23 @@ APR_DECLARE(apr_status_t) apr_env_set(co
                                       const char *value,
                                       apr_pool_t *pool)
 {
-#if APR_HAS_UNICODE_FS
-    IF_WIN_OS_IS_UNICODE
-    {
-        apr_wchar_t wenvvar[APR_PATH_MAX];
-        apr_wchar_t *wvalue;
-        apr_size_t inchars, outchars;
-        apr_status_t status;
-
-        status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
-        if (status)
-            return status;
-
-        outchars = inchars = strlen(value) + 1;
-        wvalue = apr_palloc(pool, outchars * sizeof(*wvalue));
-        status = apr_conv_utf8_to_utf16(value, &inchars, wvalue, &outchars);
-        if (status)
-            return status;
-
-        if (!SetEnvironmentVariableW(wenvvar, wvalue))
-            return apr_get_os_error();
-    }
-#endif
-#if APR_HAS_ANSI_FS
-    ELSE_WIN_OS_IS_ANSI
-    {
-        if (!SetEnvironmentVariableA(envvar, value))
-            return apr_get_os_error();
-    }
-#endif
+	apr_wchar_t wenvvar[APR_PATH_MAX];
+	apr_wchar_t *wvalue;
+	apr_size_t inchars, outchars;
+	apr_status_t status;
+
+	status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
+	if (status)
+		return status;
+
+	outchars = inchars = strlen(value) + 1;
+	wvalue = apr_palloc(pool, outchars * sizeof(*wvalue));
+	status = apr_conv_utf8_to_utf16(value, &inchars, wvalue, &outchars);
+	if (status)
+		return status;
+
+	if (!SetEnvironmentVariableW(wenvvar, wvalue))
+		return apr_get_os_error();
 
     return APR_SUCCESS;
 }
@@ -154,27 +110,15 @@ APR_DECLARE(apr_status_t) apr_env_set(co
 
 APR_DECLARE(apr_status_t) apr_env_delete(const char *envvar, apr_pool_t *pool)
 {
-#if APR_HAS_UNICODE_FS
-    IF_WIN_OS_IS_UNICODE
-    {
-        apr_wchar_t wenvvar[APR_PATH_MAX];
-        apr_status_t status;
-
-        status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
-        if (status)
-            return status;
-
-        if (!SetEnvironmentVariableW(wenvvar, NULL))
-            return apr_get_os_error();
-    }
-#endif
-#if APR_HAS_ANSI_FS
-    ELSE_WIN_OS_IS_ANSI
-    {
-        if (!SetEnvironmentVariableA(envvar, NULL))
-            return apr_get_os_error();
-    }
-#endif
+	apr_wchar_t wenvvar[APR_PATH_MAX];
+	apr_status_t status;
+
+	status = widen_envvar_name(wenvvar, APR_PATH_MAX, envvar);
+	if (status)
+		return status;
+
+	if (!SetEnvironmentVariableW(wenvvar, NULL))
+		return apr_get_os_error();
 
     return APR_SUCCESS;
 }

Modified: apr/apr/trunk/time/win32/time.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/time/win32/time.c?rev=1895509&r1=1895508&r2=1895509&view=diff
==============================================================================
--- apr/apr/trunk/time/win32/time.c (original)
+++ apr/apr/trunk/time/win32/time.c Thu Dec  2 21:45:47 2021
@@ -136,84 +136,43 @@ APR_DECLARE(apr_status_t) apr_time_exp_l
 {
     SYSTEMTIME st;
     FILETIME ft, localft;
+	TIME_ZONE_INFORMATION *tz;
+	SYSTEMTIME localst;
+	apr_time_t localtime;
 
     AprTimeToFileTime(&ft, input);
 
-#if APR_HAS_UNICODE_FS
-    IF_WIN_OS_IS_UNICODE
-    {
-        TIME_ZONE_INFORMATION *tz;
-        SYSTEMTIME localst;
-        apr_time_t localtime;
-
-        get_local_timezone(&tz);
-
-        FileTimeToSystemTime(&ft, &st);
-
-        /* The Platform SDK documents that SYSTEMTIME/FILETIME are
-         * generally UTC.  We use SystemTimeToTzSpecificLocalTime
-         * because FileTimeToLocalFileFime is documented that the
-         * resulting time local file time would have DST relative
-         * to the *present* date, not the date converted.
-         * The time value makes a roundtrip, localst cannot be invalid below.
-         */
-        SystemTimeToTzSpecificLocalTime(tz, &st, &localst);
-        SystemTimeToAprExpTime(result, &localst);
-        result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
-
-
-        /* Recover the resulting time as an apr time and use the
-         * delta for gmtoff in seconds (and ignore msec rounding) 
-         */
-        SystemTimeToFileTime(&localst, &localft);
-        FileTimeToAprTime(&localtime, &localft);
-        result->tm_gmtoff = (int)apr_time_sec(localtime) 
-                          - (int)apr_time_sec(input);
-
-        /* To compute the dst flag, we compare the expected 
-         * local (standard) timezone bias to the delta.
-         * [Note, in war time or double daylight time the
-         * resulting tm_isdst is, desireably, 2 hours]
-         */
-        result->tm_isdst = (result->tm_gmtoff / 3600)
-                         - (-(tz->Bias + tz->StandardBias) / 60);
-    }
-#endif
-#if APR_HAS_ANSI_FS
-    ELSE_WIN_OS_IS_ANSI
-    {
-        TIME_ZONE_INFORMATION tz;
-	/* XXX: This code is simply *wrong*.  The time converted will always
-         * map to the *now current* status of daylight savings time.
-         * The time value makes a roundtrip, st cannot be invalid below.
-         */
-
-        FileTimeToLocalFileTime(&ft, &localft);
-        FileTimeToSystemTime(&localft, &st);
-        SystemTimeToAprExpTime(result, &st);
-        result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
-
-        switch (GetTimeZoneInformation(&tz)) {
-            case TIME_ZONE_ID_UNKNOWN:
-                result->tm_isdst = 0;
-                /* Bias = UTC - local time in minutes
-                 * tm_gmtoff is seconds east of UTC
-                 */
-                result->tm_gmtoff = tz.Bias * -60;
-                break;
-            case TIME_ZONE_ID_STANDARD:
-                result->tm_isdst = 0;
-                result->tm_gmtoff = (tz.Bias + tz.StandardBias) * -60;
-                break;
-            case TIME_ZONE_ID_DAYLIGHT:
-                result->tm_isdst = 1;
-                result->tm_gmtoff = (tz.Bias + tz.DaylightBias) * -60;
-                break;
-            default:
-                /* noop */;
-        }
-    }
-#endif
+	get_local_timezone(&tz);
+
+	FileTimeToSystemTime(&ft, &st);
+
+	/* The Platform SDK documents that SYSTEMTIME/FILETIME are
+	 * generally UTC.  We use SystemTimeToTzSpecificLocalTime
+	 * because FileTimeToLocalFileFime is documented that the
+	 * resulting time local file time would have DST relative
+	 * to the *present* date, not the date converted.
+	 * The time value makes a roundtrip, localst cannot be invalid below.
+	 */
+	SystemTimeToTzSpecificLocalTime(tz, &st, &localst);
+	SystemTimeToAprExpTime(result, &localst);
+	result->tm_usec = (apr_int32_t) (input % APR_USEC_PER_SEC);
+
+
+	/* Recover the resulting time as an apr time and use the
+	 * delta for gmtoff in seconds (and ignore msec rounding) 
+	 */
+	SystemTimeToFileTime(&localst, &localft);
+	FileTimeToAprTime(&localtime, &localft);
+	result->tm_gmtoff = (int)apr_time_sec(localtime) 
+					  - (int)apr_time_sec(input);
+
+	/* To compute the dst flag, we compare the expected 
+	 * local (standard) timezone bias to the delta.
+	 * [Note, in war time or double daylight time the
+	 * resulting tm_isdst is, desireably, 2 hours]
+	 */
+	result->tm_isdst = (result->tm_gmtoff / 3600)
+					 - (-(tz->Bias + tz->StandardBias) / 60);
 
     return APR_SUCCESS;
 }

Modified: apr/apr/trunk/user/win32/userinfo.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/user/win32/userinfo.c?rev=1895509&r1=1895508&r2=1895509&view=diff
==============================================================================
--- apr/apr/trunk/user/win32/userinfo.c (original)
+++ apr/apr/trunk/user/win32/userinfo.c Thu Dec  2 21:45:47 2021
@@ -97,57 +97,31 @@ APR_DECLARE(apr_status_t) apr_uid_homepa
                            KEY_QUERY_VALUE, &key)) != ERROR_SUCCESS)
         return APR_FROM_OS_ERROR(rv);
 
-#if APR_HAS_UNICODE_FS
-    IF_WIN_OS_IS_UNICODE
-    {
-        keylen = sizeof(regkey);
-        rv = RegQueryValueExW(key, L"ProfileImagePath", NULL, &type,
-                                   (void*)regkey, &keylen);
-        RegCloseKey(key);
-        if (rv != ERROR_SUCCESS)
-            return APR_FROM_OS_ERROR(rv);
-        if (type == REG_SZ) {
-            char retdir[MAX_PATH];
-            if ((rv = unicode_to_utf8_path(retdir, sizeof(retdir), 
-                                           (apr_wchar_t*)regkey)) != APR_SUCCESS)
-                return rv;
-            *dirname = apr_pstrdup(p, retdir);
-        }
-        else if (type == REG_EXPAND_SZ) {
-            apr_wchar_t path[MAX_PATH];
-            char retdir[MAX_PATH];
-            ExpandEnvironmentStringsW((apr_wchar_t*)regkey, path, 
-                                      sizeof(path) / 2);
-            if ((rv = unicode_to_utf8_path(retdir, sizeof(retdir), path))
-                    != APR_SUCCESS)
-                return rv;
-            *dirname = apr_pstrdup(p, retdir);
-        }
-        else
-            return APR_ENOENT;
-    }
-#endif
-#if APR_HAS_ANSI_FS
-    ELSE_WIN_OS_IS_ANSI
-    {
-        keylen = sizeof(regkey);
-        rv = RegQueryValueEx(key, "ProfileImagePath", NULL, &type,
-                                  (void*)regkey, &keylen);
-        RegCloseKey(key);
-        if (rv != ERROR_SUCCESS)
-            return APR_FROM_OS_ERROR(rv);
-        if (type == REG_SZ) {
-            *dirname = apr_pstrdup(p, regkey);
-        }
-        else if (type == REG_EXPAND_SZ) {
-            char path[MAX_PATH];
-            ExpandEnvironmentStrings(regkey, path, sizeof(path));
-            *dirname = apr_pstrdup(p, path);
-        }
-        else
-            return APR_ENOENT;
-    }
-#endif /* APR_HAS_ANSI_FS */
+	keylen = sizeof(regkey);
+	rv = RegQueryValueExW(key, L"ProfileImagePath", NULL, &type,
+							   (void*)regkey, &keylen);
+	RegCloseKey(key);
+	if (rv != ERROR_SUCCESS)
+		return APR_FROM_OS_ERROR(rv);
+	if (type == REG_SZ) {
+		char retdir[MAX_PATH];
+		if ((rv = unicode_to_utf8_path(retdir, sizeof(retdir), 
+									   (apr_wchar_t*)regkey)) != APR_SUCCESS)
+			return rv;
+		*dirname = apr_pstrdup(p, retdir);
+	}
+	else if (type == REG_EXPAND_SZ) {
+		apr_wchar_t path[MAX_PATH];
+		char retdir[MAX_PATH];
+		ExpandEnvironmentStringsW((apr_wchar_t*)regkey, path, 
+								  sizeof(path) / 2);
+		if ((rv = unicode_to_utf8_path(retdir, sizeof(retdir), path))
+				!= APR_SUCCESS)
+			return rv;
+		*dirname = apr_pstrdup(p, retdir);
+	}
+	else
+		return APR_ENOENT;
     for (fixch = *dirname; *fixch; ++fixch)
         if (*fixch == '\\')
             *fixch = '/';