1 /*
2 * Copyright (c) 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. 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
112 }
113
114 static int try_libraries_noload(char *names[3])
115 {
116 #ifdef RTLD_NOLOAD
117 void *gtk;
118 gtk = dlopen(names[1], RTLD_LAZY | RTLD_NOLOAD);
119 return gtk ? 1 : 0;
120 #else
121 return 0;
122 #endif
123 }
124
125 static int sniffLibs(int wantVersion) {
126
127 if (gtk_versionDebug) {
128 printf("checking GTK version %d\n",wantVersion);
129 }
130
131 int success = 1;
132 char *** use_chain = two_to_three;
133 int i, found = 0;
134
135 //at first try to detect already loaded GTK version
136 for (i = 0; use_chain[i] && !found; i++) {
137 found = try_libraries_noload(use_chain[i]);
138 if (found && gtk_versionDebug) {
139 printf("found already loaded GTK library %s\n", use_chain[i][1]);
140 }
141 }
142
143 if (!found) {
144 if (wantVersion == 0 || wantVersion == 2) {
145 use_chain = two_to_three;
146 } else if (wantVersion == 3) {
147 use_chain = three_to_two;
148 } else {
149 // Note, this should never happen, java should be protecting us
150 if (gtk_versionDebug) {
151 printf("bad GTK version specified, assuming 2\n");
152 }
153 wantVersion = 2;
154 use_chain = two_to_three;
155 }
156
157 for (i = 0; use_chain[i] && !found; i++) {
158 if (gtk_versionDebug) {
159 printf("trying GTK library %s\n", use_chain[i][1]);
160 }
161 found = try_opening_libraries(use_chain[i]);
162 }
163 }
164
165 if (found) {
166 if (gtk_versionDebug) {
167 i--;
168 printf("using GTK library version %s set %s\n",
169 use_chain[i][0],
170 use_chain[i][1]);
171 fflush(stdout);
172 }
173 return use_chain[i][0][0];
174 }
|
1 /*
2 * Copyright (c) 2016, 2018, 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
112 }
113
114 static int try_libraries_noload(char *names[3])
115 {
116 #ifdef RTLD_NOLOAD
117 void *gtk;
118 gtk = dlopen(names[1], RTLD_LAZY | RTLD_NOLOAD);
119 return gtk ? 1 : 0;
120 #else
121 return 0;
122 #endif
123 }
124
125 static int sniffLibs(int wantVersion) {
126
127 if (gtk_versionDebug) {
128 printf("checking GTK version %d\n",wantVersion);
129 }
130
131 int success = 1;
132 char *** use_chain = three_to_two;
133 int i, found = 0;
134
135 //at first try to detect already loaded GTK version
136 for (i = 0; use_chain[i] && !found; i++) {
137 found = try_libraries_noload(use_chain[i]);
138 if (found && gtk_versionDebug) {
139 printf("found already loaded GTK library %s\n", use_chain[i][1]);
140 }
141 }
142
143 if (!found) {
144 if (wantVersion == 0 || wantVersion == 3) {
145 use_chain = three_to_two;
146 } else if (wantVersion == 2) {
147 use_chain = two_to_three;
148 } else {
149 // Note, this should never happen, java should be protecting us
150 if (gtk_versionDebug) {
151 printf("bad GTK version specified, assuming 3\n");
152 }
153 wantVersion = 3;
154 use_chain = three_to_two;
155 }
156
157 for (i = 0; use_chain[i] && !found; i++) {
158 if (gtk_versionDebug) {
159 printf("trying GTK library %s\n", use_chain[i][1]);
160 }
161 found = try_opening_libraries(use_chain[i]);
162 }
163 }
164
165 if (found) {
166 if (gtk_versionDebug) {
167 i--;
168 printf("using GTK library version %s set %s\n",
169 use_chain[i][0],
170 use_chain[i][1]);
171 fflush(stdout);
172 }
173 return use_chain[i][0][0];
174 }
|