< prev index next >

src/java.base/unix/native/libjava/TimeZone_md.c

Print this page
rev 59383 : [mq]: final

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -33,13 +33,10 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <string.h>
 #include <dirent.h>
 #include <unistd.h>
-#if defined(__solaris__)
-#include <libscf.h>
-#endif
 
 #include "jvm.h"
 #include "TimeZone_md.h"
 
 static char *isFileIdentical(char* buf, size_t size, char *pathname);

@@ -50,15 +47,13 @@
   do { \
     _result = _cmd; \
   } while((_result == -1) && (errno == EINTR)); \
 } while(0)
 
-#if !defined(__solaris__) || defined(__sparcv9) || defined(amd64)
 #define fileopen        fopen
 #define filegets        fgets
 #define fileclose       fclose
-#endif
 
 #if defined(_ALLBSD_SOURCE)
 #define stat64 stat
 #define lstat64 lstat
 #define fstat64 fstat

@@ -78,11 +73,11 @@
 
 #if defined(_AIX)
 static const char *ETC_ENVIRONMENT_FILE = "/etc/environment";
 #endif
 
-#if defined(__linux__) || defined(MACOSX) || defined(__solaris__)
+#if defined(__linux__) || defined(MACOSX)
 
 /*
  * Returns a pointer to the zone ID portion of the given zoneinfo file
  * name, or NULL if the given string doesn't contain "zoneinfo/".
  */

@@ -162,17 +157,10 @@
         /*
          * Skip "ROC", "posixrules", and "localtime".
          */
         if ((strcmp(dp->d_name, "ROC") == 0)
             || (strcmp(dp->d_name, "posixrules") == 0)
-#if defined(__solaris__)
-            /*
-             * Skip the "src" and "tab" directories on Solaris.
-             */
-            || (strcmp(dp->d_name, "src") == 0)
-            || (strcmp(dp->d_name, "tab") == 0)
-#endif
             || (strcmp(dp->d_name, "localtime") == 0)) {
             continue;
         }
 
         pathname = getPathName(dir, dp->d_name);

@@ -240,12 +228,10 @@
         (void) close(fd);
     }
     return possibleMatch;
 }
 
-#if defined(__linux__) || defined(MACOSX)
-
 /*
  * Performs Linux specific mapping and returns a zone ID
  * if found. Otherwise, NULL is returned.
  */
 static char *

@@ -351,315 +337,10 @@
     tz = findZoneinfoFile(buf, size, ZONEINFO_DIR);
     free((void *) buf);
     return tz;
 }
 
-#elif defined(__solaris__)
-
-#if !defined(__sparcv9) && !defined(amd64)
-
-/*
- * Those file* functions mimic the UNIX stream io functions. This is
- * because of the limitation of the number of open files on Solaris
- * (32-bit mode only) due to the System V ABI.
- */
-
-#define BUFFER_SIZE     4096
-
-static struct iobuffer {
-    int     magic;      /* -1 to distinguish from the real FILE */
-    int     fd;         /* file descriptor */
-    char    *buffer;    /* pointer to buffer */
-    char    *ptr;       /* current read pointer */
-    char    *endptr;    /* end pointer */
-};
-
-static int
-fileclose(FILE *stream)
-{
-    struct iobuffer *iop = (struct iobuffer *) stream;
-
-    if (iop->magic != -1) {
-        return fclose(stream);
-    }
-
-    if (iop == NULL) {
-        return 0;
-    }
-    close(iop->fd);
-    free((void *)iop->buffer);
-    free((void *)iop);
-    return 0;
-}
-
-static FILE *
-fileopen(const char *fname, const char *fmode)
-{
-    FILE *fp;
-    int fd;
-    struct iobuffer *iop;
-
-    if ((fp = fopen(fname, fmode)) != NULL) {
-        return fp;
-    }
-
-    /*
-     * It assumes read open.
-     */
-    RESTARTABLE(open(fname, O_RDONLY), fd);
-    if (fd == -1) {
-        return NULL;
-    }
-
-    /*
-     * Allocate struct iobuffer and its buffer
-     */
-    iop = malloc(sizeof(struct iobuffer));
-    if (iop == NULL) {
-        (void) close(fd);
-        errno = ENOMEM;
-        return NULL;
-    }
-    iop->magic = -1;
-    iop->fd = fd;
-    iop->buffer = malloc(BUFFER_SIZE);
-    if (iop->buffer == NULL) {
-        (void) close(fd);
-        free((void *) iop);
-        errno = ENOMEM;
-        return NULL;
-    }
-    iop->ptr = iop->buffer;
-    iop->endptr = iop->buffer;
-    return (FILE *)iop;
-}
-
-/*
- * This implementation assumes that n is large enough and the line
- * separator is '\n'.
- */
-static char *
-filegets(char *s, int n, FILE *stream)
-{
-    struct iobuffer *iop = (struct iobuffer *) stream;
-    char *p;
-
-    if (iop->magic != -1) {
-        return fgets(s, n, stream);
-    }
-
-    p = s;
-    for (;;) {
-        char c;
-
-        if (iop->ptr == iop->endptr) {
-            ssize_t len;
-
-            RESTARTABLE(read(iop->fd, (void *)iop->buffer, BUFFER_SIZE), len);
-            if (len == -1) {
-                return NULL;
-            }
-            if (len == 0) {
-                *p = 0;
-                if (s == p) {
-                    return NULL;
-                }
-                return s;
-            }
-            iop->ptr = iop->buffer;
-            iop->endptr = iop->buffer + len;
-        }
-        c = *iop->ptr++;
-        *p++ = c;
-        if ((p - s) == (n - 1)) {
-            *p = 0;
-            return s;
-        }
-        if (c == '\n') {
-            *p = 0;
-            return s;
-        }
-    }
-    /*NOTREACHED*/
-}
-#endif /* !defined(__sparcv9) && !defined(amd64) */
-
-/*
- * Performs Solaris dependent mapping. Returns a zone ID if
- * found. Otherwise, NULL is returned.  Solaris libc looks up
- * "/etc/default/init" to get the default TZ value if TZ is not defined
- * as an environment variable.
- */
-static char *
-getPlatformTimeZoneID()
-{
-    char *tz = NULL;
-    FILE *fp;
-
-    /*
-     * Try the TZ entry in /etc/default/init.
-     */
-    if ((fp = fileopen(SYS_INIT_FILE, "r")) != NULL) {
-        char line[256];
-        char quote = '\0';
-
-        while (filegets(line, sizeof(line), fp) != NULL) {
-            char *p = line;
-            char *s;
-            char c;
-
-            /* quick check for comment lines */
-            if (*p == '#') {
-                continue;
-            }
-            if (strncmp(p, "TZ=", 3) == 0) {
-                p += 3;
-                SKIP_SPACE(p);
-                c = *p;
-                if (c == '"' || c == '\'') {
-                    quote = c;
-                    p++;
-                }
-
-                /*
-                 * PSARC/2001/383: quoted string support
-                 */
-                for (s = p; (c = *s) != '\0' && c != '\n'; s++) {
-                    /* No '\\' is supported here. */
-                    if (c == quote) {
-                        quote = '\0';
-                        break;
-                    }
-                    if (c == ' ' && quote == '\0') {
-                        break;
-                    }
-                }
-                if (quote != '\0') {
-                    jio_fprintf(stderr, "ZoneInfo: unterminated time zone name in /etc/TIMEZONE\n");
-                }
-                *s = '\0';
-                tz = strdup(p);
-                break;
-            }
-        }
-        (void) fileclose(fp);
-    }
-    return tz;
-}
-
-#define TIMEZONE_FMRI   "svc:/system/timezone:default"
-#define TIMEZONE_PG     "timezone"
-#define LOCALTIME_PROP  "localtime"
-
-static void
-cleanupScf(scf_handle_t *h,
-           scf_snapshot_t *snap,
-           scf_instance_t *inst,
-           scf_propertygroup_t *pg,
-           scf_property_t *prop,
-           scf_value_t *val,
-           char *buf) {
-    if (buf != NULL) {
-        free(buf);
-    }
-    if (snap != NULL) {
-        scf_snapshot_destroy(snap);
-    }
-    if (val != NULL) {
-        scf_value_destroy(val);
-    }
-    if (prop != NULL) {
-        scf_property_destroy(prop);
-    }
-    if (pg != NULL) {
-        scf_pg_destroy(pg);
-    }
-    if (inst != NULL) {
-        scf_instance_destroy(inst);
-    }
-    if (h != NULL) {
-        scf_handle_destroy(h);
-    }
-}
-
-/*
- * Returns a zone ID of Solaris when the TZ value is "localtime".
- * First, it tries scf. If scf fails, it looks for the same file as
- * /usr/share/lib/zoneinfo/localtime under /usr/share/lib/zoneinfo/.
- */
-static char *
-getSolarisDefaultZoneID() {
-    char *tz = NULL;
-    struct stat64 statbuf;
-    size_t size;
-    char *buf;
-    int fd;
-    int res;
-    /* scf specific variables */
-    scf_handle_t *h = NULL;
-    scf_snapshot_t *snap = NULL;
-    scf_instance_t *inst = NULL;
-    scf_propertygroup_t *pg = NULL;
-    scf_property_t *prop = NULL;
-    scf_value_t *val = NULL;
-
-    if ((h = scf_handle_create(SCF_VERSION)) != NULL
-        && scf_handle_bind(h) == 0
-        && (inst = scf_instance_create(h)) != NULL
-        && (snap = scf_snapshot_create(h)) != NULL
-        && (pg = scf_pg_create(h)) != NULL
-        && (prop = scf_property_create(h)) != NULL
-        && (val = scf_value_create(h)) != NULL
-        && scf_handle_decode_fmri(h, TIMEZONE_FMRI, NULL, NULL, inst,
-                                  NULL, NULL, SCF_DECODE_FMRI_REQUIRE_INSTANCE) == 0
-        && scf_instance_get_snapshot(inst, "running", snap) == 0
-        && scf_instance_get_pg_composed(inst, snap, TIMEZONE_PG, pg) == 0
-        && scf_pg_get_property(pg, LOCALTIME_PROP, prop) == 0
-        && scf_property_get_value(prop, val) == 0) {
-        ssize_t len;
-
-        /* Gets the length of the zone ID string */
-        len = scf_value_get_astring(val, NULL, 0);
-        if (len != -1) {
-            tz = malloc(++len); /* +1 for a null byte */
-            if (tz != NULL && scf_value_get_astring(val, tz, len) != -1) {
-                cleanupScf(h, snap, inst, pg, prop, val, NULL);
-                return tz;
-            }
-        }
-    }
-    cleanupScf(h, snap, inst, pg, prop, val, tz);
-
-    RESTARTABLE(stat64(DEFAULT_ZONEINFO_FILE, &statbuf), res);
-    if (res == -1) {
-        return NULL;
-    }
-    size = (size_t) statbuf.st_size;
-    buf = malloc(size);
-    if (buf == NULL) {
-        return NULL;
-    }
-    RESTARTABLE(open(DEFAULT_ZONEINFO_FILE, O_RDONLY), fd);
-    if (fd == -1) {
-        free((void *) buf);
-        return NULL;
-    }
-
-    RESTARTABLE(read(fd, buf, size), res);
-    if (res != (ssize_t) size) {
-        (void) close(fd);
-        free((void *) buf);
-        return NULL;
-    }
-    (void) close(fd);
-    tz = findZoneinfoFile(buf, size, ZONEINFO_DIR);
-    free((void *) buf);
-    return tz;
-}
-
-#endif /* defined(__solaris__) */
-
 #elif defined(_AIX)
 
 static char *
 getPlatformTimeZoneID()
 {

@@ -822,19 +503,10 @@
         javatz = mapPlatformToJavaTimezone(java_home_dir, tz);
         if (freetz != NULL) {
             free((void *) freetz);
         }
 #else
-#if defined(__solaris__)
-        /* Solaris might use localtime, so handle it here. */
-        if (strcmp(tz, "localtime") == 0) {
-            javatz = getSolarisDefaultZoneID();
-            if (freetz != NULL) {
-                free((void *) freetz);
-            }
-        } else
-#endif
         if (freetz == NULL) {
             /* strdup if we are still working on getenv result. */
             javatz = strdup(tz);
         } else if (freetz != tz) {
             /* strdup and free the old buffer, if we moved the pointer. */

@@ -888,23 +560,11 @@
 char *
 getGMTOffsetID()
 {
     time_t offset;
     char sign, buf[32];
-#if defined(__solaris__)
-    struct tm localtm;
-    time_t currenttime;
-
-    currenttime = time(NULL);
-    if (localtime_r(&currenttime, &localtm) == NULL) {
-        return strdup("GMT");
-    }
-
-    offset = localtm.tm_isdst ? altzone : timezone;
-#else
     offset = timezone;
-#endif
 
     if (offset == 0) {
         return strdup("GMT");
     }
 
< prev index next >