Solaris backend depends on Solaris private symbols
authorKenjiro Tsuji <kenjiro.tsuji@oracle.com>
Wed, 25 Sep 2019 23:40:11 +0000 (16:40 -0700)
committerNathan Hjelm <hjelmn@google.com>
Thu, 26 Sep 2019 17:45:39 +0000 (11:45 -0600)
Solaris backend depends on the following double-linked list operation functions
from libcmdutils:
list_insert_tail, list_create, list_remote_head, list_head, list_next
However, they are private symbols in libcmdutils library and moreover libcmdutils
library is also a private library. libusb should not directly refer those symbols.
Due to this issue, linking a program with libusb fails on the SPARC platform.
This issue has been reported as #586.
Since the code using those functions is just to build the argument list for execv,
the double-linked list operation functions do not need to be used.

Closes #627

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/os/sunos_usb.c
libusb/version_nano.h

index 185c371..cbca379 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <sys/time.h>
 #include <sys/types.h>
-#include <sys/list.h>
 #include <sys/stat.h>
 #include <strings.h>
 #include <errno.h>
 #define UPDATEDRV_PATH "/usr/sbin/update_drv"
 #define UPDATEDRV      "update_drv"
 
-typedef list_t string_list_t;
-typedef struct string_node {
-       char            *string;
-       list_node_t     link;
-} string_node_t;
+#define        DEFAULT_LISTSIZE        6
+
+typedef struct {
+       int     nargs;
+       int     listsize;
+       char    **string;
+} string_list_t;
 
 /*
  * Backend functions
@@ -259,10 +260,14 @@ sunos_new_string_list(void)
 {
        string_list_t *list;
 
-       list = calloc(1, sizeof(*list));
-       if (list != NULL)
-               list_create(list, sizeof(string_node_t),
-                           offsetof(string_node_t, link));
+       list = calloc(1, sizeof (string_list_t));
+       if (list == NULL)
+               return (NULL);
+       list->string = calloc(DEFAULT_LISTSIZE, sizeof (char *));
+       if (list->string == NULL)
+               return (NULL);
+       list->nargs = 0;
+       list->listsize = DEFAULT_LISTSIZE;
 
        return (list);
 }
@@ -270,19 +275,22 @@ sunos_new_string_list(void)
 static int
 sunos_append_to_string_list(string_list_t *list, const char *arg)
 {
-       string_node_t *np;
+       char    *str = strdup(arg);
 
-       np = calloc(1, sizeof(*np));
-       if (!np)
+       if (str == NULL)
                return (-1);
 
-       np->string = strdup(arg);
-       if (!np->string) {
-               free(np);
-               return (-1);
+       if ((list->nargs + 1) == list->listsize) { /* +1 is for NULL */
+               char    **tmp = realloc(list->string,
+                   sizeof (char *) * (list->listsize + 1));
+               if (tmp == NULL) {
+                       free(str);
+                       return (-1);
+               }
+               list->string = tmp;
+               list->string[list->listsize++] = NULL;
        }
-
-       list_insert_tail(list, np);
+       list->string[list->nargs++] = str;
 
        return (0);
 }
@@ -290,36 +298,20 @@ sunos_append_to_string_list(string_list_t *list, const char *arg)
 static void
 sunos_free_string_list(string_list_t *list)
 {
-       string_node_t *np;
+       int     i;
 
-       while ((np = list_remove_head(list)) != NULL) {
-               free(np->string);
-               free(np);
+       for (i = 0; i < list->nargs; i++) {
+               free(list->string[i]);
        }
 
+       free(list->string);
        free(list);
 }
 
 static char **
 sunos_build_argv_list(string_list_t *list)
 {
-       char **argv_list;
-       string_node_t *np;
-       int n;
-
-       n = 1; /* Start at 1 for NULL terminator */
-       for (np = list_head(list); np != NULL; np = list_next(list, np))
-               n++;
-
-       argv_list = calloc(n, sizeof(char *));
-       if (argv_list == NULL)
-               return NULL;
-
-       n = 0;
-       for (np = list_head(list); np != NULL; np = list_next(list, np))
-               argv_list[n++] = np->string;
-
-       return (argv_list);
+       return (list->string);
 }
 
 
@@ -364,8 +356,6 @@ sunos_exec_command(struct libusb_context *ctx, const char *path,
                exit_status = -1;
        }
 
-       free(argv_list);
-
        return (exit_status);
 }
 
index c09c5a4..6a53476 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11401
+#define LIBUSB_NANO 11402