integrate changes#2120,2168,2218 from maint-5.005;
[p5sagit/p5-mst-13.2.git] / win32 / win32.c
index 1ce7ad9..be5f5e1 100644 (file)
@@ -38,6 +38,8 @@
 #include "EXTERN.h"
 #include "perl.h"
 
+#include "patchlevel.h"
+
 #define NO_XSLOCKS
 #ifdef PERL_OBJECT
 extern CPerlObj* pPerl;
@@ -176,6 +178,7 @@ GetRegStr(const char *lpszValueName, char** ptr, DWORD* lpDataLen)
 static char *
 get_emd_part(char *prev_path, char *trailing_path, ...)
 {
+    char base[10];
     va_list ap;
     char mod_name[MAX_PATH+1];
     char *ptr;
@@ -186,6 +189,8 @@ get_emd_part(char *prev_path, char *trailing_path, ...)
     va_start(ap, trailing_path);
     strip = va_arg(ap, char *);
 
+    sprintf(base, "%5.3f", (double) 5 + ((double) PATCHLEVEL / (double) 1000));
+
     GetModuleFileName((w32_perldll_handle == INVALID_HANDLE_VALUE)
                      ? GetModuleHandle(NULL)
                      : w32_perldll_handle, mod_name, sizeof(mod_name));
@@ -209,17 +214,21 @@ get_emd_part(char *prev_path, char *trailing_path, ...)
     va_end(ap);
     strcpy(++ptr, trailing_path);
 
-    newsize = strlen(mod_name) + 1;
-    if (prev_path) {
-       oldsize = strlen(prev_path) + 1;
-       newsize += oldsize;                     /* includes plus 1 for ';' */
-       Renew(prev_path, newsize, char);
-       prev_path[oldsize-1] = ';';
-       strcpy(&prev_path[oldsize], mod_name);
-    }
-    else {
-       New(1311, prev_path, newsize, char);
-       strcpy(prev_path, mod_name);
+    /* only add directory if it exists */
+    if(GetFileAttributes(mod_name) != (DWORD) -1) {
+       /* directory exists */
+       newsize = strlen(mod_name) + 1;
+       if (prev_path) {
+           oldsize = strlen(prev_path) + 1;
+           newsize += oldsize;                 /* includes plus 1 for ';' */
+           Renew(prev_path, newsize, char);
+           prev_path[oldsize-1] = ';';
+           strcpy(&prev_path[oldsize], mod_name);
+       }
+       else {
+           New(1311, prev_path, newsize, char);
+           strcpy(prev_path, mod_name);
+       }
     }
 
     return prev_path;