1 /*
2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
106 DIR *dirp = NULL;
107 struct stat statbuf;
108 struct dirent *dp = NULL;
109 struct dirent *entry = NULL;
110 char *pathname = NULL;
111 int fd = -1;
112 char *dbuf = NULL;
113 char *tz = NULL;
114
115 dirp = opendir(dir);
116 if (dirp == NULL) {
117 return NULL;
118 }
119
120 entry = (struct dirent *) malloc((size_t) pathconf(dir, _PC_NAME_MAX));
121 if (entry == NULL) {
122 (void) closedir(dirp);
123 return NULL;
124 }
125
126 #if defined(__linux__) || defined(MACOSX) || (defined(__solaris__) \
127 && (defined(_POSIX_PTHREAD_SEMANTICS) || defined(_LP64)))
128 while (readdir_r(dirp, entry, &dp) == 0 && dp != NULL) {
129 #else
130 while ((dp = readdir_r(dirp, entry)) != NULL) {
131 #endif
132
133 /*
134 * Skip '.' and '..' (and possibly other .* files)
135 */
136 if (dp->d_name[0] == '.') {
137 continue;
138 }
139
140 /*
141 * Skip "ROC", "posixrules", and "localtime".
142 */
143 if ((strcmp(dp->d_name, "ROC") == 0)
144 || (strcmp(dp->d_name, "posixrules") == 0)
145 #ifdef __solaris__
146 /*
598 return NULL;
599 }
600 if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
601 free((void *) buf);
602 return NULL;
603 }
604
605 if (read(fd, buf, size) != (ssize_t) size) {
606 (void) close(fd);
607 free((void *) buf);
608 return NULL;
609 }
610 (void) close(fd);
611 tz = findZoneinfoFile(buf, size, ZONEINFO_DIR);
612 free((void *) buf);
613 return tz;
614 }
615 #endif /*__solaris__*/
616 #endif /*__linux__*/
617
618 /*
619 * findJavaTZ_md() maps platform time zone ID to Java time zone ID
620 * using <java_home>/lib/tzmappings. If the TZ value is not found, it
621 * trys some libc implementation dependent mappings. If it still
622 * can't map to a Java time zone ID, it falls back to the GMT+/-hh:mm
623 * form. `country', which can be null, is not used for UNIX platforms.
624 */
625 /*ARGSUSED1*/
626 char *
627 findJavaTZ_md(const char *java_home_dir, const char *country)
628 {
629 char *tz;
630 char *javatz = NULL;
631 char *freetz = NULL;
632
633 tz = getenv("TZ");
634
635 #if defined(__linux__) || defined(_ALLBSD_SOURCE)
636 if (tz == NULL) {
637 #else
638 #ifdef __solaris__
639 if (tz == NULL || *tz == '\0') {
640 #endif
641 #endif
642 tz = getPlatformTimeZoneID();
643 freetz = tz;
644 }
645
646 /*
647 * Remove any preceding ':'
648 */
649 if (tz != NULL && *tz == ':') {
650 tz++;
651 }
652
653 #ifdef __solaris__
654 if (tz != NULL && strcmp(tz, "localtime") == 0) {
655 tz = getSolarisDefaultZoneID();
656 freetz = tz;
657 }
658 #endif
|
1 /*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
106 DIR *dirp = NULL;
107 struct stat statbuf;
108 struct dirent *dp = NULL;
109 struct dirent *entry = NULL;
110 char *pathname = NULL;
111 int fd = -1;
112 char *dbuf = NULL;
113 char *tz = NULL;
114
115 dirp = opendir(dir);
116 if (dirp == NULL) {
117 return NULL;
118 }
119
120 entry = (struct dirent *) malloc((size_t) pathconf(dir, _PC_NAME_MAX));
121 if (entry == NULL) {
122 (void) closedir(dirp);
123 return NULL;
124 }
125
126 #if defined(AIX) || defined(__linux__) || defined(MACOSX) || (defined(__solaris__) \
127 && (defined(_POSIX_PTHREAD_SEMANTICS) || defined(_LP64)))
128 while (readdir_r(dirp, entry, &dp) == 0 && dp != NULL) {
129 #else
130 while ((dp = readdir_r(dirp, entry)) != NULL) {
131 #endif
132
133 /*
134 * Skip '.' and '..' (and possibly other .* files)
135 */
136 if (dp->d_name[0] == '.') {
137 continue;
138 }
139
140 /*
141 * Skip "ROC", "posixrules", and "localtime".
142 */
143 if ((strcmp(dp->d_name, "ROC") == 0)
144 || (strcmp(dp->d_name, "posixrules") == 0)
145 #ifdef __solaris__
146 /*
598 return NULL;
599 }
600 if ((fd = open(DEFAULT_ZONEINFO_FILE, O_RDONLY)) == -1) {
601 free((void *) buf);
602 return NULL;
603 }
604
605 if (read(fd, buf, size) != (ssize_t) size) {
606 (void) close(fd);
607 free((void *) buf);
608 return NULL;
609 }
610 (void) close(fd);
611 tz = findZoneinfoFile(buf, size, ZONEINFO_DIR);
612 free((void *) buf);
613 return tz;
614 }
615 #endif /*__solaris__*/
616 #endif /*__linux__*/
617
618 #ifdef AIX
619 static char *
620 getPlatformTimeZoneID()
621 {
622 return NULL;
623 }
624 #endif
625
626 /*
627 * findJavaTZ_md() maps platform time zone ID to Java time zone ID
628 * using <java_home>/lib/tzmappings. If the TZ value is not found, it
629 * trys some libc implementation dependent mappings. If it still
630 * can't map to a Java time zone ID, it falls back to the GMT+/-hh:mm
631 * form. `country', which can be null, is not used for UNIX platforms.
632 */
633 /*ARGSUSED1*/
634 char *
635 findJavaTZ_md(const char *java_home_dir, const char *country)
636 {
637 char *tz;
638 char *javatz = NULL;
639 char *freetz = NULL;
640
641 tz = getenv("TZ");
642
643 #if defined(__linux__) || defined(_ALLBSD_SOURCE)
644 if (tz == NULL) {
645 #else
646 #if defined (__solaris__) || defined(AIX)
647 if (tz == NULL || *tz == '\0') {
648 #endif
649 #endif
650 tz = getPlatformTimeZoneID();
651 freetz = tz;
652 }
653
654 /*
655 * Remove any preceding ':'
656 */
657 if (tz != NULL && *tz == ':') {
658 tz++;
659 }
660
661 #ifdef __solaris__
662 if (tz != NULL && strcmp(tz, "localtime") == 0) {
663 tz = getSolarisDefaultZoneID();
664 freetz = tz;
665 }
666 #endif
|