Skip to content

Commit

Permalink
dynamic: Remove iio_dynamic_scan
Browse files Browse the repository at this point in the history
The iio_dynamic_scan() function and all its dependencies are not needed
anymore, and can be safely dropped.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Feb 24, 2022
1 parent 8b4de8b commit b3bda0d
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 171 deletions.
41 changes: 0 additions & 41 deletions dynamic-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@
*/

#include "dynamic.h"
#include "iio-private.h"

#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>

struct iio_directory {
DIR *directory;
};

void * iio_dlopen(const char *path)
{
Expand All @@ -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;
}
57 changes: 0 additions & 57 deletions dynamic-windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@
*/

#include "dynamic.h"
#include "iio-backend.h"
#include "iio-private.h"

#include <errno.h>
#include <windows.h>

struct iio_directory {
char *lastpath;
HANDLE file;
};

void * iio_dlopen(const char *path)
{
return LoadLibrary(TEXT(path));
Expand All @@ -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;
}
69 changes: 0 additions & 69 deletions dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params2, 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;
}
4 changes: 0 additions & 4 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b3bda0d

Please sign in to comment.