From: Adam Tkac Date: Thu, 25 Nov 2010 15:07:35 +0000 (+0000) Subject: [Development] Implement gethomedir() function on Windows. X-Git-Tag: v1.0.90~110 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b8ec9e851ff81af3b2e0dc51cb11e090cab6f12e;p=tigervnc.git [Development] Implement gethomedir() function on Windows. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4208 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- 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 #endif -#ifndef WIN32 #include #include + +#ifndef WIN32 #include #include #include #include #include +#else +#include +#include /* MinGW needs it */ +#include +#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 - diff --git a/common/os/os.h b/common/os/os.h index fce21def..18e61e23 100644 --- a/common/os/os.h +++ b/common/os/os.h @@ -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