File: gzillamisc.c

package info (click to toggle)
gzilla 0.1.5-4
  • links: PTS
  • area: main
  • in suites: slink
  • size: 972 kB
  • ctags: 1,396
  • sloc: ansic: 15,102; sh: 173; makefile: 117; perl: 18
file content (47 lines) | stat: -rw-r--r-- 1,248 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <gtk/gtk.h>

#include <stdio.h>
#include <stdlib.h>


/* returns the home directory of the user
 * DON'T try to free this one cause it's really a pointer
 * into the environment structure */
char *gzilla_misc_user_home(void)
{
    static char *home_dir;
    static int init = 1;
    
    if (init) {
	home_dir = getenv("HOME");
	init = 0;
    }
    
    return(home_dir);
}

/* pass in a string, and it will add the users home dir ie,
 * pass in .gzilla/bookmarks.html and it will return
 * /home/imain/.gzilla/bookmarks.html
 * 
 * Remember to g_free() returned value! */
char *gzilla_misc_prepend_user_home(char *file)
{
    char *home_return;
    home_return = g_malloc (strlen(file) + strlen(gzilla_misc_user_home()) + 3);
    
    sprintf(home_return, "%s/%s", gzilla_misc_user_home(), file);
    return(home_return);
}
/* very similar to above, but adds $HOME/.gzilla/ to beginning
 * This is meant to be the most useful version.
 * Perhaps this should be named gzilla_home_file ?
 */
char *gzilla_misc_file(char *file)
{
    char *home_return;
    home_return = g_malloc (strlen(file) + strlen(gzilla_misc_user_home()) + 16);
    
    sprintf(home_return, "%s/.gzilla/%s", gzilla_misc_user_home(), file);
    return(home_return);
}