source: branches/samba-3.0/source/script/tests/dlopen.sh

Last change on this file was 1, checked in by Paul Smedley, 18 years ago

Initial code import

File size: 2.1 KB
Line 
1#!/bin/sh
2#
3# Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19tempdir=`mktemp -d /tmp/dlopenXXXXXX`
20test -n "$tempdir" || exit 1
21cat >> $tempdir/dlopen.c << _EOF
22#include <dlfcn.h>
23#include <stdio.h>
24#include <limits.h>
25#include <sys/stat.h>
26/* Simple program to see if dlopen() would succeed. */
27int main(int argc, char **argv)
28{
29 int i;
30 struct stat st;
31 char buf[PATH_MAX];
32 for (i = 1; i < argc; i++) {
33 if (dlopen(argv[i], RTLD_NOW)) {
34 fprintf(stdout, "dlopen() of \"%s\" succeeded.\n",
35 argv[i]);
36 } else {
37 snprintf(buf, sizeof(buf), "./%s", argv[i]);
38 if ((stat(buf, &st) == 0) && dlopen(buf, RTLD_NOW)) {
39 fprintf(stdout, "dlopen() of \"./%s\" "
40 "succeeded.\n", argv[i]);
41 } else {
42 fprintf(stdout, "dlopen() of \"%s\" failed: "
43 "%s\n", argv[i], dlerror());
44 return 1;
45 }
46 }
47 }
48 return 0;
49}
50_EOF
51
52for arg in $@ ; do
53 case "$arg" in
54 "")
55 ;;
56 -I*|-D*|-f*|-m*|-g*|-O*|-W*)
57 cflags="$cflags $arg"
58 ;;
59 -l*|-L*)
60 ldflags="$ldflags $arg"
61 ;;
62 /*)
63 modules="$modules $arg"
64 ;;
65 *)
66 modules="$modules $arg"
67 ;;
68 esac
69done
70
71${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags -ldl
72
73retval=0
74for module in $modules ; do
75 case "$module" in
76 "")
77 ;;
78 /*)
79 $tempdir/dlopen "$module"
80 retval=$?
81 ;;
82 *)
83 $tempdir/dlopen ./"$module"
84 retval=$?
85 ;;
86 esac
87done
88
89rm -f $tempdir/dlopen $tempdir/dlopen.c
90rmdir $tempdir
91exit $retval
Note: See TracBrowser for help on using the repository browser.