aboutsummaryrefslogtreecommitdiffstats
path: root/src/sysutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sysutils.c')
-rw-r--r--src/sysutils.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/sysutils.c b/src/sysutils.c
index 6bdd76f..112c8b5 100644
--- a/src/sysutils.c
+++ b/src/sysutils.c
@@ -343,7 +343,7 @@ _gpgrt_getcwd (void)
/* Get the standard home directory for user NAME. If NAME is NULL the
- * directory for the current user is retruned. Caller must release
+ * directory for the current user is returned. Caller must release
* the returned string. */
char *
_gpgrt_getpwdir (const char *name)
@@ -376,3 +376,23 @@ _gpgrt_getpwdir (const char *name)
#endif /*HAVE_PWD_H*/
return result;
}
+
+
+/* Return a malloced copy of the current user's account name; this may
+ * return NULL on memory failure. */
+char *
+_gpgrt_getusername (void)
+{
+ char *result = NULL;
+#if defined(HAVE_PWD_H) && defined(HAVE_GETPWUID)
+ struct passwd *pwd;
+
+ pwd = getpwuid (getuid());
+ if (pwd)
+ {
+ result = _gpgrt_strdup (pwd->pw_name);
+ }
+
+#endif /*HAVE_PWD_H*/
+ return result;
+}