1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include <dlfcn.h>
30
31 /*
32 * NOTE: Since no one is really interested in correct unload behavior I've
33 * disabled the shared library unload check. If you want to reenable it comment
34 * the following line out
35 */
36 #define NO_UNLOAD_CHECK
37
38 static const char *pprog_name = "checkdll";
39 static const char *psymbol = "GetVersionInfo";
40
usage()41 void usage()
42 {
43 fprintf(stderr, "usage: %s [-s] <dllname>\n", pprog_name);
44 return;
45 }
46
main(int argc,char * argv[])47 int main(int argc, char *argv[])
48 {
49 int rc;
50 int silent=0;
51 void *phandle;
52 char *(*pfun)(void);
53
54 if ( argc < 2 || argc > 4) {
55 usage();
56 return 1;
57 }
58
59 if ( !strcmp(argv[1],"-s") ) {
60 silent = 1;
61 ++argv, --argc;
62 }
63
64 if ( (rc = access( argv[1], R_OK )) == -1 ) {
65 fprintf(stderr, "%s: ERROR: %s: %s\n",
66 pprog_name, argv[1], strerror(errno));
67 return 2;
68 }
69
70 if (!silent) printf("Checking DLL %s ...", argv[1]);
71 fflush(stdout);
72
73 if ( (phandle = dlopen(argv[1], RTLD_NOW)) != NULL ) {
74 if ( (pfun = (char *(*)(void))dlsym(phandle, psymbol)) != NULL ) {
75 if (!silent) printf(": ok\n");
76 }
77 else
78 {
79 printf(": WARNING: %s\n", dlerror());
80 }
81 #ifdef NO_UNLOAD_CHECK
82 _exit(0);
83 #else
84 dlclose(phandle);
85 #endif
86 return 0;
87 }
88
89 printf(": ERROR: %s\n", dlerror());
90 return 3;
91 }
92
93
94