summaryrefslogtreecommitdiff
path: root/backend/dll.c
diff options
context:
space:
mode:
Diffstat (limited to 'backend/dll.c')
-rw-r--r--backend/dll.c41
1 files changed, 20 insertions, 21 deletions
diff --git a/backend/dll.c b/backend/dll.c
index 5eaa046..8f0983d 100644
--- a/backend/dll.c
+++ b/backend/dll.c
@@ -42,7 +42,7 @@
allows managing an arbitrary number of SANE backends by using
dynamic linking to load backends on demand. */
-/* Please increase version number with every change
+/* Please increase version number with every change
(don't forget to update dll.desc) */
#define DLL_VERSION "1.0.13"
@@ -353,7 +353,7 @@ load (struct backend *be)
image_id id = -1;
int i, w;
directory_which which[3] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY };
-
+
/* look for config files in SANE/conf */
for (w = 0; (w < 3) && (id < 0) && (find_directory(which[w],0,true,path,PATH_MAX) == 0); w++)
{
@@ -373,7 +373,7 @@ load (struct backend *be)
continue; /* try next path */
}
be->handle=(void *)id;
-
+
for (i = 0; i < NUM_OPS; ++i)
{
void *(*op) ();
@@ -492,7 +492,7 @@ load (struct backend *be)
break;
DBG (4, "load: couldn't open `%s' (%s)\n", libname, strerror (errno));
-#ifdef ALT_POSTFIX
+#ifdef ALT_POSTFIX
/* Some platforms have two ways of storing their libraries, try both
postfixes */
snprintf (libname, sizeof (libname), "%s/" PREFIX "%s" ALT_POSTFIX,
@@ -882,7 +882,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
char path[1024];
directory_which which[3] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, B_BEOS_ADDONS_DIRECTORY };
int i;
-#endif
+#endif
DBG_INIT ();
@@ -934,7 +934,7 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
}
fclose (fp);
-#else
+#else
/* no ugly config files, just get scanners from their ~/config/add-ons/SANE */
/* look for drivers */
for (i = 0; i < 3; i++)
@@ -943,13 +943,13 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
continue;
strcat(path,"/SANE/");
dir=opendir(path);
- if(!dir) continue;
+ if(!dir) continue;
while((dirent=readdir(dir)))
{
if((strcmp(dirent->d_name,".")==0) || (strcmp(dirent->d_name,"..")==0)) continue;
if((strcmp(dirent->d_name,"dll")==0)) continue;
- add_backend(dirent->d_name,0);
+ add_backend(dirent->d_name,0);
}
closedir(dir);
}
@@ -1155,7 +1155,8 @@ sane_get_devices (const SANE_Device *** device_list, SANE_Bool local_only)
SANE_Status
sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
{
- const char *be_name, *dev_name;
+ char *be_name;
+ const char *dev_name;
struct meta_scanner *s;
SANE_Handle handle;
struct backend *be;
@@ -1178,16 +1179,7 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
dev_name = strchr (full_name, ':');
if (dev_name)
{
-#ifdef strndupa
- be_name = strndupa (full_name, dev_name - full_name);
-#else
- char *tmp;
-
- tmp = alloca (dev_name - full_name + 1);
- memcpy (tmp, full_name, dev_name - full_name);
- tmp[dev_name - full_name] = '\0';
- be_name = tmp;
-#endif
+ be_name = strndup(full_name, dev_name - full_name);
++dev_name; /* skip colon */
}
else
@@ -1195,10 +1187,13 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
/* if no colon interpret full_name as the backend name; an empty
backend device name will cause us to open the first device of
that backend. */
- be_name = full_name;
+ be_name = strdup(full_name);
dev_name = "";
}
+ if (!be_name)
+ return SANE_STATUS_NO_MEM;
+
if (!be_name[0])
be = first_backend;
else
@@ -1210,8 +1205,12 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle)
{
status = add_backend (be_name, &be);
if (status != SANE_STATUS_GOOD)
- return status;
+ {
+ free(be_name);
+ return status;
+ }
}
+ free(be_name);
if (!be->inited)
{