Sarathy's patch
[p5sagit/p5-mst-13.2.git] / win32 / win32.c
index 28454e8..dcdda53 100644 (file)
@@ -11,6 +11,9 @@
 #define WIN32_LEAN_AND_MEAN
 #define WIN32IO_IS_STDIO
 #include <tchar.h>
+#ifdef __GNUC__
+#define Win32_Winsock
+#endif
 #include <windows.h>
 
 /* #include "config.h" */
 #include "XSUB.h"
 #include <fcntl.h>
 #include <sys/stat.h>
+#ifndef __GNUC__
+/* assert.h conflicts with #define of assert in perl.h */
 #include <assert.h>
+#endif
 #include <string.h>
 #include <stdarg.h>
 #include <float.h>
 
+#ifdef __GNUC__
+/* Mingw32 defaults to globing command line 
+ * So we turn it off like this:
+ */
+int _CRT_glob = 0;
+#endif
+
 #define EXECF_EXEC 1
 #define EXECF_SPAWN 2
 #define EXECF_SPAWN_NOWAIT 3
@@ -55,30 +68,30 @@ IsWinNT(void) {
 }
 
 char *
-win32PerlLibPath(void)
+win32PerlLibPath(char *sfx,...)
 {
+    va_list ap;
     char *end;
+    va_start(ap,sfx);
     GetModuleFileName((PerlDllHandle == INVALID_HANDLE_VALUE) 
                      ? GetModuleHandle(NULL)
                      : PerlDllHandle,
                      szPerlLibRoot, 
                      sizeof(szPerlLibRoot));
-
     *(end = strrchr(szPerlLibRoot, '\\')) = '\0';
     if (stricmp(end-4,"\\bin") == 0)
      end -= 4;
     strcpy(end,"\\lib");
+    while (sfx)
+     {
+      strcat(end,"\\");
+      strcat(end,sfx);
+      sfx = va_arg(ap,char *);
+     }
+    va_end(ap); 
     return (szPerlLibRoot);
 }
 
-char *
-win32SiteLibPath(void)
-{
-    static char szPerlSiteLib[MAX_PATH+1];
-    strcpy(szPerlSiteLib, win32PerlLibPath());
-    strcat(szPerlSiteLib, "\\site");
-    return (szPerlSiteLib);
-}
 
 BOOL
 HasRedirection(char *ptr)
@@ -532,15 +545,15 @@ getegid(void)
 }
 
 int
-setuid(uid_t uid)
+setuid(uid_t auid)
 { 
-    return (uid == ROOT_UID ? 0 : -1);
+    return (auid == ROOT_UID ? 0 : -1);
 }
 
 int
-setgid(gid_t gid)
+setgid(gid_t agid)
 {
-    return (gid == ROOT_GID ? 0 : -1);
+    return (agid == ROOT_GID ? 0 : -1);
 }
 
 /*
@@ -923,7 +936,15 @@ win32_feof(FILE *fp)
  * we have to roll our own.
  */
 
+#ifdef USE_THREADS
+#ifdef USE_DECLSPEC_THREAD
 __declspec(thread) char        strerror_buffer[512];
+#else
+#define strerror_buffer (thr->i.Wstrerror_buffer)
+#endif
+#else
+char   strerror_buffer[512];
+#endif
 
 DllExport char *
 win32_strerror(int e) 
@@ -934,6 +955,7 @@ win32_strerror(int e)
     DWORD source = 0;
 
     if(e < 0 || e > sys_nerr) {
+        dTHR;
        if(e < 0)
            e = GetLastError();
 
@@ -1109,9 +1131,9 @@ win32_abort(void)
 }
 
 DllExport int
-win32_fstat(int fd,struct stat *bufptr)
+win32_fstat(int fd,struct stat *sbufptr)
 {
-    return fstat(fd,bufptr);
+    return fstat(fd,sbufptr);
 }
 
 DllExport int
@@ -1338,7 +1360,7 @@ sbrk(int need)
    if (committed && reserved && committed < reserved)
     {
      /* Commit last of previous chunk cannot span allocations */
-     addr = VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
+     addr = (char *) VirtualAlloc(committed,reserved-committed,MEM_COMMIT,PAGE_READWRITE);
      if (addr)
       committed = reserved;
     }
@@ -1347,7 +1369,7 @@ sbrk(int need)
     * so lets system choose where we start, subsequent calls pass
     * the old end address so ask for a contiguous block
     */
-   addr  = VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
+   addr  = (char *) VirtualAlloc(reserved,size,MEM_RESERVE,PAGE_NOACCESS);
    if (addr)
     {
      reserved = addr+size;
@@ -1368,7 +1390,7 @@ sbrk(int need)
  if (brk > committed)
   {
    DWORD size = ((brk-committed + pagesize -1)/pagesize) * pagesize;
-   char *addr = VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
+   char *addr = (char *) VirtualAlloc(committed,size,MEM_COMMIT,PAGE_READWRITE);
    if (addr)
     {
      committed += size;
@@ -1720,9 +1742,10 @@ Perl_win32_init(int *argcp, char ***argvp)
      * want to be at the vendor's whim on the default, we set
      * it explicitly here.
      */
-#if !defined(_ALPHA_)
+#if !defined(_ALPHA_) && !defined(__GNUC__)
     _control87(MCW_EM, MCW_EM);
 #endif
+    MALLOC_INIT; 
 }
 
 #ifdef USE_BINMODE_SCRIPTS
@@ -1754,3 +1777,6 @@ win32_strip_return(SV *sv)
 
 
 
+
+
+