1 | /*
|
---|
2 | * Copyright (c) 2002 IBM Corp and others. All rights reserved.
|
---|
3 | * This file is made available under the terms of the Common Public License v1.0
|
---|
4 | * which accompanies this distribution, and is available at
|
---|
5 | * http://www.eclipse.org/legal/cpl-v10.html
|
---|
6 | *
|
---|
7 | * Contributors:
|
---|
8 | * Kevin Cornell (Rational Software Corporation)
|
---|
9 | */
|
---|
10 |
|
---|
11 |
|
---|
12 | /* Eclipse Launcher Utility Methods */
|
---|
13 |
|
---|
14 | #include <string.h>
|
---|
15 | #include <stdlib.h>
|
---|
16 | #include <stdio.h>
|
---|
17 |
|
---|
18 | #include "eclipseUtil.h"
|
---|
19 | #include "eclipseOS.h"
|
---|
20 |
|
---|
21 | #define MAX_LINE_LENGTH 256
|
---|
22 |
|
---|
23 | #ifdef _WIN32
|
---|
24 | #define strcasecmp _stricmp
|
---|
25 | #endif
|
---|
26 |
|
---|
27 |
|
---|
28 | /* Is the given VM J9 */
|
---|
29 | int isJ9VM( char* vm )
|
---|
30 | {
|
---|
31 | char *ch = strrchr( vm, (int)dirSeparator );
|
---|
32 | if (ch == NULL)
|
---|
33 | ch = vm;
|
---|
34 | else
|
---|
35 | ch++;
|
---|
36 | return (stricmp( ch, "j9" ) == 0);
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | #ifdef AIX
|
---|
41 |
|
---|
42 | #include <sys/types.h>
|
---|
43 | #include <time.h>
|
---|
44 |
|
---|
45 | /* Return the JVM version in the format x.x.x
|
---|
46 | */
|
---|
47 | char* getVMVersion( char *vmPath )
|
---|
48 | {
|
---|
49 | char cmd[MAX_LINE_LENGTH];
|
---|
50 | char lineString[MAX_LINE_LENGTH];
|
---|
51 | char* firstChar;
|
---|
52 | char fileName[MAX_LINE_LENGTH];
|
---|
53 | time_t curTime;
|
---|
54 | FILE* fp;
|
---|
55 | int numChars = 0;
|
---|
56 | char* version = NULL;
|
---|
57 |
|
---|
58 | /* Define a unique filename for the java output. */
|
---|
59 | (void) time(&curTime);
|
---|
60 | (void) sprintf(fileName, "/tmp/tmp%ld.txt", curTime);
|
---|
61 |
|
---|
62 | /* Write java -version output to a temp file */
|
---|
63 | (void) sprintf(cmd,"%s -version 2> %s", vmPath, fileName);
|
---|
64 | (void) system(cmd);
|
---|
65 |
|
---|
66 | fp = fopen(fileName, "r");
|
---|
67 | if (fp != NULL)
|
---|
68 | {
|
---|
69 | /* Read java -version output from a temp file */
|
---|
70 | if (fgets(lineString, MAX_LINE_LENGTH, fp) == NULL)
|
---|
71 | lineString[0] = '\0';
|
---|
72 | fclose(fp);
|
---|
73 | unlink(fileName);
|
---|
74 |
|
---|
75 | /* Extract version number */
|
---|
76 | firstChar = (char *) (strchr(lineString, '"') + 1);
|
---|
77 | if (firstChar != NULL)
|
---|
78 | numChars = (int) (strrchr(lineString, '"') - firstChar);
|
---|
79 |
|
---|
80 | /* Allocate a buffer and copy the version string into it. */
|
---|
81 | if (numChars > 0)
|
---|
82 | {
|
---|
83 | version = malloc( numChars + 1 );
|
---|
84 | strncpy(version, firstChar, numChars);
|
---|
85 | version[numChars] = '\0';
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | return version;
|
---|
90 | }
|
---|
91 |
|
---|
92 | /* Compare JVM Versions of the form "x.x.x..."
|
---|
93 | *
|
---|
94 | * Returns -1 if ver1 < ver2
|
---|
95 | * Returns 0 if ver1 = ver2
|
---|
96 | * Returns 1 if ver1 > ver2
|
---|
97 | */
|
---|
98 | int versionCmp(char *ver1, char *ver2)
|
---|
99 | {
|
---|
100 | char* dot1;
|
---|
101 | char* dot2;
|
---|
102 | int num1;
|
---|
103 | int num2;
|
---|
104 |
|
---|
105 | dot1 = strchr(ver1, '.');
|
---|
106 | dot2 = strchr(ver2, '.');
|
---|
107 |
|
---|
108 | num1 = atoi(ver1);
|
---|
109 | num2 = atoi(ver2);
|
---|
110 |
|
---|
111 | if (num1 > num2)
|
---|
112 | return 1;
|
---|
113 |
|
---|
114 | if (num1 < num2)
|
---|
115 | return -1;
|
---|
116 |
|
---|
117 | if (dot1 && !dot2) /* x.y > x */
|
---|
118 | return 1;
|
---|
119 |
|
---|
120 | if (!dot1 && dot2) /* x < x.y */
|
---|
121 | return -1;
|
---|
122 |
|
---|
123 | if (!dot1 && !dot2) /* x == x */
|
---|
124 | return 0;
|
---|
125 |
|
---|
126 | return versionCmp((char*)(dot1 + 1), (char*)(dot2 + 1) );
|
---|
127 | }
|
---|
128 | #endif /* AIX */
|
---|