int reset_property_cache() { int idx = 0; /* 0 the cache keys */ while (idx < MAX_PROPERTIES && cache[idx].key != NULL) { cache[idx].key[0] = 0; idx++; } return file_to_cache(); }
int property_set(char *name, char *value) { int idx = 0; if (!name || !value) return -EINVAL; if (cache[0].key == NULL && file_to_cache() < 0) return -errno; while (idx < MAX_PROPERTIES && cache[idx].key[0] != 0) { if ( !strncmp(cache[idx].key, name, PROPERTY_KEY_MAX) ) { strncpy(cache[idx].value, value, PROPERTY_VALUE_MAX); break; } } if (idx < MAX_PROPERTIES && cache[idx].key[0] != 0) { return cache_to_file(); } /* property not found */ return -1; }
int property_get(char *name, char *value, char *def) { int idx = 0; if (!name || !value) return -EINVAL; if (cache[0].key == NULL && file_to_cache() < 0) return -errno; while (idx < MAX_PROPERTIES && cache[idx].key[0] != 0) { /*printf("%s: Compare %s to cache[%d]=[key=\"%s\", value=\"%s\"]\n", __FUNCTION__, name, idx, cache[idx].key, cache[idx].value);*/ if ( !strncmp(cache[idx].key, name, PROPERTY_KEY_MAX) ) { strncpy(value, cache[idx].value, PROPERTY_VALUE_MAX); return strlen(value); } idx++; } if (def != NULL) { strncpy(value, def, PROPERTY_VALUE_MAX); return strlen(value); } return -1; }
static void foreach_file(const gchar *song_dir_path, const GRegex *cRegex, GlyrQuery *query, GList **retv_list) { if(song_dir_path != NULL) { GError *dir_error = NULL; GDir *song_dir = g_dir_open(song_dir_path, 0, &dir_error); if(song_dir != NULL) { const gchar *entry = NULL; while((entry = g_dir_read_name(song_dir)) != NULL) { if(regex_match_compiled(entry, cRegex) == TRUE) { gsize size = 0; gchar *absolute_path = g_strdup_printf("%s%c%s", song_dir_path, G_DIR_SEPARATOR, entry); if(absolute_path != NULL) { /* Read file */ gchar *file_path = g_filename_from_utf8(absolute_path, -1, NULL, NULL, NULL); gchar *retv = get_file_contents(file_path, &size); g_free(file_path); g_free(absolute_path); /* Add file to result list if not null */ file_to_cache(retv_list, query, retv, size); /* Not requested more? */ if(g_list_length(*retv_list) >= (gsize) query->number) { break; } } } } g_dir_close(song_dir); } else { glyr_message(-1, NULL, "Opening %s failed: %s\n", song_dir_path, dir_error->message); g_error_free(dir_error); } } }