> >OK ... are you supposed to find it out by looking at the environment > >vars, or is there another API defined? > > > >I am planning to consolidate the platform dependency into a function > >defined like > > > > static bool pqGetHomeDirectory(char *buf, int bufsize) > > { > > -- Obtain pathname of user's home directory, store in > > -- buf[] (of size bufsize) > > -- Return TRUE if succeeded, FALSE if not > > } > > > >If someone can whip up and test a WIN32 version of this, > I'll take care > >of the rest. > > > > > > I can't do the coding, but I took a quick look at msdn and I > think this is relevant: > > http://msdn.microsoft.com/library/default.asp?url=/library/en- > us/shellcc/platform/shell/reference/functions/shgetfolderpath.asp > > HRESULT SHGetFolderPath( > HWND /hwndOwner/, > int /nFolder/, > HANDLE /hToken/, > DWORD /dwFlags/, > LPTSTR /pszPath/ > ); > > > Also, for nFolder, it looks like the we want to use a value > of CSIDL_PROFILE (0x0028). > > Hope that helps someone out there.
No, we should use CSIDL_APPDATA. Two reasons: 1) Never put things in the root of the profile :P 2) CSIDL_APPDATA is supported on 9x (4.71 of the shell which,IIRC, is Win95, as long as you have IE4 or newer install. And I doubt a lot of people don't have that). Remember that our *client side code* support 9x. (Then of course it should have "postgresql" (or ".postgresql" for consiscency with *nix) appended to it) Also, SHGetFolderPath() rqeuires Win2k. There is SHGetSpecialFolderPath() for all versions. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc /platform/shell/reference/functions/shgetspecialfolderpath.asp Tom also wrote: > Now that I look at it, there are several places that are depending on > getenv("HOME") or getenv("USERPROFILE") (on Windows) as the meaning of "home directory". In particular ~/.pgpass is sought > there, and psql also uses get_home_path in a lot of places. > Seems like we should be consistent about this --- either we trust $HOME or we don't. Don't trust $HOME on win32. There is no such thing.It's set by Cygwin, and it's set by the MingW shell, but it's not set by Windows. HOMEDRIVE, HOMEPATH and HOMESHARE are set, but not HOME. You can trust USERPROFILE in NT based OSes. Not sure about 9x. Using the API above is a much nicer way of doing it. So, a quick implementation (not tested, but shouldn't be too hard) of your functino would be: static bool pqGetHomeDirectory(char *buf, int bufsize) { char tmppath[MAX_PATH+16]; /* Add 16 chars for "/.postgresql/" */ ZeroMemory(tmppath,sizeof(tmppath)); if (!SHGetSpecialFolderPath(NULL, tmppath, CSIDL_APPDATA, FALSE)) { return FALSE; strcat(tmppath,"/.postgresql/"); if (strlen(tmppath) > bufsize) return FALSE; /* Better than returning a chopped-off path */ strcpy(buf, tmppath); return TRUE; } You're going to have to add #include <shlobj.h> to the file as well. //Magnus ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org