]> source.dussan.org Git - tigervnc.git/commitdiff
[Development] Implement gethomedir() function on Windows.
authorAdam Tkac <atkac@redhat.com>
Thu, 25 Nov 2010 15:07:35 +0000 (15:07 +0000)
committerAdam Tkac <atkac@redhat.com>
Thu, 25 Nov 2010 15:07:35 +0000 (15:07 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4208 3789f03b-4d11-0410-bbf8-ca57d06f2519

common/os/os.cxx
common/os/os.h

index 5d41055349d0cb261f7625fb10f2a98d81637922..fb07dcf65ca0c9b2d68c30990ddd3d21e3e1de92 100644 (file)
 #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
-
index fce21def703f4f41eccc16910da8de240d0e44bb..18e61e23f92931a42b98d851769b2e0b1f966372 100644 (file)
@@ -27,6 +27,9 @@
  * Get home directory. If HOME environment variable is set then it is returned.
  * Otherwise home directory is obtained via getpwuid function.
  *
+ * Note for Windows:
+ * This functions returns array of TCHARs, not array of chars.
+ *
  * Returns:
  * 0 - Success
  * -1 - Failure