Skip to content

Commit f272886

Browse files
committed
scan: Prefer comma instead of colon for backends separator
Libiio 1.x (in the dev branch) uses a comma instead of a colon as the backends separator in the scan list string. This makes it possible to use the colon as the VID/PID separator in the USB backend parameters. Update the code and documentation to specify that commas should be used, while still allowing colons as separators to be backwards-compatible. Signed-off-by: Paul Cercueil <[email protected]>
1 parent b058c69 commit f272886

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

iio.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,18 @@ enum iio_event_direction {
236236

237237

238238
/** @brief Create a scan context
239-
* @param backend A NULL-terminated string containing the backend(s) to use for
240-
* scanning (example: pre version 0.20 : "local", "ip", or "usb"; post version
241-
* 0.20 can handle multiple, including "local:usb:", "ip:usb:", "local:usb:ip:").
242-
* If NULL, all the available backends are used.
239+
* @param backend A NULL-terminated string containing a comma-separated
240+
* list of the backend(s) to use for scanning.
243241
* @param flags Unused for now. Set to 0.
244242
* @return on success, a pointer to a iio_scan_context structure
245-
* @return On failure, NULL is returned and errno is set appropriately */
243+
* @return On failure, NULL is returned and errno is set appropriately
244+
*
245+
* <b>NOTE:</b> Libiio version 0.20 and above can handle multiple
246+
* strings, for instance "local:usb:", "ip:usb:", "local:usb:ip:", and
247+
* require a colon as the delimiter. If NULL, the local, USB and IP
248+
* backends will be scanned.
249+
* Libiio version 0.24 and above prefer a comma instead of colon as the
250+
* delimiter. */
246251
__api __check_ret struct iio_scan_context * iio_create_scan_context(
247252
const char *backend, unsigned int flags);
248253

scan.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx,
3636
char *token, *rest=NULL;
3737
ssize_t ret;
3838

39-
for (token = iio_strtok_r(ctx->backendopts, ":", &rest);
40-
token; token = iio_strtok_r(NULL, ":", &rest)) {
39+
for (token = iio_strtok_r(ctx->backendopts, ",", &rest);
40+
token; token = iio_strtok_r(NULL, ",", &rest)) {
4141

4242
/* Since tokens are all null terminated, it's safe to use strcmp on them */
4343
if (WITH_LOCAL_BACKEND && !strcmp(token, "local")) {
@@ -108,6 +108,7 @@ struct iio_scan_context * iio_create_scan_context(
108108
const char *backend, unsigned int flags)
109109
{
110110
struct iio_scan_context *ctx;
111+
unsigned int i, len;
111112

112113
/* "flags" must be zero for now */
113114
if (flags != 0) {
@@ -121,13 +122,21 @@ struct iio_scan_context * iio_create_scan_context(
121122
return NULL;
122123
}
123124

124-
ctx->backendopts = iio_strndup(backend ? backend : "local:usb:ip", PATH_MAX);
125+
ctx->backendopts = iio_strndup(backend ? backend : "local,usb,ip", PATH_MAX);
125126
if (!ctx->backendopts) {
126127
free(ctx);
127128
errno = ENOMEM;
128129
return NULL;
129130
}
130131

132+
if (backend) {
133+
/* Replace the colon separator with a comma. */
134+
len = strlen(ctx->backendopts);
135+
for (i = 0; i < len; i++)
136+
if (ctx->backendopts[i] == ':')
137+
ctx->backendopts[i] = ',';
138+
}
139+
131140
return ctx;
132141
}
133142

0 commit comments

Comments
 (0)