aboutsummaryrefslogtreecommitdiffstats
path: root/common/os/os.cxx
diff options
context:
space:
mode:
authorAdam Tkac <atkac@redhat.com>2010-11-25 15:07:35 +0000
committerAdam Tkac <atkac@redhat.com>2010-11-25 15:07:35 +0000
commitb8ec9e851ff81af3b2e0dc51cb11e090cab6f12e (patch)
treef1a6f6e637b8ab8580141c056c7d1ce8870e67b6 /common/os/os.cxx
parent5b1d8503b860151171544f1be20940a38eeb0c33 (diff)
downloadtigervnc-b8ec9e851ff81af3b2e0dc51cb11e090cab6f12e.tar.gz
tigervnc-b8ec9e851ff81af3b2e0dc51cb11e090cab6f12e.zip
[Development] Implement gethomedir() function on Windows.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4208 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'common/os/os.cxx')
-rw-r--r--common/os/os.cxx37
1 files changed, 29 insertions, 8 deletions
diff --git a/common/os/os.cxx b/common/os/os.cxx
index 5d410553..fb07dcf6 100644
--- a/common/os/os.cxx
+++ b/common/os/os.cxx
@@ -20,30 +20,37 @@
#include <config.h>
#endif
-#ifndef WIN32
#include <os/os.h>
#include <assert.h>
+
+#ifndef WIN32
#include <pwd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
+#else
+#include <windows.h>
+#include <wininet.h> /* MinGW needs it */
+#include <shlobj.h>
+#endif
int gethomedir(char **dirp)
{
+#ifndef WIN32
char *homedir, *dir;
size_t len;
uid_t uid;
struct passwd *passwd;
+#else
+ TCHAR *dir;
+ BOOL ret;
+#endif
assert(dirp != NULL && *dirp == NULL);
-#ifdef WIN32
- /* Not supported, yet */
- return -1;
-#endif
-
+#ifndef WIN32
homedir = getenv("HOME");
if (homedir == NULL) {
uid = getuid();
@@ -57,11 +64,25 @@ int gethomedir(char **dirp)
len = strlen(homedir) + 1;
dir = new char[len];
+ if (dir == NULL)
+ return -1;
+
memcpy(dir, homedir, len);
+#else
+ dir = new TCHAR[MAX_PATH];
+ if (dir == NULL)
+ return -1;
+
+ ret = SHGetSpecialFolderPath(NULL, dir, CSIDL_APPDATA, FALSE);
+ if (ret == FALSE) {
+ delete [] dir;
+ return -1;
+ }
+
+
+#endif
*dirp = dir;
return 0;
}
-#endif
-