@@ -762,6 +762,31 @@ get_man_path(const char *my_exec_path, char *ret_path)
762
762
make_relative_path (ret_path ,MANDIR ,PGBINDIR ,my_exec_path );
763
763
}
764
764
765
+ #ifdef WIN32
766
+ /*
767
+ * make_wc_name
768
+ */
769
+
770
+ const wchar_t * make_wc_name (const char * name ) {
771
+ int wlen ;
772
+ size_t size = strlen (s )+ 1 ;
773
+ size_t wsize = size * sizeof (wchar_t );
774
+ wchar_t * p = (wchar_t * )malloc (wsize );
775
+ wlen = MultiByteToWideChar (CP_ACP ,0 ,(LPCCH )name ,(int )size ,(LPWSTR )p ,(int )wsize );
776
+ return p ;
777
+ }
778
+
779
+ /*
780
+ * make_utf8_path
781
+ */
782
+ const char * make_utf8_path (const wchar_t * s ) {
783
+ int len ;
784
+ size_t size = wcslen (s )+ 1 ;
785
+ char * p = (char * )malloc (size * sizeof (wchar_t ));
786
+ len = WideCharToMultiByte (CP_UTF8 ,0 ,s ,size ,p ,size * sizeof (wchar_t ),NULL ,NULL );
787
+ return p ;
788
+ }
789
+ #endif
765
790
766
791
/*
767
792
*get_home_path
@@ -783,19 +808,27 @@ get_home_path(char *ret_path)
783
808
strlcpy (ret_path ,pwd -> pw_dir ,MAXPGPATH );
784
809
return true;
785
810
#else
786
- char * tmppath ;
787
-
811
+ wchar_t * tmppath ;
812
+ wchar_t * vname ;
813
+ const char * utf8_path ;
814
+
788
815
/*
789
816
* Note: We use getenv() here because the more modern SHGetFolderPath()
790
817
* would force the backend to link with shell32.lib, which eats valuable
791
818
* desktop heap. XXX This function is used only in psql, which already
792
819
* brings in shell32 via libpq. Moving this function to its own file
793
820
* would keep it out of the backend, freeing it from this concern.
794
821
*/
795
- tmppath = getenv ("APPDATA" );
822
+
823
+ vname = make_wc_name ("APPDATA" );
824
+ tmppath = _wgetenv (vname );
825
+ free (vname );
826
+
796
827
if (!tmppath )
797
828
return false;
798
- snprintf (ret_path ,MAXPGPATH ,"%s\\postgresql" ,tmppath );
829
+ utf8_path = make_utf8_path (tmppath );
830
+ snprintf (ret_path ,MAXPGPATH ,"%s\\postgresql" ,utf8_path );
831
+ free (utf8_path );
799
832
return true;
800
833
#endif
801
834
}