/** Locate the application's localization folder. * * The path is generated by the following pseudo-code evaluation: * \code * prefix + "/share/locale" * \endcode * * @param default_locale_dir A default path which will used as fallback. * @return A string containing the localization folder's path, which must be freed when * no longer necessary. If BinReloc is not initialized, or if the * initialization function failed, then a copy of default_locale_dir will be returned. * If default_locale_dir is NULL, then NULL will be returned. */ gchar *gbr_find_locale_dir(const gchar * default_locale_dir) { gchar *data_dir, *dir; data_dir = gbr_find_data_dir(NULL); if (data_dir == NULL) { /* BinReloc not initialized. */ if (default_locale_dir != NULL) return g_strdup(default_locale_dir); else return NULL; } dir = g_build_filename(data_dir, "locale", NULL); g_free(data_dir); return dir; }
gboolean binreloc_init(gboolean try_hardcoded) { GError *error = NULL; gchar *tmp; DEBUG("initializing binreloc (hardcoded = %d)", try_hardcoded); /* If the runtime data directories we previously found, don't even try to find them again. */ if (params.path_data && params.path_lib) { DEBUG("data and lib path already found."); return TRUE; } if (try_hardcoded || !gbr_init(&error)) { /* We were asked to try hardcoded paths or BinReloc failed to initialize. */ params.path_data = g_strdup(PREFIX); params.path_lib = g_strdup(LIBPREFIX); if (error) { g_error_free(error); } DEBUG("%strying hardcoded paths.", try_hardcoded ? "" : "binreloc init failed. "); } else { /* If we were able to initialize BinReloc, build the default data and library paths. */ DEBUG("done, trying to use binreloc paths."); tmp = gbr_find_data_dir(PREFIX); params.path_data = g_build_filename(tmp, "hardinfo", NULL); g_free(tmp); tmp = gbr_find_lib_dir(PREFIX); params.path_lib = g_build_filename(tmp, "hardinfo", NULL); g_free(tmp); } DEBUG("searching for runtime data on these locations:"); DEBUG(" lib: %s", params.path_lib); DEBUG(" data: %s", params.path_data); /* Try to see if the uidefs.xml file isn't missing. This isn't the definitive test, but it should do okay for most situations. */ tmp = g_build_filename(params.path_data, "benchmark.data", NULL); if (!g_file_test(tmp, G_FILE_TEST_EXISTS)) { DEBUG("runtime data not found"); g_free(params.path_data); g_free(params.path_lib); g_free(tmp); params.path_data = params.path_lib = NULL; if (try_hardcoded) { /* We tried the hardcoded paths, but still was unable to find the runtime data. Give up. */ DEBUG("giving up"); return FALSE; } else { /* Even though BinReloc worked OK, the runtime data was not found. Try the hardcoded paths. */ DEBUG("trying to find elsewhere"); return binreloc_init(TRUE); } } g_free(tmp); DEBUG("runtime data found!"); /* We found the runtime data; hope everything is fine */ return TRUE; }