]> pere.pagekite.me Git - homepage.git/blob - linux/sane/19990428-sane-dll-cleanup.diff
Generated.
[homepage.git] / linux / sane / 19990428-sane-dll-cleanup.diff
1 diff -ur sane-1.0.1/ChangeLog sane-1.0.1-pere/ChangeLog
2 --- sane-1.0.1/ChangeLog Mon Apr 19 18:21:33 1999
3 +++ sane-1.0.1-pere/ChangeLog Wed Apr 28 00:52:19 1999
4 @@ -1,3 +1,11 @@
5 +1999-04-28 Petter Reinholdtsen <pere@td.org.uit.no>
6 +
7 + * backend/dll.c: Cleanup. Use calloc() instead of
8 + malloc/memset(0). Only check the correct environment path
9 + variables. Make ifdef'ed code smaller and clearer. Include
10 + bugfix reported by Ingo Wilken: use dlerror() instead of
11 + strerror(errno).
12 +
13 1999-04-19 David Mosberger-Tang <David.Mosberger@acm.org>
14
15 * Version 1.0.1 released.
16 diff -ur sane-1.0.1/backend/dll.c sane-1.0.1-pere/backend/dll.c
17 --- sane-1.0.1/backend/dll.c Sun Feb 28 00:51:37 1999
18 +++ sane-1.0.1-pere/backend/dll.c Wed Apr 28 01:01:58 1999
19 @@ -68,12 +68,22 @@
20 # ifndef RTLD_LAZY
21 # define RTLD_LAZY 1
22 # endif
23 +# if defined(_AIX)
24 +# define DLL_PATH_ENV "LIBPATH"
25 +# else
26 +# define DLL_PATH_ENV "LD_LIBRARY_PATH"
27 +# endif
28 +# define DLL_PATH_SEPARATOR ":"
29 +# define DLL_SLASH "/"
30 +# define DLL_NAME "libsane-%s.so." STRINGIFY(V_MAJOR)
31 # define HAVE_DLL
32 -#endif
33 -
34 +#elif defined (HAVE_SHL_LOAD) && defined(HAVE_DL_H)
35 /* HP/UX DLL support */
36 -#if defined (HAVE_SHL_LOAD) && defined(HAVE_DL_H)
37 # include <dl.h>
38 +# define DLL_PATH_ENV "SHLIB_PATH"
39 +# define DLL_PATH_SEPARATOR ":"
40 +# define DLL_SLASH "/"
41 +# define DLL_NAME "libsane-%s.sl." STRINGIFY(V_MAJOR)
42 # define HAVE_DLL
43 #endif
44
45 @@ -211,11 +221,10 @@
46 return SANE_STATUS_GOOD;
47 }
48
49 - be = malloc (sizeof (*be));
50 + be = calloc (1, sizeof (*be));
51 if (!be)
52 return SANE_STATUS_NO_MEM;
53
54 - memset (be, 0, sizeof (*be));
55 be->name = strdup (name);
56 if (!be->name)
57 return SANE_STATUS_NO_MEM;
58 @@ -230,24 +239,12 @@
59 load (struct backend *be)
60 {
61 #ifdef HAVE_DLL
62 - int mode = 0;
63 + int funcnamesize = 0;
64 char *funcname, *src, *dir, *path = 0;
65 char libname[PATH_MAX];
66 int i;
67 FILE *fp = 0;
68
69 -#if defined(HAVE_DLOPEN)
70 -# define PREFIX "libsane-"
71 -# define POSTFIX ".so.%u"
72 - mode = getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY;
73 -#elif defined(HAVE_SHL_LOAD)
74 -# define PREFIX "libsane-"
75 -# define POSTFIX ".sl.%u"
76 - mode = BIND_DEFERRED;
77 -#else
78 -# error "Tried to compile unsupported DLL."
79 -#endif /* HAVE_DLOPEN */
80 -
81 DBG(1, "loading backend %s\n", be->name);
82
83 /* initialize all ops to "unsupported" so we can "use" the backend
84 @@ -260,28 +257,23 @@
85 dir = STRINGIFY(LIBDIR);
86 while (dir)
87 {
88 - snprintf (libname, sizeof (libname), "%s/"PREFIX"%s"POSTFIX,
89 - dir, be->name, V_MAJOR);
90 + /* Make string like "<libdir>/sane-<backend>.so.<version>" */
91 + snprintf (libname, sizeof (libname), "%s" DLL_SLASH DLL_NAME,
92 + dir, be->name);
93 fp = fopen (libname, "r");
94 if (fp)
95 break;
96
97 if (!path)
98 {
99 - path = getenv ("LD_LIBRARY_PATH");
100 - if (!path)
101 - {
102 - path = getenv ("SHLIB_PATH"); /* for HP-UX */
103 - if (!path)
104 - path = getenv ("LIBPATH"); /* for AIX */
105 - }
106 + path = getenv (DLL_PATH_ENV);
107 if (!path)
108 break;
109
110 path = strdup (path);
111 src = path;
112 }
113 - dir = strsep (&src, ":");
114 + dir = strsep (&src, DLL_PATH_SEPARATOR);
115 }
116 if (path)
117 free (path);
118 @@ -294,57 +286,52 @@
119 DBG(2, "dlopen()ing `%s'\n", libname);
120
121 #ifdef HAVE_DLOPEN
122 - be->handle = dlopen (libname, mode);
123 + be->handle = dlopen (libname, getenv ("LD_BIND_NOW") ? RTLD_NOW : RTLD_LAZY);
124 #elif defined(HAVE_SHL_LOAD)
125 - be->handle = (shl_t)shl_load (libname, mode, 0L);
126 + be->handle = (shl_t)shl_load (libname, BIND_DEFERRED, 0L);
127 #else
128 # error "Tried to compile unsupported DLL."
129 #endif /* HAVE_DLOPEN */
130 if (!be->handle)
131 {
132 +#ifdef HAVE_DLOPEN
133 + DBG(2, "dlopen() failed (%s)\n", dlerror());
134 +#else
135 DBG(2, "dlopen() failed (%s)\n", strerror (errno));
136 +#endif
137 return SANE_STATUS_INVAL;
138 }
139
140 /* all is dandy---lookup and fill in backend ops: */
141 - funcname = alloca (strlen (be->name) + 64);
142 + funcnamesize = strlen (be->name) + 64;
143 + funcname = alloca (funcnamesize);
144 for (i = 0; i < NUM_OPS; ++i)
145 {
146 void *(*op) ();
147 + void *(*op_) ();
148
149 - sprintf (funcname, "_sane_%s_%s", be->name, op_name[i]);
150 + snprintf (funcname, funcnamesize, "_sane_%s_%s", be->name, op_name[i]);
151
152 /* First try looking up the symbol without a leading underscore. */
153 + /* Then try again, with an underscore prepended. */
154 #ifdef HAVE_DLOPEN
155 op = (void *(*)()) dlsym (be->handle, funcname + 1);
156 + op_ = (void *(*)()) dlsym (be->handle, funcname);
157 #elif defined(HAVE_SHL_LOAD)
158 shl_findsym ((shl_t*)&(be->handle), funcname + 1, TYPE_UNDEFINED, &op);
159 + shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op_);
160 #else
161 # error "Tried to compile unsupported DLL."
162 #endif /* HAVE_DLOPEN */
163 - if (op)
164 - be->op[i] = op;
165 +
166 + if (NULL != op || NULL != op_)
167 + be->op[i] = (NULL != op) ? op : op_;
168 else
169 - {
170 - /* Try again, with an underscore prepended. */
171 -#ifdef HAVE_DLOPEN
172 - op = (void *(*)()) dlsym (be->handle, funcname);
173 -#elif defined(HAVE_SHL_LOAD)
174 - shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
175 -#else
176 -# error "Tried to compile unsupported DLL."
177 -#endif /* HAVE_DLOPEN */
178 - if (op)
179 - be->op[i] = op;
180 - }
181 - if (NULL == op)
182 DBG(2, "unable to find %s\n", funcname);
183 }
184
185 return SANE_STATUS_GOOD;
186
187 -# undef PREFIX
188 -# undef POSTFIX
189 #else /* HAVE_DLL */
190 DBG(1, "load: ignoring attempt to load `%s'; compiled without dl support\n",
191 be->name);
192 @@ -441,15 +428,16 @@
193 (*be->op[OP_EXIT]) ();
194 #ifdef HAVE_DLL
195
196 -#ifdef HAVE_DLOPEN
197 if (be->handle)
198 - dlclose (be->handle);
199 + {
200 +#ifdef HAVE_DLOPEN
201 + dlclose (be->handle);
202 #elif defined(HAVE_SHL_LOAD)
203 - if (be->handle)
204 - shl_unload(be->handle);
205 + shl_unload(be->handle);
206 #else
207 # error "Tried to compile unsupported DLL."
208 #endif /* HAVE_DLOPEN */
209 + }
210
211 #endif /* HAVE_DLL */
212 }
213 @@ -607,11 +595,10 @@
214 if (status != SANE_STATUS_GOOD)
215 return status;
216
217 - s = malloc (sizeof (*s));
218 + s = calloc (1, sizeof (*s));
219 if (!s)
220 return SANE_STATUS_NO_MEM;
221
222 - memset (s, 0, sizeof (*s));
223 s->be = be;
224 s->handle = handle;
225 *meta_handle = s;