libusb10.c (aa87aa52326be7b726664dba65e91ec3d8160f48) | libusb10.c (4c6bcffd04f9d0b6cb57af0ffcc9be3098fe950c) |
---|---|
1/* $FreeBSD$ */ 2/*- 3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 4 * 5 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. | 1/* $FreeBSD$ */ 2/*- 3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 4 * 5 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. |
6 * Copyright (c) 2009 Hans Petter Selasky. All rights reserved. | 6 * Copyright (c) 2009-2023 Hans Petter Selasky |
7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the --- 116 unchanged lines hidden (view full) --- 131 /* ignore error, if any */ 132 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "Waking up event loop failed!"); 133 } 134} 135 136int 137libusb_init(libusb_context **context) 138{ | 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the --- 116 unchanged lines hidden (view full) --- 131 /* ignore error, if any */ 132 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "Waking up event loop failed!"); 133 } 134} 135 136int 137libusb_init(libusb_context **context) 138{ |
139 return (libusb_init_context(context, NULL, 0)); 140} 141 142int 143libusb_init_context(libusb_context **context, 144 const struct libusb_init_option option[], int num_options) 145{ |
|
139 struct libusb_context *ctx; 140 pthread_condattr_t attr; 141 char *debug, *ep; 142 int ret; 143 | 146 struct libusb_context *ctx; 147 pthread_condattr_t attr; 148 char *debug, *ep; 149 int ret; 150 |
151 if (num_options < 0) 152 return (LIBUSB_ERROR_INVALID_PARAM); 153 |
|
144 ctx = malloc(sizeof(*ctx)); 145 if (!ctx) 146 return (LIBUSB_ERROR_INVALID_PARAM); 147 148 memset(ctx, 0, sizeof(*ctx)); 149 150 debug = getenv("LIBUSB_DEBUG"); 151 if (debug != NULL) { 152 /* | 154 ctx = malloc(sizeof(*ctx)); 155 if (!ctx) 156 return (LIBUSB_ERROR_INVALID_PARAM); 157 158 memset(ctx, 0, sizeof(*ctx)); 159 160 debug = getenv("LIBUSB_DEBUG"); 161 if (debug != NULL) { 162 /* |
153 * If LIBUSB_DEBUG is set, we'll honor that and use it to 154 * override libusb_set_debug calls. | 163 * If LIBUSB_DEBUG is set, we'll honor that first and 164 * use it to override any future libusb_set_debug() 165 * calls or init options. |
155 */ 156 errno = 0; 157 ctx->debug = strtol(debug, &ep, 10); 158 if (errno == 0 && *ep == '\0') { 159 ctx->debug_fixed = 1; 160 } else { 161 /* 162 * LIBUSB_DEBUG conversion failed for some reason, but 163 * we don't care about the specifics all that much. We 164 * can't use it either way. Force it to the default, 165 * 0, in case we had a partial number. 166 */ 167 ctx->debug = 0; 168 } | 166 */ 167 errno = 0; 168 ctx->debug = strtol(debug, &ep, 10); 169 if (errno == 0 && *ep == '\0') { 170 ctx->debug_fixed = 1; 171 } else { 172 /* 173 * LIBUSB_DEBUG conversion failed for some reason, but 174 * we don't care about the specifics all that much. We 175 * can't use it either way. Force it to the default, 176 * 0, in case we had a partial number. 177 */ 178 ctx->debug = 0; 179 } |
180 } else { 181 /* 182 * If the LIBUSB_OPTION_LOG_LEVEL is set, honor that. 183 */ 184 for (int i = 0; i != num_options; i++) { 185 if (option[i].option != LIBUSB_OPTION_LOG_LEVEL) 186 continue; 187 188 ctx->debug = (int)option[i].value.ival; 189 if ((int64_t)ctx->debug == option[i].value.ival) { 190 ctx->debug_fixed = 1; 191 } else { 192 free(ctx); 193 return (LIBUSB_ERROR_INVALID_PARAM); 194 } 195 } |
|
169 } | 196 } |
197 |
|
170 TAILQ_INIT(&ctx->pollfds); 171 TAILQ_INIT(&ctx->tr_done); 172 TAILQ_INIT(&ctx->hotplug_cbh); 173 TAILQ_INIT(&ctx->hotplug_devs); 174 175 if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) { 176 free(ctx); 177 return (LIBUSB_ERROR_NO_MEM); --- 1572 unchanged lines hidden --- | 198 TAILQ_INIT(&ctx->pollfds); 199 TAILQ_INIT(&ctx->tr_done); 200 TAILQ_INIT(&ctx->hotplug_cbh); 201 TAILQ_INIT(&ctx->hotplug_devs); 202 203 if (pthread_mutex_init(&ctx->ctx_lock, NULL) != 0) { 204 free(ctx); 205 return (LIBUSB_ERROR_NO_MEM); --- 1572 unchanged lines hidden --- |