diff options
author | Kenjiro Tsuji <kenjiro.tsuji@oracle.com> | 2019-09-25 16:40:11 -0700 |
---|---|---|
committer | Nathan Hjelm <hjelmn@google.com> | 2019-09-26 11:45:39 -0600 |
commit | 17348731b48702cece1bc783b3764975e495840d (patch) | |
tree | 11388544e81d7973c71ed33d28dd2260164d7c8c | |
parent | 8b04a5510f541306e37ad8cfa83984f913fa08d1 (diff) | |
download | libusb-17348731b48702cece1bc783b3764975e495840d.tar.gz |
Solaris backend depends on Solaris private symbols
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>
-rw-r--r-- | libusb/os/sunos_usb.c | 74 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
2 files changed, 33 insertions, 43 deletions
diff --git a/libusb/os/sunos_usb.c b/libusb/os/sunos_usb.c index 185c371..cbca379 100644 --- a/libusb/os/sunos_usb.c +++ b/libusb/os/sunos_usb.c @@ -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> @@ -46,11 +45,13 @@ #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); } diff --git a/libusb/version_nano.h b/libusb/version_nano.h index c09c5a4..6a53476 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11401 +#define LIBUSB_NANO 11402 |