updates.
[silc.git] / apps / irssi / src / core / misc.c
index 6bf871779a7a6b061f5d9d304db47cf9326c6972..93612d6bb5ab7704f786fa2dc51fd21e5ee4fbf7 100644 (file)
@@ -26,6 +26,7 @@
 #ifdef HAVE_REGEX_H
 #  include <regex.h>
 #endif
+#include <pwd.h>
 
 typedef struct {
        int condition;
@@ -448,11 +449,24 @@ int mkpath(const char *path, int mode)
        return 0;
 }
 
+/* Get home directory */
+const char *get_home_dir(void)
+{
+       struct passwd *pw = getpwuid(getuid());
+       if (!pw) {
+        if (g_getenv("HOME"))
+          return g_getenv("HOME");
+        else
+          return ".";
+       }
+       return pw->pw_dir;
+}
+
 /* convert ~/ to $HOME */
 char *convert_home(const char *path)
 {
        return *path == '~' && (*(path+1) == '/' || *(path+1) == '\0') ?
-               g_strconcat(g_get_home_dir(), path+1, NULL) :
+               g_strconcat((char *)get_home_dir, path+1, NULL) :
                g_strdup(path);
 }