Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7dc9466

Browse files
committed
Make UTF-8 get_home_path for winedit/write_history
1 parent9cdbb1b commit7dc9466

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

‎src/port/path.c

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,31 @@ get_man_path(const char *my_exec_path, char *ret_path)
762762
make_relative_path(ret_path,MANDIR,PGBINDIR,my_exec_path);
763763
}
764764

765+
#ifdefWIN32
766+
/*
767+
* make_wc_name
768+
*/
769+
770+
constwchar_t*make_wc_name(constchar*name) {
771+
intwlen;
772+
size_tsize=strlen(s)+1;
773+
size_twsize=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+
returnp;
777+
}
778+
779+
/*
780+
* make_utf8_path
781+
*/
782+
constchar*make_utf8_path(constwchar_t*s) {
783+
intlen;
784+
size_tsize=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+
returnp;
788+
}
789+
#endif
765790

766791
/*
767792
*get_home_path
@@ -783,19 +808,27 @@ get_home_path(char *ret_path)
783808
strlcpy(ret_path,pwd->pw_dir,MAXPGPATH);
784809
return true;
785810
#else
786-
char*tmppath;
787-
811+
wchar_t*tmppath;
812+
wchar_t*vname;
813+
constchar*utf8_path;
814+
788815
/*
789816
* Note: We use getenv() here because the more modern SHGetFolderPath()
790817
* would force the backend to link with shell32.lib, which eats valuable
791818
* desktop heap. XXX This function is used only in psql, which already
792819
* brings in shell32 via libpq. Moving this function to its own file
793820
* would keep it out of the backend, freeing it from this concern.
794821
*/
795-
tmppath=getenv("APPDATA");
822+
823+
vname=make_wc_name("APPDATA");
824+
tmppath=_wgetenv(vname);
825+
free(vname);
826+
796827
if (!tmppath)
797828
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);
799832
return true;
800833
#endif
801834
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp