summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2013-10-30 03:40:24 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2013-10-30 03:40:24 (GMT)
commit8e4a8b2fda372c924e355360e9562948406ebc13 (patch)
treeedc46427a7d95bc8ac07f1b47f563ee03279741b
parentd5d63dd379bf1f6056390d2da3fbd469ebbb0bc2 (diff)
downloadgrv-8e4a8b2fda372c924e355360e9562948406ebc13.zip
grv-8e4a8b2fda372c924e355360e9562948406ebc13.tar.gz
grv-8e4a8b2fda372c924e355360e9562948406ebc13.tar.bz2
grv-8e4a8b2fda372c924e355360e9562948406ebc13.tar.xz
homedir: be saner about the error cases...HEADmaster
Try our best... Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-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
}