File: dltest.c

package info (click to toggle)
myodbc 3.51.09-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 4,400 kB
  • ctags: 1,596
  • sloc: ansic: 29,806; sh: 10,765; cpp: 627; makefile: 610
file content (89 lines) | stat: -rw-r--r-- 2,791 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <stdlib.h>
#include <ltdl.h>

char *szSyntax =
"\n" \
"**********************************************\n" \
"* dltest                                     *\n" \
"**********************************************\n" \
"* Syntax                                     *\n" \
"*                                            *\n" \
"*      dltest libName Symbol                 *\n" \
"*                                            *\n" \
"* libName                                    *\n" \
"*                                            *\n" \
"*      Full path + file name of share to test*\n" \
"*                                            *\n" \
"* Symbol                                     *\n" \
"*                                            *\n" \
"*      ie a function name in the share       *\n" \
"*                                            *\n" \
"* Notes                                      *\n" \
"*                                            *\n" \
"*      This can be placed into a makefile    *\n" \
"*      to throw an error if test fails.      *\n" \
"*                                            *\n" \
"*      If this segfaults you probably have an*\n" \
"*      unresolved symbol in the lib. This is *\n" \
"*      not caught since dltest started using *\n" \
"*      libtool. Linux users can refer to the *\n" \
"*      man page for dlopen to create a       *\n" \
"*      better test.                          *\n" \
"*                                            *\n" \
"*                                            *\n" \
"* Examples                                   *\n" \
"*                                            *\n" \
"*      dltest /usr/lib/libMy.so MyFunc       *\n" \
"*                                            *\n" \
"**********************************************\n\n";

int main( int argc, char *argv[] )
{
	void	*hDLL;
	void	(*pFunc)();
	const char	*pError;

	if ( argc < 2  )
	{
		printf( szSyntax );
		exit( 1 );
	}

    /*
     * initialize libtool
     */

    if ( lt_dlinit() )
	{
		printf( "ERROR: Failed to lt_dlinit()\n" );
		exit( 1 );
	}

    hDLL = lt_dlopen( argv[1] );
	if ( !hDLL )
	{
		printf( "[dltest] ERROR dlopen: %s\n", lt_dlerror() );
		exit( 1 );
	}
	printf( "SUCCESS: Loaded %s\n", argv[1] );
	if ( argc > 2 )
	{
		pFunc = (void (*)()) lt_dlsym( hDLL, argv[2] );
/* PAH - lt_dlerror() is not a good indicator of success    */
/*		if ( (pError = lt_dlerror()) != NULL )              */
		if ( !pFunc )
		{
            if ( (pError = lt_dlerror()) != NULL )
			    printf( "ERROR: %s\n Could not find %s\n", pError, argv[2] );
            else
			    printf( "ERROR: Could not find %s\n", argv[2] );
			exit( 1 );
		}
		printf( "SUCCESS: Found %s\n", argv[2] );
	}
	lt_dlclose( hDLL );

	return ( 0 );
}