summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--homedir.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/homedir.c b/homedir.c
index 89766d6..f3ff0d4 100644
--- a/homedir.c
+++ b/homedir.c
@@ -13,17 +13,21 @@ void goto_grv_dir(void)
{
char *home = getenv("HOME");
char *grvd = getenv("GRV_DIR");
+ int rv;
if ( !grvd ) {
grvd = alloca(strlen(home)+6);
- if ( grvd ) {
- sprintf(grvd, "%s/.grv", home);
- mkdir(grvd, 0777); /* Make .grv directory if missing */
- }
+ if ( !grvd || !home )
+ return; /* Not much we can do here... */
+ sprintf(grvd, "%s/.grv", home);
}
- if ( grvd )
- chdir(grvd); /* Change to .grv directory */
+ rv = chdir(grvd); /* Change to .grv directory */
+ if (rv && errno == ENOENT) {
+ /* Try to create it */
+ mkdir(grvd, 0777);
+ chdir(grvd);
+ }
}
#endif
}