1 /*
2 * Copyright (c) 1997, 2014, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
756 }
757
758 int JDK_Version::compare(const JDK_Version& other) const {
759 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
760 if (!is_partially_initialized() && other.is_partially_initialized()) {
761 return -(other.compare(*this)); // flip the comparators
762 }
763 assert(!other.is_partially_initialized(), "Not initialized yet");
764 if (is_partially_initialized()) {
765 assert(other.major_version() >= 6,
766 "Invalid JDK version comparison during initialization");
767 return -1;
768 } else {
769 uint64_t e = encode_jdk_version(*this);
770 uint64_t o = encode_jdk_version(other);
771 return (e > o) ? 1 : ((e == o) ? 0 : -1);
772 }
773 }
774
775 void JDK_Version::to_string(char* buffer, size_t buflen) const {
776 size_t index = 0;
777 if (!is_valid()) {
778 jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
779 } else if (is_partially_initialized()) {
780 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
781 } else {
782 index += jio_snprintf(
783 &buffer[index], buflen - index, "%d.%d", _major, _minor);
784 if (_micro > 0) {
785 index += jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
786 }
787 if (_update > 0) {
788 index += jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
789 }
790 if (_special > 0) {
791 index += jio_snprintf(&buffer[index], buflen - index, "%c", _special);
792 }
793 if (_build > 0) {
794 index += jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
795 }
796 }
797 }
|
1 /*
2 * Copyright (c) 1997, 2016, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
756 }
757
758 int JDK_Version::compare(const JDK_Version& other) const {
759 assert(is_valid() && other.is_valid(), "Invalid version (uninitialized?)");
760 if (!is_partially_initialized() && other.is_partially_initialized()) {
761 return -(other.compare(*this)); // flip the comparators
762 }
763 assert(!other.is_partially_initialized(), "Not initialized yet");
764 if (is_partially_initialized()) {
765 assert(other.major_version() >= 6,
766 "Invalid JDK version comparison during initialization");
767 return -1;
768 } else {
769 uint64_t e = encode_jdk_version(*this);
770 uint64_t o = encode_jdk_version(other);
771 return (e > o) ? 1 : ((e == o) ? 0 : -1);
772 }
773 }
774
775 void JDK_Version::to_string(char* buffer, size_t buflen) const {
776 assert(buffer && buflen > 0, "call with useful buffer");
777 size_t index = 0;
778 if (!is_valid()) {
779 jio_snprintf(buffer, buflen, "%s", "(uninitialized)");
780 } else if (is_partially_initialized()) {
781 jio_snprintf(buffer, buflen, "%s", "(uninitialized) pre-1.6.0");
782 } else {
783 int rc = jio_snprintf(
784 &buffer[index], buflen - index, "%d.%d", _major, _minor);
785 if (rc == -1) return;
786 index += rc;
787 if (_micro > 0) {
788 rc = jio_snprintf(&buffer[index], buflen - index, ".%d", _micro);
789 if (rc == -1) return;
790 index += rc;
791 }
792 if (_update > 0) {
793 rc = jio_snprintf(&buffer[index], buflen - index, "_%02d", _update);
794 if (rc == -1) return;
795 index += rc;
796 }
797 if (_special > 0) {
798 rc = jio_snprintf(&buffer[index], buflen - index, "%c", _special);
799 if (rc == -1) return;
800 index += rc;
801 }
802 if (_build > 0) {
803 rc = jio_snprintf(&buffer[index], buflen - index, "-b%02d", _build);
804 if (rc == -1) return;
805 index += rc;
806 }
807 }
808 }
|