Samba 3: added Samba 3.0.24 sources
[tomato.git] / release / src / router / samba3 / source / script / tests / dlopen.sh
blob61279536927c03cedf29ba429f5927848d01643e
1 #!/bin/sh
3 # Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2003
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.
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.
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.
19 tempdir=`mktemp -d /tmp/dlopenXXXXXX`
20 test -n "$tempdir" || exit 1
21 cat >> $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. */
27 int main(int argc, char **argv)
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;
48 return 0;
50 _EOF
52 for arg in $@ ; do
53 case "$arg" in
54 "")
56 -I*|-D*|-f*|-m*|-g*|-O*|-W*)
57 cflags="$cflags $arg"
59 -l*|-L*)
60 ldflags="$ldflags $arg"
62 /*)
63 modules="$modules $arg"
66 modules="$modules $arg"
68 esac
69 done
71 ${CC:-gcc} $RPM_OPT_FLAGS $CFLAGS -o $tempdir/dlopen $cflags $tempdir/dlopen.c $ldflags -ldl
73 retval=0
74 for module in $modules ; do
75 case "$module" in
76 "")
78 /*)
79 $tempdir/dlopen "$module"
80 retval=$?
83 $tempdir/dlopen ./"$module"
84 retval=$?
86 esac
87 done
89 rm -f $tempdir/dlopen $tempdir/dlopen.c
90 rmdir $tempdir
91 exit $retval