1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Access to project specific data files.
6 * This file is part of gmidimonitor
8 * Copyright (C) 2005,2006,2007 Nedko Arnaudov <nedko@arnaudov.name>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2 of the License
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23 *****************************************************************************/
25 #include <sys/types.h>
33 static gchar
*pszPathToExecutable
= NULL
;
34 static gchar
*pszExecutable
= NULL
;
37 path_init(const char * argv0
)
39 /* FIXME: pszPathToExecutable calculation is ugly workaround
40 * that assumes that current directory is nevere changed for our process.
41 * We should better get full path (/proc/pid/maps in Linux ?) */
42 pszExecutable
= g_path_get_basename(argv0
);
43 pszPathToExecutable
= g_path_get_dirname(argv0
);
47 path_check_initialization()
49 if (pszPathToExecutable
== NULL
||
50 pszExecutable
== NULL
)
52 g_warning("path_init() not called.");
58 path_get_data_filename(const gchar
* filename
)
63 path_check_initialization();
65 /* check if it can be found where executable resides */
66 /* This allows executing not installed binary to read right data files */
67 full_path
= g_strdup_printf("%s/%s", pszPathToExecutable
, filename
);
68 if (stat(full_path
, &st
) == 0)
75 /* check in installation data dir */
76 full_path
= g_strdup_printf(DATA_DIR
"/%s", filename
);
77 if (stat(full_path
, &st
) == 0)
90 path_check_initialization();
92 g_free(pszExecutable
);
93 g_free(pszPathToExecutable
);