예제 #1
0
/*ARGSUSED1*/
char *
findJavaTZ_md(const char *java_home_dir)
{
    char *tz;
    char *javatz = NULL;
    char *freetz = NULL;

    tz = getenv("TZ");

    if (tz == NULL || *tz == '\0') {
        tz = getPlatformTimeZoneID();
        freetz = tz;
    }

    if (tz != NULL) {
        /* Ignore preceding ':' */
        if (*tz == ':') {
            tz++;
        }
#if defined(__linux__)
        /* Ignore "posix/" prefix on Linux. */
        if (strncmp(tz, "posix/", 6) == 0) {
            tz += 6;
        }
#endif

#if defined(_AIX)
        /* On AIX do the platform to Java mapping. */
        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. */
            javatz = strdup(tz);
            free((void *) freetz);
        } else {
            /* we are good if we already work on a freshly allocated buffer. */
            javatz = tz;
        }
#endif
    }

    return javatz;
}
예제 #2
0
/*ARGSUSED1*/
char *
findJavaTZ_md(const char *java_home_dir, const char *country)
{
    char *tz;
    char *javatz = NULL;
    char *freetz = NULL;

    tz = getenv("TZ");

#if defined(__linux__) || defined(_ALLBSD_SOURCE)
    if (tz == NULL) {
#else
#ifdef __solaris__
    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.
         */
        if (strncmp(tz, "posix/", 6) == 0) {
            tz += 6;
        }
#endif
        javatz = strdup(tz);
        if (freetz != NULL) {
            free((void *) freetz);
        }
    }
    return javatz;
}
/**
 * Returns a GMT-offset-based zone ID. (e.g., "GMT-08:00")
 */

#ifdef MACOSX

char *
getGMTOffsetID()
{
    time_t offset;
    char sign, buf[16];
    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 = "-";
    }
    sprintf(buf, (const char *)"GMT%c%02d:%02d",
            sign, (int)(offset/3600), (int)((offset%3600)/60));
    return strdup(buf);
}
/*ARGSUSED1*/
char *
CVMtimezoneFindJavaTZ(const char *java_home_dir, const char *country)
{
    char *tz;
    char *javatz = NULL;
    char *freetz = NULL;

    tz = getenv("TZ");

#ifdef __linux__
    if (tz == NULL) {
#else
#ifdef __solaris__
    if (tz == NULL || *tz == '\0') {
#endif
#endif
	tz = getPlatformTimeZoneID();
	freetz = tz;
    }

    if (tz != NULL) {
	if (*tz == ':') {
	    tz++;
	}
#ifdef __linix__
	/*
	 * Ignore "posix/" and "right/" prefix.
	 */
	if (strncmp(tz, "posix/", 6) == 0 || strncomp(tz, "right/", 6) == 0) {
	    tz += 6;
	}
#endif
	javatz = strdup(tz);
	if (freetz != NULL) {
	    free((void *) freetz);
	}
    }	
    return javatz;
}

/**
 * Returns a GMT-offset-based time zone ID. (e.g., "GMT-08:00")
 */
char *
CVMgetGMTOffsetID()
{
    time_t offset;
    char sign, buf[16];

    if (timezone == 0) {
	return strdup("GMT");
    }

    /* Note that the time offset direction is opposite. */
    if (timezone > 0) {
	offset = timezone;
	sign = '-';
    } else {
	offset = -timezone;
	sign = '+';
    }
    sprintf(buf, (const char *)"GMT%c%02d:%02d",
	    sign, (int)(offset/3600), (int)((offset%3600)/60));
    return strdup(buf);
}