Add platform support for getting user home directory

This commit is contained in:
Jesse van den Kieboom 2015-12-22 09:56:05 +01:00
parent 5f60982686
commit a0d448304d
5 changed files with 66 additions and 0 deletions

View file

@ -26,6 +26,9 @@
#include <gdk/gdkquartz.h>
#include <gio/gunixinputstream.h>
#include <sys/types.h>
#include <pwd.h>
gboolean
gitg_platform_support_use_native_window_controls (GdkDisplay *display)
{
@ -190,4 +193,29 @@ gitg_platform_support_get_data_dir (void)
return g_strdup (GITG_DATADIR);
}
gchar *
gitg_platform_support_get_user_home_dir (const gchar *name)
{
struct passwd *pwd;
if (name == NULL)
{
name = g_get_user_name ();
}
if (name == NULL)
{
return NULL;
}
pwd = getpwnam (name);
if (pwd == NULL)
{
return NULL;
}
return g_strdup (pwd->pw_dir);
}
// ex:ts=4 noet

View file

@ -100,4 +100,11 @@ gitg_platform_support_get_data_dir (void)
return data_dir;
}
gchar *
gitg_platform_support_get_user_home_dir (const gchar *name)
{
// TODO
return NULL;
}
// ex:ts=4 noet

View file

@ -25,6 +25,9 @@
#include <gio/gunixinputstream.h>
#include <sys/types.h>
#include <pwd.h>
gboolean
gitg_platform_support_use_native_window_controls (GdkDisplay *display)
{
@ -117,4 +120,29 @@ gitg_platform_support_get_data_dir (void)
return g_strdup (GITG_DATADIR);
}
gchar *
gitg_platform_support_get_user_home_dir (const gchar *name)
{
struct passwd *pwd;
if (name == NULL)
{
name = g_get_user_name ();
}
if (name == NULL)
{
return NULL;
}
pwd = getpwnam (name);
if (pwd == NULL)
{
return NULL;
}
return g_strdup (pwd->pw_dir);
}
// ex:ts=4 noet

View file

@ -50,6 +50,8 @@ gchar *gitg_platform_support_get_locale_dir (void);
gchar *gitg_platform_support_get_data_dir (void);
gchar *gitg_platform_support_get_user_home_dir (const gchar *name);
#endif /* __GITG_PLATFORM_SUPPORT_H__ */
// ex:ts=4 noet

View file

@ -18,5 +18,6 @@ namespace Gitg
public static string get_lib_dir();
public static string get_locale_dir();
public static string get_data_dir();
public static string? get_user_home_dir(string? user = null);
}
}