Minor fixes.
[mediadatabase.git] / gtk / path.c
blobb8b791b326ab499e91b423fcab133941d68eebc9
1 /* -*- Mode: C ; c-basic-offset: 3 -*- */
2 /*****************************************************************************
4 * $Id: path.c,v 1.1 2005/02/18 02:10:10 nedko Exp $
6 * DESCRIPTION:
7 * Access to project specific data files.
9 *****************************************************************************/
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <unistd.h>
14 #include <stdlib.h>
15 #include <gtk/gtk.h>
17 #include "common.h"
18 #include "path.h"
20 static gchar *pszPathToExecutable = NULL;
21 static gchar *pszExecutable = NULL;
23 void
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);
33 static void
34 path_check_initialization()
36 if (pszPathToExecutable == NULL ||
37 pszExecutable == NULL)
39 g_warning("path_init() not called.");
40 exit(1);
44 gchar *
45 path_get_data_filename(const gchar * filename)
47 gchar * full_path;
48 struct stat st;
50 path_check_initialization();
52 full_path = g_strdup_printf("%s/%s", pszPathToExecutable, filename);
53 if (stat(full_path, &st) == 0)
55 return full_path;
57 g_free(full_path);
59 return NULL;
62 void
63 path_uninit()
65 path_check_initialization();
67 g_free(pszExecutable);
68 g_free(pszPathToExecutable);
71 /*****************************************************************************
73 * Modifications log:
75 * !!! WARNING !!! Following lines are automatically updated by the CVS system.
77 * $Log: path.c,v $
78 * Revision 1.1 2005/02/18 02:10:10 nedko
79 * Access to project specific data files - initial revision.
81 *****************************************************************************/