$OpenBSD: patch-jdk_src_solaris_native_java_util_TimeZone_md_c,v 1.3 2009/10/07 01:53:54 kurt Exp $
--- jdk/src/solaris/native/java/util/TimeZone_md.c.orig	Thu Sep 17 03:52:32 2009
+++ jdk/src/solaris/native/java/util/TimeZone_md.c	Sun Sep 27 10:26:02 2009
@@ -31,7 +31,7 @@
 #include <errno.h>
 #include <stddef.h>
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
 #include <string.h>
 #include <dirent.h>
 #include <sys/stat.h>
@@ -49,7 +49,11 @@
 #define fileclose       fclose
 #endif
 
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+
 #ifdef __linux__
+static const char *sysconfig_clock_file = "/etc/sysconfig/clock";
+#endif
 
 static const char *ETC_TIMEZONE_FILE = "/etc/timezone";
 static const char *ZONEINFO_DIR = "/usr/share/zoneinfo";
@@ -199,7 +203,9 @@ getPlatformTimeZoneID()
     int fd;
     char *buf;
     size_t size;
+    char zoneinfo_file[PATH_MAX+1];
 
+#ifdef __linux__
     /*
      * Try reading the /etc/timezone file for Debian distros. There's
      * no spec of the file format available. This parsing assumes that
@@ -223,6 +229,7 @@ getPlatformTimeZoneID()
             return tz;
         }
     }
+#endif /* __linux__ */
 
     /*
      * Next, try /etc/localtime to find the zone ID.
@@ -231,6 +238,10 @@ getPlatformTimeZoneID()
         return NULL;
     }
 
+    strncpy(zoneinfo_file, DEFAULT_ZONEINFO_FILE, PATH_MAX);
+    zoneinfo_file[PATH_MAX] = '\0';
+
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     /*
      * If it's a symlink, get the link name and its zone ID part. (The
      * older versions of timeconfig created a symlink as described in
@@ -239,21 +250,25 @@ getPlatformTimeZoneID()
      * from /etc/localtime.)
      */
     if (S_ISLNK(statbuf.st_mode)) {
-        char linkbuf[PATH_MAX+1];
         int len;
 
-        if ((len = readlink(DEFAULT_ZONEINFO_FILE, linkbuf, sizeof(linkbuf)-1)) == -1) {
+	if ((len = readlink(DEFAULT_ZONEINFO_FILE, zoneinfo_file, sizeof(zoneinfo_file)-1)) == -1) {
             jio_fprintf(stderr, (const char *) "can't get a symlink of %s\n",
                         DEFAULT_ZONEINFO_FILE);
             return NULL;
         }
-        linkbuf[len] = '\0';
-        tz = getZoneName(linkbuf);
+	zoneinfo_file[len] = '\0';
+	tz = getZoneName(zoneinfo_file);
         if (tz != NULL) {
             tz = strdup(tz);
+	    return tz;
+	} else {
+	    if (lstat(zoneinfo_file, &statbuf) == -1) {
+		return NULL;
+	    }
         }
-        return tz;
     }
+#endif /* __linux__ || _ALLBSD_SOURCE */
 
     /*
      * If it's a regular file, we need to find out the same zoneinfo file
@@ -264,7 +279,7 @@ getPlatformTimeZoneID()
     if (buf == NULL) {
         return NULL;
     }
-    if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
+    if ((fd = open(zoneinfo_file, O_RDONLY)) == -1) {
         free((void *) buf);
         return NULL;
     }
@@ -493,7 +508,7 @@ findJavaTZ_md(const char *java_home_dir, const char *c
 
     tz = getenv("TZ");
 
-#ifdef __linux__
+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
     if (tz == NULL) {
 #else
 #ifdef __solaris__
@@ -532,19 +547,32 @@ getGMTOffsetID()
 {
     time_t offset;
     char sign, buf[16];
+#if defined(_ALLBSD_SOURCE)
+    struct tm *local_tm;
+    time_t clock;
+ 
+    clock = time(NULL);
+    tzset();
+    local_tm = localtime(&clock);
+    if (local_tm->tm_gmtoff >= 0) {
+	offset = (time_t) local_tm->tm_gmtoff;
+	sign = "+";
+    } else {
+	offset = (time_t) -local_tm->tm_gmtoff;
+	sign = "-";
+    }
+#else
 
     if (timezone == 0) {
         return strdup("GMT");
-    }
-
-    /* Note that the time offset direction is opposite. */
-    if (timezone > 0) {
+    } else if (timezone > 0) {
         offset = timezone;
         sign = '-';
     } else {
         offset = -timezone;
         sign = '+';
     }
+#endif
     sprintf(buf, (const char *)"GMT%c%02d:%02d",
             sign, (int)(offset/3600), (int)((offset%3600)/60));
     return strdup(buf);
