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,2008,2011 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 *****************************************************************************/
27 #include <sys/types.h>
35 static gchar
*pszPathToExecutable
= NULL
;
36 static gchar
*pszExecutable
= NULL
;
39 path_init(const char * argv0
)
41 /* FIXME: pszPathToExecutable calculation is ugly workaround
42 * that assumes that current directory is nevere changed for our process.
43 * We should better get full path (/proc/pid/maps in Linux ?) */
44 pszExecutable
= g_path_get_basename(argv0
);
45 pszPathToExecutable
= g_path_get_dirname(argv0
);
49 path_check_initialization()
51 if (pszPathToExecutable
== NULL
||
52 pszExecutable
== NULL
)
54 g_warning("path_init() not called.");
60 path_get_data_filename(const gchar
* filename
)
65 path_check_initialization();
67 /* check if it can be found in the source dir */
68 /* This allows a not installed binary to read right data files */
69 full_path
= g_strdup_printf("%s/../%s", pszPathToExecutable
, filename
);
70 if (stat(full_path
, &st
) == 0)
77 /* check in installation data dir */
78 full_path
= g_strdup_printf(DATA_DIR
"/%s", filename
);
79 if (stat(full_path
, &st
) == 0)
92 path_check_initialization();
94 g_free(pszExecutable
);
95 g_free(pszPathToExecutable
);