Revision: 4208
          http://tigervnc.svn.sourceforge.net/tigervnc/?rev=4208&view=rev
Author:   atkac
Date:     2010-11-25 15:07:35 +0000 (Thu, 25 Nov 2010)

Log Message:
-----------
[Development] Implement gethomedir() function on Windows.

Modified Paths:
--------------
    trunk/common/os/os.cxx
    trunk/common/os/os.h

Modified: trunk/common/os/os.cxx
===================================================================
--- trunk/common/os/os.cxx      2010-11-25 14:01:59 UTC (rev 4207)
+++ trunk/common/os/os.cxx      2010-11-25 15:07:35 UTC (rev 4208)
@@ -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 @@
 
        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
-

Modified: trunk/common/os/os.h
===================================================================
--- trunk/common/os/os.h        2010-11-25 14:01:59 UTC (rev 4207)
+++ trunk/common/os/os.h        2010-11-25 15:07:35 UTC (rev 4208)
@@ -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


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Tigervnc-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tigervnc-commits

Reply via email to