From: Gurusamy Sarathy Date: Thu, 24 Apr 1997 17:13:30 +0000 (+1200) Subject: Win32 update (three patches) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b10511d03f06e2bc36e4d866861ec81d92d48fc;p=p5sagit%2Fp5-mst-13.2.git Win32 update (three patches) Signed-off-by: Gurusamy Sarathy --- diff --git a/win32/makedef.pl b/win32/makedef.pl index f080dcd..3a827d3 100644 --- a/win32/makedef.pl +++ b/win32/makedef.pl @@ -136,8 +136,10 @@ Perl_safexmalloc Perl_safexfree Perl_safexrealloc Perl_my_memcmp +Perl_my_memset Perl_cshlen Perl_cshname +boot_DynaLoader !END!OF!SKIP! # All symbols have a Perl_ prefix because that's what embed.h diff --git a/win32/perllib.c b/win32/perllib.c index 43d84c5..f40013b 100644 --- a/win32/perllib.c +++ b/win32/perllib.c @@ -52,46 +52,6 @@ RunPerl(int argc, char **argv, char **env, void *iosubsystem) return (exitstatus); } -/* Register any extra external extensions */ - -char *staticlinkmodules[] = { - "DynaLoader", - NULL, -}; - -EXTERN_C void boot_DynaLoader _((CV* cv)); - -static -XS(w32_GetCurrentDirectory) -{ - dXSARGS; - SV *sv = sv_newmortal(); - /* Make one call with zero size - return value is required size */ - DWORD len = GetCurrentDirectory((DWORD)0,NULL); - SvUPGRADE(sv,SVt_PV); - SvGROW(sv,len); - SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv)); - /* - * If result != 0 - * then it worked, set PV valid, - * else leave it 'undef' - */ - if (SvCUR(sv)) - SvPOK_on(sv); - EXTEND(sp,1); - ST(0) = sv; - XSRETURN(1); -} - -static void -xs_init() -{ - char *file = __FILE__; - dXSUB_SYS; - newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); - newXS("Win32::GetCurrentDirectory", w32_GetCurrentDirectory, file); -} - extern HANDLE PerlDllHandle; BOOL APIENTRY @@ -133,3 +93,66 @@ DllMain(HANDLE hModule, /* DLL module handle */ } return TRUE; } + +/* Register any extra external extensions */ + +char *staticlinkmodules[] = { + "DynaLoader", + NULL, +}; + +EXTERN_C void boot_DynaLoader _((CV* cv)); + +static +XS(w32_GetCurrentDirectory) +{ + dXSARGS; + SV *sv = sv_newmortal(); + /* Make one call with zero size - return value is required size */ + DWORD len = GetCurrentDirectory((DWORD)0,NULL); + SvUPGRADE(sv,SVt_PV); + SvGROW(sv,len); + SvCUR(sv) = GetCurrentDirectory((DWORD) SvLEN(sv), SvPVX(sv)); + /* + * If result != 0 + * then it worked, set PV valid, + * else leave it 'undef' + */ + if (SvCUR(sv)) + SvPOK_on(sv); + EXTEND(sp,1); + ST(0) = sv; + XSRETURN(1); +} + +static +XS(w32_GetLastError) +{ + dXSARGS; + XSRETURN_IV(GetLastError()); +} + +XS(w32_IsWinNT) +{ + dXSARGS; + XSRETURN_IV(IsWinNT()); +} + +XS(w32_IsWin95) +{ + dXSARGS; + XSRETURN_IV(IsWin95()); +} + +static void +xs_init() +{ + char *file = __FILE__; + dXSUB_SYS; + newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); + newXS("Win32::GetCurrentDirectory", w32_GetCurrentDirectory, file); + newXS("Win32::GetLastError", w32_GetLastError, file); + newXS("Win32::IsWinNT", w32_IsWinNT, file); + newXS("Win32::IsWin95", w32_IsWin95, file); +} + diff --git a/win32/win32.c b/win32/win32.c index 0759df8..e6dfb6b 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -31,24 +31,26 @@ #define CROAK croak #define WARN warn +static DWORD IdOS(void); + extern WIN32_IOSUBSYSTEM win32stdio; __declspec(thread) PWIN32_IOSUBSYSTEM pIOSubSystem = &win32stdio; /*__declspec(thread) PWIN32_IOSUBSYSTEM pIOSubSystem = NULL;*/ BOOL ProbeEnv = FALSE; -DWORD Win32System; +DWORD Win32System = (DWORD)-1; char szShellPath[MAX_PATH+1]; char szPerlLibRoot[MAX_PATH+1]; HANDLE PerlDllHandle = INVALID_HANDLE_VALUE; int IsWin95(void) { - return (Win32System == VER_PLATFORM_WIN32_WINDOWS); + return (IdOS() == VER_PLATFORM_WIN32_WINDOWS); } int IsWinNT(void) { - return (Win32System == VER_PLATFORM_WIN32_NT); + return (IdOS() == VER_PLATFORM_WIN32_NT); } void * @@ -298,16 +300,18 @@ my_pclose(PerlIO *fp) return win32_pclose(fp); } -static void +static DWORD IdOS(void) { - OSVERSIONINFO osver; + static OSVERSIONINFO osver; - memset(&osver, 0, sizeof(OSVERSIONINFO)); - osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osver); - Win32System = osver.dwPlatformId; - return; + if (osver.dwPlatformId != Win32System) { + memset(&osver, 0, sizeof(OSVERSIONINFO)); + osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); + GetVersionEx(&osver); + Win32System = osver.dwPlatformId; + } + return (Win32System); } static char * @@ -318,7 +322,7 @@ GetShell(void) static char* szWinNTDefaultShell = "cmd.exe"; if (!ProbeEnv) { - IdOS(), ProbeEnv = TRUE; + ProbeEnv = TRUE; if (IsWin95()) { strcpy(szShellPath, szWin95DefaultShell); }