[wing/wip/user-name] Add wing_get_user_name utility method



commit 9ee36abb0f32ab34292cb723965dfaabf451a614
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Jul 21 15:38:06 2016 +0200

    Add wing_get_user_name utility method

 wing/wingutils.c |   14 ++++++++++++++
 wing/wingutils.h |    3 +++
 2 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/wing/wingutils.c b/wing/wingutils.c
index c743386..98709a5 100644
--- a/wing/wingutils.c
+++ b/wing/wingutils.c
@@ -18,6 +18,7 @@
 #include "wingutils.h"
 
 #include <windows.h>
+#include <Lmcons.h>
 
 gboolean
 wing_is_wow_64 (void)
@@ -72,3 +73,16 @@ wing_get_version_number (gint *major,
 
   return TRUE;
 }
+
+gchar *
+wing_get_user_name (void)
+{
+  wchar_t user_namew[UNLEN + 1];
+  DWORD buf_size = UNLEN + 1;
+  gchar *user_name = NULL;
+
+  if (GetUserNameW(user_name, &buf_size)
+    user_name = g_utf16_to_utf8(user_namew, -1, NULL, NULL, NULL);
+
+  return user_name;
+}
diff --git a/wing/wingutils.h b/wing/wingutils.h
index 390ad20..bc0a44b 100644
--- a/wing/wingutils.h
+++ b/wing/wingutils.h
@@ -33,6 +33,9 @@ WING_AVAILABLE_IN_ALL
 gboolean     wing_get_version_number   (gint *major,
                                         gint *minor);
 
+WING_AVAILABLE_IN_ALL
+gchar       *wing_get_user_name        (void);
+
 G_END_DECLS
 
 #endif /* WING_UTILS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]