summaryrefslogtreecommitdiff
path: root/win32/perlhost.h
diff options
context:
space:
mode:
authorJan Dubois <jand@activestate.com>2006-12-18 13:37:25 -0800
committerSteve Peters <steve@fisharerojo.org>2006-12-20 04:14:06 +0000
commitd684b16258d4be88a6b78f17e48637c1127b0ed7 (patch)
tree56192373b41ee0fe650bdc7677208f0efb500d98 /win32/perlhost.h
parent35cf1ab6c6ff4f898ef39b9c22313127bcebffc4 (diff)
downloadperl-d684b16258d4be88a6b78f17e48637c1127b0ed7.tar.gz
Update cwd() to return the "short" pathname if the long one doesn't fit the codepage
Message-ID: <3rteo219or8hqr511e4vg1fnsgvgemb4sh@4ax.com> p4raw-id: //depot/perl@29598
Diffstat (limited to 'win32/perlhost.h')
-rw-r--r--win32/perlhost.h54
1 files changed, 45 insertions, 9 deletions
diff --git a/win32/perlhost.h b/win32/perlhost.h
index fe026dde1f..d6e1e0fe33 100644
--- a/win32/perlhost.h
+++ b/win32/perlhost.h
@@ -21,6 +21,10 @@
#include "vmem.h"
#include "vdir.h"
+#ifndef WC_NO_BEST_FIT_CHARS
+# define WC_NO_BEST_FIT_CHARS 0x00000400
+#endif
+
START_EXTERN_C
extern char * g_win32_get_privlib(const char *pl);
extern char * g_win32_get_sitelib(const char *pl);
@@ -2236,20 +2240,52 @@ CPerlHost::FreeLocalEnvironmentStrings(LPSTR lpStr)
Safefree(lpStr);
}
+static char *
+get_valid_filename(pTHX_ WCHAR *widename)
+{
+ char *name;
+ BOOL use_default = FALSE;
+ size_t widelen = wcslen(widename)+1;
+ int len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, widename, widelen,
+ NULL, 0, NULL, NULL);
+ Newx(name, len, char);
+ WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, widename, widelen,
+ name, len, NULL, &use_default);
+ if (use_default) {
+ WCHAR *shortname;
+ DWORD shortlen = GetShortPathNameW(widename, NULL, 0);
+ Newx(shortname, shortlen, WCHAR);
+ shortlen = GetShortPathNameW(widename, shortname, shortlen)+1;
+ len = WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, shortname, shortlen,
+ NULL, 0, NULL, NULL);
+ Renew(name, len, char);
+ WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, shortname, shortlen,
+ name, len, NULL, NULL);
+ Safefree(shortname);
+ }
+ return name;
+}
+
char*
CPerlHost::GetChildDir(void)
{
dTHX;
- int length;
char* ptr;
- Newx(ptr, MAX_PATH+1, char);
- if(ptr) {
- m_pvDir->GetCurrentDirectoryA(MAX_PATH+1, ptr);
- length = strlen(ptr);
- if (length > 3) {
- if ((ptr[length-1] == '\\') || (ptr[length-1] == '/'))
- ptr[length-1] = 0;
- }
+ size_t length;
+
+ if (IsWin95()) {
+ Newx(ptr, MAX_PATH+1, char);
+ m_pvDir->GetCurrentDirectoryA(MAX_PATH+1, ptr);
+ }
+ else {
+ WCHAR path[MAX_PATH+1];
+ m_pvDir->GetCurrentDirectoryW(MAX_PATH+1, path);
+ ptr = get_valid_filename(aTHX_ path);
+ }
+ length = strlen(ptr);
+ if (length > 3) {
+ if ((ptr[length-1] == '\\') || (ptr[length-1] == '/'))
+ ptr[length-1] = 0;
}
return ptr;
}