summaryrefslogtreecommitdiffstats
path: root/homedir.c
blob: f3ff0d481c2a1e1224ae1d5c64b5a940c15c9245 (plain)
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
#include "grv.h"

#ifdef __unix__
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#endif

void goto_grv_dir(void)
{
  /* On Unix, save stuff in a ~/.grv directory */
#ifdef __unix__
  {
    char *home = getenv("HOME");
    char *grvd = getenv("GRV_DIR");
    int rv;

    if ( !grvd ) {
      grvd = alloca(strlen(home)+6);
      if ( !grvd || !home )
	return;			/* Not much we can do here... */
      sprintf(grvd, "%s/.grv", home);
    }

    rv = chdir(grvd);		/* Change to .grv directory */
    if (rv && errno == ENOENT) {
      /* Try to create it */
      mkdir(grvd, 0777);
      chdir(grvd);
    }
  }
#endif
}