* They are now variables, all defined relative to one level above the
* directory that the executable is run from.
*/
-static void create_application_paths()
+static void create_application_paths(gchar *argv[])
{
- gchar buf[1024];
gchar *dirname;
gchar *tmp;
+ gchar **env;
- memset(buf, 0, sizeof(buf));
- if (readlink("/proc/self/exe", buf, sizeof(buf) - 1) < 0)
+ env = g_get_environ();
+
+ if (argv[0][0] == G_DIR_SEPARATOR)
+ {
+ gq_executable_path = g_strdup(argv[0]);
+ }
+ else
{
- /* There was an error. Perhaps the path does not exist
- * or the buffer is not big enough. */
- log_printf("Can't get path from /proc/self/exe");
- exit(1);
+ gq_executable_path = g_build_filename(g_environ_getenv(env, "PWD"), argv[0], NULL);
}
- gq_executable_path = g_strdup(buf);
- dirname = g_path_get_dirname(buf); // default is /usr/bin/
+ dirname = g_path_get_dirname(gq_executable_path); // default is /usr/bin/
gq_prefix = g_path_get_dirname(dirname);
gq_localedir = g_build_filename(gq_prefix, "share", "locale", NULL);
g_free(tmp);
g_free(dirname);
+ g_strfreev(env);
}
gint main(gint argc, gchar *argv[])
/* init execution time counter (debug only) */
init_exec_time();
- create_application_paths();
+ create_application_paths(argv);
/* setup locale, i18n */
setlocale(LC_ALL, "");
gint get_cpu_cores(void)
{
- FILE *cpuinfo = fopen("/proc/cpuinfo", "rb");
- char *arg = 0;
- size_t size = 0;
- int cores = 1;
- gchar *siblings_line;
- gchar *siblings_str;
-
- while(getline(&arg, &size, cpuinfo) != -1)
- {
- siblings_line = g_strrstr(arg, "siblings");
- if (siblings_line)
- {
- siblings_str = g_strrstr(siblings_line, ":");
- if (siblings_str)
- {
- cores = g_ascii_strtoll(siblings_str + 1, NULL, 0);
- }
- }
- }
- free(arg);
- fclose(cpuinfo);
-
- return cores;
+ return sysconf(_SC_NPROCESSORS_ONLN);
}
void tree_path_free_wrapper(void *data, void *useradata)