From b3bda0d38042db4b8983b68140cf367885e01b5a Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Mon, 21 Feb 2022 10:18:58 +0000 Subject: [PATCH] dynamic: Remove iio_dynamic_scan The iio_dynamic_scan() function and all its dependencies are not needed anymore, and can be safely dropped. Signed-off-by: Paul Cercueil --- dynamic-unix.c | 41 ---------------------------- dynamic-windows.c | 57 --------------------------------------- dynamic.c | 69 ----------------------------------------------- iio-private.h | 4 --- 4 files changed, 171 deletions(-) diff --git a/dynamic-unix.c b/dynamic-unix.c index bfd275a33..7734f88ce 100644 --- a/dynamic-unix.c +++ b/dynamic-unix.c @@ -7,15 +7,8 @@ */ #include "dynamic.h" -#include "iio-private.h" -#include #include -#include - -struct iio_directory { - DIR *directory; -}; void * iio_dlopen(const char *path) { @@ -31,37 +24,3 @@ const void * iio_dlsym(void *lib, const char *symbol) { return dlsym(lib, symbol); } - -struct iio_directory * iio_open_dir(const char *path) -{ - struct iio_directory *entry; - - entry = malloc(sizeof(*entry)); - if (!entry) - return ERR_PTR(-ENOMEM); - - entry->directory = opendir(path); - if (!entry->directory) { - free(entry); - return ERR_PTR(-errno); - } - - return entry; -} - -void iio_close_dir(struct iio_directory *dir) -{ - closedir(dir->directory); - free(dir); -} - -const char * iio_dir_get_next_file_name(struct iio_directory *dir) -{ - struct dirent *dirent; - - dirent = readdir(dir->directory); - if (!dirent) - return NULL; - - return dirent->d_name; -} diff --git a/dynamic-windows.c b/dynamic-windows.c index 38df2b25e..9aca9a001 100644 --- a/dynamic-windows.c +++ b/dynamic-windows.c @@ -7,17 +7,9 @@ */ #include "dynamic.h" -#include "iio-backend.h" -#include "iio-private.h" -#include #include -struct iio_directory { - char *lastpath; - HANDLE file; -}; - void * iio_dlopen(const char *path) { return LoadLibrary(TEXT(path)); @@ -32,52 +24,3 @@ const void * iio_dlsym(void *lib, const char *symbol) { return (const void *) GetProcAddress(lib, symbol); } - -struct iio_directory * iio_open_dir(const char *path) -{ - struct iio_directory *dir; - WIN32_FIND_DATA fdata; - char buf[PATH_MAX]; - - dir = zalloc(sizeof(*dir)); - if (!dir) - return ERR_PTR(-ENOMEM); - - iio_snprintf(buf, sizeof(buf), "%s\\*", path); - - /* FindFirstFileA will always return the '.' folder if the directory - * exists, so we don't care if the related fdata is lost. */ - dir->file = FindFirstFileA(buf, &fdata); - if (dir->file == INVALID_HANDLE_VALUE) { - if (GetLastError() == ERROR_FILE_NOT_FOUND) - return ERR_PTR(-ENOENT); - else - return ERR_PTR(-EIO); - } - - return dir; -} - -void iio_close_dir(struct iio_directory *dir) -{ - if (dir->file) - FindClose(dir->file); - free (dir->lastpath); - free(dir); -} - -const char * iio_dir_get_next_file_name(struct iio_directory *dir) -{ - WIN32_FIND_DATA fdata; - - free(dir->lastpath); - - do { - if (!FindNextFileA(dir->file, &fdata)) - return NULL; - } while (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); - - dir->lastpath = _strdup(fdata.cFileName); - - return dir->lastpath; -} diff --git a/dynamic.c b/dynamic.c index 2cb8adadf..a01df9467 100644 --- a/dynamic.c +++ b/dynamic.c @@ -159,72 +159,3 @@ iio_create_dynamic_context(const struct iio_context_params *params, iio_release_module(lib); return NULL; } - -int iio_dynamic_scan(const struct iio_context_params *params, - struct iio_scan *ctx, const char *backends) -{ - struct iio_context_params params2 = *params; - const struct iio_backend *backend; - const char *path, *endchar, *startchar; - struct iio_module *lib; - struct iio_directory *dir; - char buf[256]; - int ret = 0; - - dir = iio_open_dir(IIO_MODULES_DIR); - if (IS_ERR(dir)) { - ret = PTR_ERR(dir); - - if (ret != -ENOENT) - prm_perror(params, -ret, "Unable to open modules directory"); - return ret; - } - - prm_dbg(params, "Opened directory " IIO_MODULES_DIR "\n"); - - while (true) { - path = iio_dir_get_next_file_name(dir); - if (!path) - break; - - endchar = strrchr(path, '.'); - if (!endchar || strcmp(endchar, IIO_LIBRARY_SUFFIX) || - strncmp(path, "libiio-", sizeof("libiio-") - 1)) - continue; - - startchar = path + sizeof("libiio-") - 1; - - iio_snprintf(buf, sizeof(buf), "%.*s", - (int) (endchar - startchar), startchar); - - if (backends && !iio_list_has_elem(backends, buf)) - continue; - - backend = get_iio_backend(params, buf, &lib); - if (IS_ERR(backend)) { - iio_close_dir(dir); - return PTR_ERR(backend); - } - - prm_dbg(params, "Found backend: %s\n", backend->name); - - if (params->timeout_ms) - params2.timeout_ms = params->timeout_ms; - else - params2.timeout_ms = backend->default_timeout_ms; - - if (backend->ops && backend->ops->scan) { - ret = backend->ops->scan(¶ms2, ctx, NULL); /* TODO: Support args */ - if (ret < 0) { - prm_perror(params, -ret, - "Unable to scan %s context(s)", buf); - } - } - - iio_release_module(lib); - } - - iio_close_dir(dir); - - return 0; -} diff --git a/iio-private.h b/iio-private.h index ca6a30447..e20cc1cac 100644 --- a/iio-private.h +++ b/iio-private.h @@ -158,10 +158,6 @@ void iio_release_module(struct iio_module *module); const struct iio_backend * iio_module_get_backend(struct iio_module *module); -struct iio_directory * iio_open_dir(const char *path); -void iio_close_dir(struct iio_directory *dir); -const char * iio_dir_get_next_file_name(struct iio_directory *dir); - void free_channel(struct iio_channel *chn); void free_device(struct iio_device *dev);