static void open_modules_for_path (const char * path) { GDir * folder = g_dir_open (path, 0, NULL); if (! folder) { fprintf (stderr, "ladspa: Failed to read folder %s: %s\n", path, strerror (errno)); return; } const char * name; while ((name = g_dir_read_name (folder))) { if (! str_has_suffix_nocase (name, G_MODULE_SUFFIX)) continue; char * filename = filename_build (path, name); void * handle = open_module (filename); if (handle) index_insert (modules, -1, handle); str_unref (filename); } g_dir_close (folder); }
char * write_temp_file (void * data, int64_t len) { char * temp = filename_build (g_get_tmp_dir (), "audacious-temp-XXXXXX"); SCOPY (name, temp); str_unref (temp); int handle = g_mkstemp (name); if (handle < 0) { fprintf (stderr, "Error creating temporary file: %s\n", strerror (errno)); return NULL; } while (len) { int64_t written = write (handle, data, len); if (written < 0) { fprintf (stderr, "Error writing %s: %s\n", name, strerror (errno)); close (handle); return NULL; } data = (char *) data + written; len -= written; } if (close (handle) < 0) { fprintf (stderr, "Error closing %s: %s\n", name, strerror (errno)); return NULL; } return str_get (name); }
static char * get_path (void) { char * path = aud_get_str ("search-tool", "path"); if (g_file_test (path, G_FILE_TEST_EXISTS)) return path; str_unref (path); path = filename_build (g_get_home_dir (), "Music"); if (g_file_test (path, G_FILE_TEST_EXISTS)) return path; str_unref (path); return str_get (g_get_home_dir ()); }
void plugin_system_init(void) { assert (g_module_supported ()); audgui_init (& api_table, _AUD_PLUGIN_VERSION); plugin_registry_load (); const char * path = get_path (AUD_PATH_PLUGIN_DIR); for (int i = 0; i < ARRAY_LEN (plugin_dir_list); i ++) { char * dir = filename_build (path, plugin_dir_list[i]); scan_plugins (dir); str_unref (dir); } plugin_registry_prune (); }
bool_t dir_foreach (const char * path, DirForeachFunc func, void * user) { DIR * dir = opendir (path); if (! dir) return FALSE; struct dirent * entry; while ((entry = readdir (dir))) { if (entry->d_name[0] == '.') continue; char * full = filename_build (path, entry->d_name); bool_t stop = func (full, entry->d_name, user); str_unref (full); if (stop) break; } closedir (dir); return TRUE; }
static char * fileinfo_recursive_get_image (const char * path, const SearchParams * params, int depth) { DIR * d = opendir (path); if (! d) return NULL; struct dirent * entry; if (get_bool (NULL, "use_file_cover") && ! depth) { /* Look for images matching file name */ while ((entry = readdir (d))) { if (entry->d_name[0] == '.') continue; char * newpath = filename_build (path, entry->d_name); if (! g_file_test (newpath, G_FILE_TEST_IS_DIR) && has_front_cover_extension (entry->d_name) && is_file_image (entry->d_name, params->basename)) { closedir (d); return newpath; } str_unref (newpath); } rewinddir (d); } /* Search for files using filter */ while ((entry = readdir (d))) { if (entry->d_name[0] == '.') continue; char * newpath = filename_build (path, entry->d_name); if (! g_file_test (newpath, G_FILE_TEST_IS_DIR) && has_front_cover_extension (entry->d_name) && cover_name_filter (entry->d_name, params->include, TRUE) && ! cover_name_filter (entry->d_name, params->exclude, FALSE)) { closedir (d); return newpath; } str_unref (newpath); } rewinddir (d); if (get_bool (NULL, "recurse_for_cover") && depth < get_int (NULL, "recurse_for_cover_depth")) { /* Descend into directories recursively. */ while ((entry = readdir (d))) { if (entry->d_name[0] == '.') continue; char * newpath = filename_build (path, entry->d_name); if (g_file_test (newpath, G_FILE_TEST_IS_DIR)) { char * tmp = fileinfo_recursive_get_image (newpath, params, depth + 1); if (tmp) { str_unref (newpath); closedir (d); return tmp; } } str_unref (newpath); } } closedir (d); return NULL; }