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
5 +1999-04-28 Petter Reinholdtsen <pere@td.org.uit.no>
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
13 1999-04-19 David Mosberger-Tang <David.Mosberger@acm.org>
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
24 +# define DLL_PATH_ENV "LIBPATH"
26 +# define DLL_PATH_ENV "LD_LIBRARY_PATH"
28 +# define DLL_PATH_SEPARATOR ":"
29 +# define DLL_SLASH "/"
30 +# define DLL_NAME "libsane-%s.so." STRINGIFY(V_MAJOR)
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)
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)
46 return SANE_STATUS_GOOD;
49 - be = malloc (sizeof (*be));
50 + be = calloc (1, sizeof (*be));
52 return SANE_STATUS_NO_MEM;
54 - memset (be, 0, sizeof (*be));
55 be->name = strdup (name);
57 return SANE_STATUS_NO_MEM;
59 load (struct backend *be)
63 + int funcnamesize = 0;
64 char *funcname, *src, *dir, *path = 0;
65 char libname[PATH_MAX];
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;
78 -# error "Tried to compile unsupported DLL."
79 -#endif /* HAVE_DLOPEN */
81 DBG(1, "loading backend %s\n", be->name);
83 /* initialize all ops to "unsupported" so we can "use" the backend
85 dir = STRINGIFY(LIBDIR);
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,
93 fp = fopen (libname, "r");
99 - path = getenv ("LD_LIBRARY_PATH");
102 - path = getenv ("SHLIB_PATH"); /* for HP-UX */
104 - path = getenv ("LIBPATH"); /* for AIX */
106 + path = getenv (DLL_PATH_ENV);
110 path = strdup (path);
113 - dir = strsep (&src, ":");
114 + dir = strsep (&src, DLL_PATH_SEPARATOR);
118 @@ -294,57 +286,52 @@
119 DBG(2, "dlopen()ing `%s'\n", libname);
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);
128 # error "Tried to compile unsupported DLL."
129 #endif /* HAVE_DLOPEN */
133 + DBG(2, "dlopen() failed (%s)\n", dlerror());
135 DBG(2, "dlopen() failed (%s)\n", strerror (errno));
137 return SANE_STATUS_INVAL;
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)
149 - sprintf (funcname, "_sane_%s_%s", be->name, op_name[i]);
150 + snprintf (funcname, funcnamesize, "_sane_%s_%s", be->name, op_name[i]);
152 /* First try looking up the symbol without a leading underscore. */
153 + /* Then try again, with an underscore prepended. */
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_);
161 # error "Tried to compile unsupported DLL."
162 #endif /* HAVE_DLOPEN */
166 + if (NULL != op || NULL != op_)
167 + be->op[i] = (NULL != op) ? op : op_;
170 - /* Try again, with an underscore prepended. */
172 - op = (void *(*)()) dlsym (be->handle, funcname);
173 -#elif defined(HAVE_SHL_LOAD)
174 - shl_findsym (be->handle, funcname, TYPE_UNDEFINED, &op);
176 -# error "Tried to compile unsupported DLL."
177 -#endif /* HAVE_DLOPEN */
182 DBG(2, "unable to find %s\n", funcname);
185 return SANE_STATUS_GOOD;
190 DBG(1, "load: ignoring attempt to load `%s'; compiled without dl support\n",
192 @@ -441,15 +428,16 @@
193 (*be->op[OP_EXIT]) ();
198 - dlclose (be->handle);
201 + dlclose (be->handle);
202 #elif defined(HAVE_SHL_LOAD)
204 - shl_unload(be->handle);
205 + shl_unload(be->handle);
207 # error "Tried to compile unsupported DLL."
208 #endif /* HAVE_DLOPEN */
211 #endif /* HAVE_DLL */
213 @@ -607,11 +595,10 @@
214 if (status != SANE_STATUS_GOOD)
217 - s = malloc (sizeof (*s));
218 + s = calloc (1, sizeof (*s));
220 return SANE_STATUS_NO_MEM;
222 - memset (s, 0, sizeof (*s));