1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
5 * Access to project specific data files.
8 * GNU GENERAL PUBLIC LICENSE version 2
10 *****************************************************************************/
12 #include <sys/types.h>
20 static gchar
*pszPathToExecutable
= NULL
;
21 static gchar
*pszExecutable
= NULL
;
24 path_init(const char * argv0
)
26 /* FIXME: pszPathToExecutable calculation is ugly workaround
27 * that assumes that current directory is nevere changed for our process.
28 * We should better get full path (/proc/pid/maps in Linux ?) */
29 pszExecutable
= g_path_get_basename(argv0
);
30 pszPathToExecutable
= g_path_get_dirname(argv0
);
34 path_check_initialization()
36 if (pszPathToExecutable
== NULL
||
37 pszExecutable
== NULL
)
39 g_warning("path_init() not called.");
45 path_get_data_filename(const gchar
* filename
)
50 path_check_initialization();
52 /* check if it can be found where executable resides */
53 /* This allows executing not installed binary to read right data files */
54 full_path
= g_strdup_printf("%s/%s", pszPathToExecutable
, filename
);
55 if (stat(full_path
, &st
) == 0)
62 /* check in installation data dir */
63 full_path
= g_strdup_printf(DATA_DIR
"/%s", filename
);
64 if (stat(full_path
, &st
) == 0)
77 path_check_initialization();
79 g_free(pszExecutable
);
80 g_free(pszPathToExecutable
);