Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
ea4e7475
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ea4e7475
编写于
10月 13, 2015
作者:
S
simonis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
8134505: Cleanup of "TimeZone_md.c"
Reviewed-by: rriggs, dsamersoff, simonis Contributed-by: christoph.langer@sap.com
上级
72c90b53
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
164 addition
and
165 deletion
+164
-165
src/solaris/native/java/util/TimeZone_md.c
src/solaris/native/java/util/TimeZone_md.c
+164
-165
未找到文件。
src/solaris/native/java/util/TimeZone_md.c
浏览文件 @
ea4e7475
/*
* Copyright (c) 1999, 201
4
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 201
5
, 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
...
...
@@ -35,14 +35,20 @@
#include <string.h>
#include <dirent.h>
#include <unistd.h>
#if
def __solaris__
#if
defined(__solaris__)
#include <libscf.h>
#endif
#include "jvm.h"
#include "TimeZone_md.h"
#define SKIP_SPACE(p) while (*p == ' ' || *p == '\t') p++;
#if defined(_ALLBSD_SOURCE)
#define dirent64 dirent
#define readdir64_r readdir_r
#endif
#if !defined(__solaris__) || defined(__sparcv9) || defined(amd64)
#define fileopen fopen
#define filegets fgets
...
...
@@ -50,19 +56,20 @@
#endif
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
static
const
char
*
ETC_TIMEZONE_FILE
=
"/etc/timezone"
;
static
const
char
*
ZONEINFO_DIR
=
"/usr/share/zoneinfo"
;
static
const
char
*
DEFAULT_ZONEINFO_FILE
=
"/etc/localtime"
;
#else
#ifdef _AIX
static
const
char
*
ETC_ENVIRONMENT_FILE
=
"/etc/environment"
;
#endif
static
const
char
*
SYS_INIT_FILE
=
"/etc/default/init"
;
static
const
char
*
ZONEINFO_DIR
=
"/usr/share/lib/zoneinfo"
;
static
const
char
*
DEFAULT_ZONEINFO_FILE
=
"/usr/share/lib/zoneinfo/localtime"
;
#endif
/*__linux__*/
#endif
/* defined(__linux__) || defined(_ALLBSD_SOURCE) */
#if defined(_AIX)
static
const
char
*
ETC_ENVIRONMENT_FILE
=
"/etc/environment"
;
#endif
#if defined(__linux__) || defined(MACOSX) || defined(__solaris__)
/*
* Returns a pointer to the zone ID portion of the given zoneinfo file
...
...
@@ -108,8 +115,8 @@ findZoneinfoFile(char *buf, size_t size, const char *dir)
{
DIR
*
dirp
=
NULL
;
struct
stat
statbuf
;
struct
dirent
*
dp
=
NULL
;
struct
dirent
*
entry
=
NULL
;
struct
dirent
64
*
dp
=
NULL
;
struct
dirent
64
*
entry
=
NULL
;
char
*
pathname
=
NULL
;
int
fd
=
-
1
;
char
*
dbuf
=
NULL
;
...
...
@@ -120,19 +127,13 @@ findZoneinfoFile(char *buf, size_t size, const char *dir)
return
NULL
;
}
entry
=
(
struct
dirent
*
)
malloc
((
size_t
)
pathconf
(
dir
,
_PC_NAME_MAX
));
entry
=
(
struct
dirent
64
*
)
malloc
((
size_t
)
pathconf
(
dir
,
_PC_NAME_MAX
));
if
(
entry
==
NULL
)
{
(
void
)
closedir
(
dirp
);
return
NULL
;
}
#if defined(_AIX) || defined(__linux__) || defined(MACOSX) || (defined(__solaris__) \
&& (defined(_POSIX_PTHREAD_SEMANTICS) || defined(_LP64)))
while
(
readdir_r
(
dirp
,
entry
,
&
dp
)
==
0
&&
dp
!=
NULL
)
{
#else
while
((
dp
=
readdir_r
(
dirp
,
entry
))
!=
NULL
)
{
#endif
while
(
readdir64_r
(
dirp
,
entry
,
&
dp
)
==
0
&&
dp
!=
NULL
)
{
/*
* Skip '.' and '..' (and possibly other .* files)
*/
...
...
@@ -145,7 +146,7 @@ findZoneinfoFile(char *buf, size_t size, const char *dir)
*/
if
((
strcmp
(
dp
->
d_name
,
"ROC"
)
==
0
)
||
(
strcmp
(
dp
->
d_name
,
"posixrules"
)
==
0
)
#if
def __solaris__
#if
defined(__solaris__)
/*
* Skip the "src" and "tab" directories on Solaris.
*/
...
...
@@ -230,7 +231,7 @@ getPlatformTimeZoneID()
char
*
buf
;
size_t
size
;
#if
def __linux__
#if
defined(__linux__)
/*
* Try reading the /etc/timezone file for Debian distros. There's
* no spec of the file format available. This parsing assumes that
...
...
@@ -254,7 +255,7 @@ getPlatformTimeZoneID()
return
tz
;
}
}
#endif
/*
__linux__
*/
#endif
/*
defined(__linux__)
*/
/*
* Next, try /etc/localtime to find the zone ID.
...
...
@@ -318,8 +319,9 @@ getPlatformTimeZoneID()
free
((
void
*
)
buf
);
return
tz
;
}
#else
#ifdef __solaris__
#elif defined(__solaris__)
#if !defined(__sparcv9) && !defined(amd64)
/*
...
...
@@ -444,8 +446,7 @@ filegets(char *s, int n, FILE *stream)
}
/*NOTREACHED*/
}
#endif
/* not __sparcv9 */
#endif
/* !defined(__sparcv9) && !defined(amd64) */
/*
* Performs Solaris dependent mapping. Returns a zone ID if
...
...
@@ -546,7 +547,7 @@ cleanupScf(scf_handle_t *h,
}
/*
* Ret
ru
ns a zone ID of Solaris when the TZ value is "localtime".
* Ret
ur
ns 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/.
*/
...
...
@@ -615,10 +616,11 @@ getSolarisDefaultZoneID() {
free
((
void
*
)
buf
);
return
tz
;
}
#endif
/*__solaris__*/
#endif
/*__linux__*/
#ifdef _AIX
#endif
/* defined(__solaris__) */
#elif defined(_AIX)
static
char
*
getPlatformTimeZoneID
()
{
...
...
@@ -644,8 +646,103 @@ getPlatformTimeZoneID()
return
tz
;
}
static
char
*
mapPlatformToJavaTimezone
(
const
char
*
java_home_dir
,
const
char
*
tz
);
#endif
static
char
*
mapPlatformToJavaTimezone
(
const
char
*
java_home_dir
,
const
char
*
tz
)
{
FILE
*
tzmapf
;
char
mapfilename
[
PATH_MAX
+
1
];
char
line
[
256
];
int
linecount
=
0
;
char
*
tz_buf
=
NULL
;
char
*
temp_tz
=
NULL
;
char
*
javatz
=
NULL
;
size_t
tz_len
=
0
;
/* On AIX, the TZ environment variable may end with a comma
* followed by modifier fields. These are ignored here. */
temp_tz
=
strchr
(
tz
,
','
);
tz_len
=
(
temp_tz
==
NULL
)
?
strlen
(
tz
)
:
temp_tz
-
tz
;
tz_buf
=
(
char
*
)
malloc
(
tz_len
+
1
);
memcpy
(
tz_buf
,
tz
,
tz_len
);
tz_buf
[
tz_len
]
=
0
;
/* Open tzmappings file, with buffer overrun check */
if
((
strlen
(
java_home_dir
)
+
15
)
>
PATH_MAX
)
{
jio_fprintf
(
stderr
,
"Path %s/lib/tzmappings exceeds maximum path length
\n
"
,
java_home_dir
);
goto
tzerr
;
}
strcpy
(
mapfilename
,
java_home_dir
);
strcat
(
mapfilename
,
"/lib/tzmappings"
);
if
((
tzmapf
=
fopen
(
mapfilename
,
"r"
))
==
NULL
)
{
jio_fprintf
(
stderr
,
"can't open %s
\n
"
,
mapfilename
);
goto
tzerr
;
}
while
(
fgets
(
line
,
sizeof
(
line
),
tzmapf
)
!=
NULL
)
{
char
*
p
=
line
;
char
*
sol
=
line
;
char
*
java
;
int
result
;
linecount
++
;
/*
* Skip comments and blank lines
*/
if
(
*
p
==
'#'
||
*
p
==
'\n'
)
{
continue
;
}
/*
* Get the first field, platform zone ID
*/
while
(
*
p
!=
'\0'
&&
*
p
!=
'\t'
)
{
p
++
;
}
if
(
*
p
==
'\0'
)
{
/* mapping table is broken! */
jio_fprintf
(
stderr
,
"tzmappings: Illegal format at near line %d.
\n
"
,
linecount
);
break
;
}
*
p
++
=
'\0'
;
if
((
result
=
strncmp
(
tz_buf
,
sol
,
tz_len
))
==
0
)
{
/*
* If this is the current platform zone ID,
* take the Java time zone ID (2nd field).
*/
java
=
p
;
while
(
*
p
!=
'\0'
&&
*
p
!=
'\n'
)
{
p
++
;
}
if
(
*
p
==
'\0'
)
{
/* mapping table is broken! */
jio_fprintf
(
stderr
,
"tzmappings: Illegal format at line %d.
\n
"
,
linecount
);
break
;
}
*
p
=
'\0'
;
javatz
=
strdup
(
java
);
break
;
}
else
if
(
result
<
0
)
{
break
;
}
}
(
void
)
fclose
(
tzmapf
);
tzerr:
if
(
tz_buf
!=
NULL
)
{
free
((
void
*
)
tz_buf
);
}
if
(
javatz
==
NULL
)
{
return
getGMTOffsetID
();
}
return
javatz
;
}
#endif
/* defined(_AIX) */
/*
* findJavaTZ_md() maps platform time zone ID to Java time zone ID
...
...
@@ -664,51 +761,50 @@ findJavaTZ_md(const char *java_home_dir)
tz
=
getenv
(
"TZ"
);
#if defined(__linux__) || defined(_ALLBSD_SOURCE)
if
(
tz
==
NULL
)
{
#else
#if defined (__solaris__) || defined(_AIX)
if
(
tz
==
NULL
||
*
tz
==
'\0'
)
{
#endif
#endif
tz
=
getPlatformTimeZoneID
();
freetz
=
tz
;
}
/*
* Remove any preceding ':'
*/
if
(
tz
!=
NULL
&&
*
tz
==
':'
)
{
tz
++
;
}
#ifdef __solaris__
if
(
tz
!=
NULL
&&
strcmp
(
tz
,
"localtime"
)
==
0
)
{
tz
=
getSolarisDefaultZoneID
();
freetz
=
tz
;
}
#endif
if
(
tz
!=
NULL
)
{
#ifdef __linux__
/*
* Ignore "posix/" prefix.
*/
/* Ignore preceding ':' */
if
(
*
tz
==
':'
)
{
tz
++
;
}
#if defined(__linux__)
/* Ignore "posix/" prefix on Linux. */
if
(
strncmp
(
tz
,
"posix/"
,
6
)
==
0
)
{
tz
+=
6
;
}
#endif
javatz
=
strdup
(
tz
);
#if defined(_AIX)
/* On AIX do the platform to Java mapping. */
javatz
=
mapPlatformToJavaTimezone
(
java_home_dir
,
tz
);
if
(
freetz
!=
NULL
)
{
free
((
void
*
)
freetz
);
}
#ifdef _AIX
freetz
=
mapPlatformToJavaTimezone
(
java_home_dir
,
javatz
);
if
(
javatz
!=
NULL
)
{
free
((
void
*
)
javatz
);
#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. */
javatz
=
strdup
(
tz
);
free
((
void
*
)
freetz
);
}
else
{
/* we are good if we already work on a freshly allocated buffer. */
javatz
=
tz
;
}
javatz
=
freetz
;
#endif
}
...
...
@@ -719,7 +815,7 @@ findJavaTZ_md(const char *java_home_dir)
* Returns a GMT-offset-based zone ID. (e.g., "GMT-08:00")
*/
#if
def MACOSX
#if
defined(MACOSX)
char
*
getGMTOffsetID
()
...
...
@@ -735,15 +831,16 @@ getGMTOffsetID()
local_tm
=
localtime
(
&
clock
);
if
(
local_tm
->
tm_gmtoff
>=
0
)
{
offset
=
(
time_t
)
local_tm
->
tm_gmtoff
;
sign
=
"+"
;
sign
=
'+'
;
}
else
{
offset
=
(
time_t
)
-
local_tm
->
tm_gmtoff
;
sign
=
"-"
;
sign
=
'-'
;
}
sprintf
(
buf
,
(
const
char
*
)
"GMT%c%02d:%02d"
,
sign
,
(
int
)(
offset
/
3600
),
(
int
)((
offset
%
3600
)
/
60
));
return
strdup
(
buf
);
}
#else
char
*
...
...
@@ -751,7 +848,7 @@ getGMTOffsetID()
{
time_t
offset
;
char
sign
,
buf
[
32
];
#if
def __solaris__
#if
defined(__solaris__)
struct
tm
localtm
;
time_t
currenttime
;
...
...
@@ -763,7 +860,7 @@ getGMTOffsetID()
offset
=
localtm
.
tm_isdst
?
altzone
:
timezone
;
#else
offset
=
timezone
;
#endif
/*__linux__*/
#endif
if
(
offset
==
0
)
{
return
strdup
(
"GMT"
);
...
...
@@ -781,101 +878,3 @@ getGMTOffsetID()
return
strdup
(
buf
);
}
#endif
/* MACOSX */
#ifdef _AIX
static
char
*
mapPlatformToJavaTimezone
(
const
char
*
java_home_dir
,
const
char
*
tz
)
{
FILE
*
tzmapf
;
char
mapfilename
[
PATH_MAX
+
1
];
char
line
[
256
];
int
linecount
=
0
;
char
temp
[
100
],
*
temp_tz
;
char
*
javatz
=
NULL
;
char
*
str_tmp
=
NULL
;
size_t
temp_tz_len
=
0
;
/* On AIX, the TZ environment variable may end with a comma
* followed by modifier fields. These are ignored here.
*/
strncpy
(
temp
,
tz
,
100
);
temp_tz
=
strtok_r
(
temp
,
","
,
&
str_tmp
);
if
(
temp_tz
==
NULL
)
goto
tzerr
;
temp_tz_len
=
strlen
(
temp_tz
);
if
(
strlen
(
java_home_dir
)
>=
(
PATH_MAX
-
15
))
{
jio_fprintf
(
stderr
,
"java.home longer than maximum path length
\n
"
);
goto
tzerr
;
}
strncpy
(
mapfilename
,
java_home_dir
,
PATH_MAX
);
strcat
(
mapfilename
,
"/lib/tzmappings"
);
if
((
tzmapf
=
fopen
(
mapfilename
,
"r"
))
==
NULL
)
{
jio_fprintf
(
stderr
,
"can't open %s
\n
"
,
mapfilename
);
goto
tzerr
;
}
while
(
fgets
(
line
,
sizeof
(
line
),
tzmapf
)
!=
NULL
)
{
char
*
p
=
line
;
char
*
sol
=
line
;
char
*
java
;
int
result
;
linecount
++
;
/*
* Skip comments and blank lines
*/
if
(
*
p
==
'#'
||
*
p
==
'\n'
)
{
continue
;
}
/*
* Get the first field, platform zone ID
*/
while
(
*
p
!=
'\0'
&&
*
p
!=
'\t'
)
{
p
++
;
}
if
(
*
p
==
'\0'
)
{
/* mapping table is broken! */
jio_fprintf
(
stderr
,
"tzmappings: Illegal format at near line %d.
\n
"
,
linecount
);
break
;
}
*
p
++
=
'\0'
;
if
((
result
=
strncmp
(
temp_tz
,
sol
,
temp_tz_len
))
==
0
)
{
/*
* If this is the current platform zone ID,
* take the Java time zone ID (2nd field).
*/
java
=
p
;
while
(
*
p
!=
'\0'
&&
*
p
!=
'\n'
)
{
p
++
;
}
if
(
*
p
==
'\0'
)
{
/* mapping table is broken! */
jio_fprintf
(
stderr
,
"tzmappings: Illegal format at line %d.
\n
"
,
linecount
);
break
;
}
*
p
=
'\0'
;
javatz
=
strdup
(
java
);
break
;
}
else
if
(
result
<
0
)
{
break
;
}
}
(
void
)
fclose
(
tzmapf
);
tzerr:
if
(
javatz
==
NULL
)
{
return
getGMTOffsetID
();
}
return
javatz
;
}
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录