merge the formfield patch from ooo-build
[ooovba.git] / soltools / checkdll / checkdll.c
blobcb5228fd9b43c2c5aa20feddaca823ed4bc7a330
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: checkdll.c,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <stdio.h>
33 #include <string.h>
34 #include <errno.h>
35 #include <unistd.h>
36 #include <dlfcn.h>
38 /*
39 * NOTE: Since no one is really interested in correct unload behavior I've
40 * disabled the shared library unload check. If you want to reenable it comment
41 * the following line out
43 #define NO_UNLOAD_CHECK
45 static const char *pprog_name = "checkdll";
46 static const char *psymbol = "GetVersionInfo";
48 void usage()
50 fprintf(stderr, "usage: %s [-s] <dllname>\n", pprog_name);
51 return;
54 int main(int argc, char *argv[])
56 int rc;
57 int silent=0;
58 void *phandle;
59 char *(*pfun)(void);
61 if ( argc < 2 || argc > 4) {
62 usage();
63 return 1;
66 if ( !strcmp(argv[1],"-s") ) {
67 silent = 1;
68 ++argv, --argc;
71 if ( (rc = access( argv[1], R_OK )) == -1 ) {
72 fprintf(stderr, "%s: ERROR: %s: %s\n",
73 pprog_name, argv[1], strerror(errno));
74 return 2;
77 if (!silent) printf("Checking DLL %s ...", argv[1]);
78 fflush(stdout);
80 if ( (phandle = dlopen(argv[1], RTLD_NOW)) != NULL ) {
81 if ( (pfun = (char *(*)(void))dlsym(phandle, psymbol)) != NULL ) {
82 if (!silent) printf(": ok\n");
84 else
86 printf(": WARNING: %s\n", dlerror());
88 #ifdef NO_UNLOAD_CHECK
89 _exit(0);
90 #else
91 dlclose(phandle);
92 #endif
93 return 0;
96 printf(": ERROR: %s\n", dlerror());
97 return 3;