+
+static char **module_folders = NULL;
+
+static int init_module_folders(void)
+{
+ int n = 0;
+ struct stat st;
+ struct utsname ver;
+ char *s, *e, *p, path[256], ldpath[256];
+
+ e = ldpath;
+ s = getenv("LD_LIBRARY_PATH");
+
+ if (s)
+ e += snprintf(ldpath, sizeof(ldpath), "%s:", s);
+
+ e += snprintf(e, sizeof(ldpath) - (e - ldpath), "/lib");
+
+ uname(&ver);
+
+ for (s = p = ldpath; p <= e; p++) {
+ if (*p != ':' && *p != '\0')
+ continue;
+
+ *p = 0;
+ snprintf(path, sizeof(path), "%s" DEF_MOD_PATH, s, ver.release);
+
+ if (!stat(path, &st) && S_ISDIR(st.st_mode)) {
+ module_folders = realloc(module_folders, sizeof(p) * (n + 2));
+
+ if (!module_folders)
+ return -1;
+
+ module_folders[n++] = strdup(path);
+ }
+
+ s = p + 1;
+ }
+
+ if (!module_folders)
+ return -1;
+
+ module_folders[n] = NULL;
+ return 0;
+}