This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
new perldelta
[perl5.git] / win32 / perlhost.h
index b1c6c80..9a2e24c 100644 (file)
@@ -7,16 +7,13 @@
  *    License or the Artistic License, as specified in the README file.
  */
 
-#ifndef UNDER_CE
 #define CHECK_HOST_INTERP
-#endif
 
 #ifndef ___PerlHost_H___
 #define ___PerlHost_H___
 
-#ifndef UNDER_CE
 #include <signal.h>
-#endif
+#include <wchar.h>
 #include "iperlsys.h"
 #include "vmem.h"
 #include "vdir.h"
@@ -26,9 +23,6 @@
 #endif
 
 START_EXTERN_C
-extern char *  g_win32_get_privlib(const char *pl, STRLEN *const len);
-extern char *  g_win32_get_sitelib(const char *pl, STRLEN *const len);
-extern char *  g_win32_get_vendorlib(const char *pl, STRLEN *const len);
 extern char *  g_getlogin(void);
 END_EXTERN_C
 
@@ -38,10 +32,10 @@ public:
     /* Constructors */
     CPerlHost(void);
     CPerlHost(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared,
-                struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
-                struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
-                struct IPerlDir** ppDir, struct IPerlSock** ppSock,
-                struct IPerlProc** ppProc);
+                 struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
+                 struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
+                 struct IPerlDir** ppDir, struct IPerlSock** ppSock,
+                 struct IPerlProc** ppProc);
     CPerlHost(CPerlHost& host);
     ~CPerlHost(void);
 
@@ -67,11 +61,11 @@ public:
     inline void Free(void* ptr) { m_pVMem->Free(ptr); };
     inline void* Calloc(size_t num, size_t size)
     {
-       size_t count = num*size;
-       void* lpVoid = Malloc(count);
-       if (lpVoid)
-           ZeroMemory(lpVoid, count);
-       return lpVoid;
+        size_t count = num*size;
+        void* lpVoid = Malloc(count);
+        if (lpVoid)
+            ZeroMemory(lpVoid, count);
+        return lpVoid;
     };
     inline void GetLock(void) { m_pVMem->GetLock(); };
     inline void FreeLock(void) { m_pVMem->FreeLock(); };
@@ -84,37 +78,37 @@ public:
     inline int IsLockedShared(void) { return m_pVMemShared->IsLocked(); };
     inline void* MallocShared(size_t size)
     {
-       void *result;
-       GetLockShared();
-       result = m_pVMemShared->Malloc(size);
-       FreeLockShared();
-       return result;
+        void *result;
+        GetLockShared();
+        result = m_pVMemShared->Malloc(size);
+        FreeLockShared();
+        return result;
     };
     inline void* ReallocShared(void* ptr, size_t size)
     {
-       void *result;
-       GetLockShared();
-       result = m_pVMemShared->Realloc(ptr, size);
-       FreeLockShared();
-       return result;
+        void *result;
+        GetLockShared();
+        result = m_pVMemShared->Realloc(ptr, size);
+        FreeLockShared();
+        return result;
     };
     inline void FreeShared(void* ptr)
     {
-       GetLockShared();
-       m_pVMemShared->Free(ptr);
-       FreeLockShared();
+        GetLockShared();
+        m_pVMemShared->Free(ptr);
+        FreeLockShared();
     };
     inline void* CallocShared(size_t num, size_t size)
     {
-       size_t count = num*size;
-       void* lpVoid = MallocShared(count);
-       if (lpVoid)
-           ZeroMemory(lpVoid, count);
-       return lpVoid;
+        size_t count = num*size;
+        void* lpVoid = MallocShared(count);
+        if (lpVoid)
+            ZeroMemory(lpVoid, count);
+        return lpVoid;
     };
 
 /* IPerlMemParse */
-    /* Assume something else is using locks to mangaging serialize
+    /* Assume something else is using locks to manage serialization
        on a batch basis
      */
     inline void GetLockParse(void) { m_pVMemParse->GetLock(); };
@@ -125,11 +119,11 @@ public:
     inline void FreeParse(void* ptr) { m_pVMemParse->Free(ptr); };
     inline void* CallocParse(size_t num, size_t size)
     {
-       size_t count = num*size;
-       void* lpVoid = MallocParse(count);
-       if (lpVoid)
-           ZeroMemory(lpVoid, count);
-       return lpVoid;
+        size_t count = num*size;
+        void* lpVoid = MallocParse(count);
+        if (lpVoid)
+            ZeroMemory(lpVoid, count);
+        return lpVoid;
     };
 
 /* IPerlEnv */
@@ -137,11 +131,11 @@ public:
     int Putenv(const char *envstring);
     inline char *Getenv(const char *varname, unsigned long *len)
     {
-       *len = 0;
-       char *e = Getenv(varname);
-       if (e)
-           *len = strlen(e);
-       return e;
+        *len = 0;
+        char *e = Getenv(varname);
+        if (e)
+            *len = strlen(e);
+        return e;
     }
     void* CreateChildEnv(void) { return CreateLocalEnvironmentStrings(*m_pvDir); };
     void FreeChildEnv(void* pStr) { FreeLocalEnvironmentStrings((char*)pStr); };
@@ -152,12 +146,12 @@ public:
 
     inline LPSTR GetIndex(DWORD &dwIndex)
     {
-       if(dwIndex < m_dwEnvCount)
-       {
-           ++dwIndex;
-           return m_lppEnvList[dwIndex-1];
-       }
-       return NULL;
+        if(dwIndex < m_dwEnvCount)
+        {
+            ++dwIndex;
+            return m_lppEnvList[dwIndex-1];
+        }
+        return NULL;
     };
 
 protected:
@@ -332,7 +326,7 @@ PerlMemIsLocked(struct IPerlMem* piPerl)
     return IPERL2HOST(piPerl)->IsLocked();
 }
 
-struct IPerlMem perlMem =
+const struct IPerlMem perlMem =
 {
     PerlMemMalloc,
     PerlMemRealloc,
@@ -386,7 +380,7 @@ PerlMemSharedIsLocked(struct IPerlMem* piPerl)
     return IPERL2HOST(piPerl)->IsLockedShared();
 }
 
-struct IPerlMem perlMemShared =
+const struct IPerlMem perlMemShared =
 {
     PerlMemSharedMalloc,
     PerlMemSharedRealloc,
@@ -440,7 +434,7 @@ PerlMemParseIsLocked(struct IPerlMem* piPerl)
     return IPERL2HOST(piPerl)->IsLockedParse();
 }
 
-struct IPerlMem perlMemParse =
+const struct IPerlMem perlMemParse =
 {
     PerlMemParseMalloc,
     PerlMemParseRealloc,
@@ -517,22 +511,22 @@ PerlEnvOsId(struct IPerlEnv* piPerl)
 }
 
 char*
-PerlEnvLibPath(struct IPerlEnv* piPerl, const char *pl, STRLEN *const len)
+PerlEnvLibPath(struct IPerlEnv* piPerl, WIN32_NO_REGISTRY_M_(const char *pl) STRLEN *const len)
 {
-    return g_win32_get_privlib(pl, len);
+    return win32_get_privlib(WIN32_NO_REGISTRY_M_(pl) len);
 }
 
 char*
 PerlEnvSiteLibPath(struct IPerlEnv* piPerl, const char *pl, STRLEN *const len)
 {
-    return g_win32_get_sitelib(pl, len);
+    return win32_get_sitelib(pl, len);
 }
 
 char*
 PerlEnvVendorLibPath(struct IPerlEnv* piPerl, const char *pl,
-                    STRLEN *const len)
+                     STRLEN *const len)
 {
-    return g_win32_get_vendorlib(pl, len);
+    return win32_get_vendorlib(pl, len);
 }
 
 void
@@ -541,7 +535,7 @@ PerlEnvGetChildIO(struct IPerlEnv* piPerl, child_IO_table* ptr)
     win32_get_child_IO(ptr);
 }
 
-struct IPerlEnv perlEnv =
+const struct IPerlEnv perlEnv =
 {
     PerlEnvGetenv,
     PerlEnvPutenv,
@@ -832,25 +826,24 @@ PerlStdIOGetOSfhandle(struct IPerlStdIO* piPerl, int filenum)
 FILE*
 PerlStdIOFdupopen(struct IPerlStdIO* piPerl, FILE* pf)
 {
-#ifndef UNDER_CE
     FILE* pfdup;
     fpos_t pos;
     char mode[3];
     int fileno = win32_dup(win32_fileno(pf));
 
     /* open the file in the same mode */
-    if((pf)->_flag & _IOREAD) {
-       mode[0] = 'r';
-       mode[1] = 0;
+    if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RD) {
+        mode[0] = 'r';
+        mode[1] = 0;
     }
-    else if((pf)->_flag & _IOWRT) {
-       mode[0] = 'a';
-       mode[1] = 0;
+    else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_WR) {
+        mode[0] = 'a';
+        mode[1] = 0;
     }
-    else if((pf)->_flag & _IORW) {
-       mode[0] = 'r';
-       mode[1] = '+';
-       mode[2] = 0;
+    else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RW) {
+        mode[0] = 'r';
+        mode[1] = '+';
+        mode[2] = 0;
     }
 
     /* it appears that the binmode is attached to the
@@ -861,15 +854,12 @@ PerlStdIOFdupopen(struct IPerlStdIO* piPerl, FILE* pf)
 
     /* move the file pointer to the same position */
     if (!fgetpos(pf, &pos)) {
-       fsetpos(pfdup, &pos);
+        fsetpos(pfdup, &pos);
     }
     return pfdup;
-#else
-    return 0;
-#endif
 }
 
-struct IPerlStdIO perlStdIO =
+const struct IPerlStdIO perlStdIO =
 {
     PerlStdIOStdin,
     PerlStdIOStdout,
@@ -996,6 +986,18 @@ PerlLIOLink(struct IPerlLIO* piPerl, const char*oldname, const char *newname)
     return win32_link(oldname, newname);
 }
 
+int
+PerlLIOSymLink(struct IPerlLIO* piPerl, const char*oldname, const char *newname)
+{
+    return win32_symlink(oldname, newname);
+}
+
+int
+PerlLIOReadLink(struct IPerlLIO* piPerl, const char *path, char *buf, size_t bufsiz)
+{
+    return win32_readlink(path, buf, bufsiz);
+}
+
 Off_t
 PerlLIOLseek(struct IPerlLIO* piPerl, int handle, Off_t offset, int origin)
 {
@@ -1005,7 +1007,7 @@ PerlLIOLseek(struct IPerlLIO* piPerl, int handle, Off_t offset, int origin)
 int
 PerlLIOLstat(struct IPerlLIO* piPerl, const char *path, Stat_t *buffer)
 {
-    return win32_stat(path, buffer);
+    return win32_lstat(path, buffer);
 }
 
 char*
@@ -1080,7 +1082,7 @@ PerlLIOWrite(struct IPerlLIO* piPerl, int handle, const void *buffer, unsigned i
     return win32_write(handle, buffer, count);
 }
 
-struct IPerlLIO perlLIO =
+const struct IPerlLIO perlLIO =
 {
     PerlLIOAccess,
     PerlLIOChmod,
@@ -1108,6 +1110,8 @@ struct IPerlLIO perlLIO =
     PerlLIOUnlink,
     PerlLIOUtime,
     PerlLIOWrite,
+    PerlLIOSymLink,
+    PerlLIOReadLink
 };
 
 
@@ -1181,7 +1185,7 @@ PerlDirMapPathW(struct IPerlDir* piPerl, const WCHAR* path)
     return IPERL2HOST(piPerl)->MapPathW(path);
 }
 
-struct IPerlDir perlDir =
+const struct IPerlDir perlDir =
 {
     PerlDirMakedir,
     PerlDirChdir,
@@ -1467,7 +1471,7 @@ PerlSockIoctlsocket(struct IPerlSock* piPerl, SOCKET s, long cmd, u_long *argp)
     return win32_ioctlsocket(s, cmd, argp);
 }
 
-struct IPerlSock perlSock =
+const struct IPerlSock perlSock =
 {
     PerlSockHtonl,
     PerlSockHtons,
@@ -1608,7 +1612,7 @@ PerlProcKillpg(struct IPerlProc* piPerl, int pid, int sig)
 int
 PerlProcPauseProc(struct IPerlProc* piPerl)
 {
-    return win32_sleep((32767L << 16) + 32767);
+    return win32_pause();
 }
 
 PerlIO*
@@ -1688,6 +1692,7 @@ PerlProcGetTimeOfDay(struct IPerlProc* piPerl, struct timeval *t, void *z)
 }
 
 #ifdef USE_ITHREADS
+PERL_STACK_REALIGN
 static THREAD_RET_TYPE
 win32_start_child(LPVOID arg)
 {
@@ -1720,24 +1725,24 @@ win32_start_child(LPVOID arg)
 
     /* push a zero on the stack (we are the child) */
     {
-       dSP;
-       dTARGET;
-       PUSHi(0);
-       PUTBACK;
+        dSP;
+        dTARGET;
+        PUSHi(0);
+        PUTBACK;
     }
 
     /* continue from next op */
     PL_op = PL_op->op_next;
 
     {
-       dJMPENV;
-       volatile int oldscope = 1; /* We are responsible for all scopes */
+        dJMPENV;
+        volatile int oldscope = 1; /* We are responsible for all scopes */
 
 restart:
-       JMPENV_PUSH(status);
-       switch (status) {
-       case 0:
-           CALLRUNOPS(aTHX);
+        JMPENV_PUSH(status);
+        switch (status) {
+        case 0:
+            CALLRUNOPS(aTHX);
             /* We may have additional unclosed scopes if fork() was called
              * from within a BEGIN block.  See perlfork.pod for more details.
              * We cannot clean up these other scopes because they belong to a
@@ -1748,48 +1753,48 @@ restart:
                 PL_scopestack[oldscope-1] = PL_scopestack[PL_scopestack_ix-1];
                 PL_scopestack_ix = oldscope;
             }
-           status = 0;
-           break;
-       case 2:
-           while (PL_scopestack_ix > oldscope)
-               LEAVE;
-           FREETMPS;
-           PL_curstash = PL_defstash;
-           if (PL_curstash != PL_defstash) {
-               SvREFCNT_dec(PL_curstash);
-               PL_curstash = (HV *)SvREFCNT_inc(PL_defstash);
-           }
-           if (PL_endav && !PL_minus_c) {
-               PERL_SET_PHASE(PERL_PHASE_END);
-               call_list(oldscope, PL_endav);
-           }
-           status = STATUS_EXIT;
-           break;
-       case 3:
-           if (PL_restartop) {
-               POPSTACK_TO(PL_mainstack);
-               PL_op = PL_restartop;
-               PL_restartop = (OP*)NULL;
-               goto restart;
-           }
-           PerlIO_printf(Perl_error_log, "panic: restartop\n");
-           FREETMPS;
-           status = 1;
-           break;
-       }
-       JMPENV_POP;
-
-       /* XXX hack to avoid perl_destruct() freeing optree */
+            status = 0;
+            break;
+        case 2:
+            while (PL_scopestack_ix > oldscope)
+                LEAVE;
+            FREETMPS;
+            PL_curstash = PL_defstash;
+            if (PL_curstash != PL_defstash) {
+                SvREFCNT_dec(PL_curstash);
+                PL_curstash = (HV *)SvREFCNT_inc(PL_defstash);
+            }
+            if (PL_endav && !PL_minus_c) {
+                PERL_SET_PHASE(PERL_PHASE_END);
+                call_list(oldscope, PL_endav);
+            }
+            status = STATUS_EXIT;
+            break;
+        case 3:
+            if (PL_restartop) {
+                POPSTACK_TO(PL_mainstack);
+                PL_op = PL_restartop;
+                PL_restartop = (OP*)NULL;
+                goto restart;
+            }
+            PerlIO_printf(Perl_error_log, "panic: restartop\n");
+            FREETMPS;
+            status = 1;
+            break;
+        }
+        JMPENV_POP;
+
+        /* XXX hack to avoid perl_destruct() freeing optree */
         win32_checkTLS(my_perl);
-       PL_main_root = (OP*)NULL;
+        PL_main_root = (OP*)NULL;
     }
 
     win32_checkTLS(my_perl);
     /* close the std handles to avoid fd leaks */
     {
-       do_close(PL_stdingv, FALSE);
-       do_close(gv_fetchpv("STDOUT", TRUE, SVt_PVIO), FALSE); /* PL_stdoutgv - ISAGN */
-       do_close(PL_stderrgv, FALSE);
+        do_close(PL_stdingv, FALSE);
+        do_close(gv_fetchpv("STDOUT", TRUE, SVt_PVIO), FALSE); /* PL_stdoutgv - ISAGN */
+        do_close(PL_stderrgv, FALSE);
     }
 
     /* destroy everything (waits for any pseudo-forked children) */
@@ -1816,22 +1821,22 @@ PerlProcFork(struct IPerlProc* piPerl)
     CPerlHost *h;
 
     if (w32_num_pseudo_children >= MAXIMUM_WAIT_OBJECTS) {
-       errno = EAGAIN;
-       return -1;
+        errno = EAGAIN;
+        return -1;
     }
     h = new CPerlHost(*(CPerlHost*)w32_internal_host);
     PerlInterpreter *new_perl = perl_clone_using((PerlInterpreter*)aTHX,
-                                                CLONEf_COPY_STACKS,
-                                                h->m_pHostperlMem,
-                                                h->m_pHostperlMemShared,
-                                                h->m_pHostperlMemParse,
-                                                h->m_pHostperlEnv,
-                                                h->m_pHostperlStdIO,
-                                                h->m_pHostperlLIO,
-                                                h->m_pHostperlDir,
-                                                h->m_pHostperlSock,
-                                                h->m_pHostperlProc
-                                                );
+                                                 CLONEf_COPY_STACKS,
+                                                 h->m_pHostperlMem,
+                                                 h->m_pHostperlMemShared,
+                                                 h->m_pHostperlMemParse,
+                                                 h->m_pHostperlEnv,
+                                                 h->m_pHostperlStdIO,
+                                                 h->m_pHostperlLIO,
+                                                 h->m_pHostperlDir,
+                                                 h->m_pHostperlSock,
+                                                 h->m_pHostperlProc
+                                                 );
     new_perl->Isys_intern.internal_host = h;
     h->host_perl = new_perl;
 #  ifdef PERL_SYNC_FORK
@@ -1845,15 +1850,15 @@ PerlProcFork(struct IPerlProc* piPerl)
         (w32_message_hwnd == NULL) ? (HWND)NULL : (HWND)INVALID_HANDLE_VALUE;
 #    ifdef USE_RTL_THREAD_API
     handle = (HANDLE)_beginthreadex((void*)NULL, 0, win32_start_child,
-                                   (void*)new_perl, 0, (unsigned*)&id);
+                                    (void*)new_perl, 0, (unsigned*)&id);
 #    else
     handle = CreateThread(NULL, 0, win32_start_child,
-                         (LPVOID)new_perl, 0, &id);
+                          (LPVOID)new_perl, 0, &id);
 #    endif
     PERL_SET_THX(aTHX);        /* XXX perl_clone*() set TLS */
     if (!handle) {
-       errno = EAGAIN;
-       return -1;
+        errno = EAGAIN;
+        return -1;
     }
     w32_pseudo_child_handles[w32_num_pseudo_children] = handle;
     w32_pseudo_child_pids[w32_num_pseudo_children] = id;
@@ -1901,7 +1906,7 @@ PerlProcLastHost(struct IPerlProc* piPerl)
  return h->LastHost();
 }
 
-struct IPerlProc perlProc =
+const struct IPerlProc perlProc =
 {
     PerlProcAbort,
     PerlProcCrypt,
@@ -1981,20 +1986,20 @@ CPerlHost::CPerlHost(void)
 
 #define SETUPEXCHANGE(xptr, iptr, table) \
     STMT_START {                               \
-       if (xptr) {                             \
-           iptr = *xptr;                       \
-           *xptr = &table;                     \
-                                             \
-       else {                                  \
-           iptr = &table;                      \
-                                             \
+        if (xptr) {                            \
+            iptr = *xptr;                      \
+            *xptr = &table;                    \
+        }                                      \
+        else {                                 \
+            iptr = &table;                     \
+        }                                      \
     } STMT_END
 
 CPerlHost::CPerlHost(struct IPerlMem** ppMem, struct IPerlMem** ppMemShared,
-                struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
-                struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
-                struct IPerlDir** ppDir, struct IPerlSock** ppSock,
-                struct IPerlProc** ppProc)
+                 struct IPerlMem** ppMemParse, struct IPerlEnv** ppEnv,
+                 struct IPerlStdIO** ppStdIO, struct IPerlLIO** ppLIO,
+                 struct IPerlDir** ppDir, struct IPerlSock** ppSock,
+                 struct IPerlProc** ppProc)
 {
     InterlockedIncrement(&num_hosts);
     m_pvDir = new VDir(0);
@@ -2069,7 +2074,7 @@ CPerlHost::CPerlHost(CPerlHost& host)
     LPSTR lpPtr;
     DWORD dwIndex = 0;
     while(lpPtr = host.GetIndex(dwIndex))
-       Add(lpPtr);
+        Add(lpPtr);
 }
 
 CPerlHost::~CPerlHost(void)
@@ -2088,13 +2093,13 @@ CPerlHost::Find(LPCSTR lpStr)
     LPSTR lpPtr;
     LPSTR* lppPtr = Lookup(lpStr);
     if(lppPtr != NULL) {
-       for(lpPtr = *lppPtr; *lpPtr != '\0' && *lpPtr != '='; ++lpPtr)
-           ;
+        for(lpPtr = *lppPtr; *lpPtr != '\0' && *lpPtr != '='; ++lpPtr)
+            ;
 
-       if(*lpPtr == '=')
-           ++lpPtr;
+        if(*lpPtr == '=')
+            ++lpPtr;
 
-       return lpPtr;
+        return lpPtr;
     }
     return NULL;
 }
@@ -2108,26 +2113,26 @@ lookup(const void *arg1, const void *arg2)
     ptr1 = *(char**)arg1;
     ptr2 = *(char**)arg2;
     for(;;) {
-       c1 = *ptr1++;
-       c2 = *ptr2++;
-       if(c1 == '\0' || c1 == '=') {
-           if(c2 == '\0' || c2 == '=')
-               break;
-
-           return -1; // string 1 < string 2
-       }
-       else if(c2 == '\0' || c2 == '=')
-           return 1; // string 1 > string 2
-       else if(c1 != c2) {
-           c1 = toupper(c1);
-           c2 = toupper(c2);
-           if(c1 != c2) {
-               if(c1 < c2)
-                   return -1; // string 1 < string 2
-
-               return 1; // string 1 > string 2
-           }
-       }
+        c1 = *ptr1++;
+        c2 = *ptr2++;
+        if(c1 == '\0' || c1 == '=') {
+            if(c2 == '\0' || c2 == '=')
+                break;
+
+            return -1; // string 1 < string 2
+        }
+        else if(c2 == '\0' || c2 == '=')
+            return 1; // string 1 > string 2
+        else if(c1 != c2) {
+            c1 = toupper(c1);
+            c2 = toupper(c2);
+            if(c1 != c2) {
+                if(c1 < c2)
+                    return -1; // string 1 < string 2
+
+                return 1; // string 1 > string 2
+            }
+        }
     }
     return 0;
 }
@@ -2135,12 +2140,8 @@ lookup(const void *arg1, const void *arg2)
 LPSTR*
 CPerlHost::Lookup(LPCSTR lpStr)
 {
-#ifdef UNDER_CE
-    if (!m_lppEnvList || !m_dwEnvCount)
-       return NULL;
-#endif
     if (!lpStr)
-       return NULL;
+        return NULL;
     return (LPSTR*)bsearch(&lpStr, m_lppEnvList, m_dwEnvCount, sizeof(LPSTR), lookup);
 }
 
@@ -2153,26 +2154,26 @@ compare(const void *arg1, const void *arg2)
     ptr1 = *(char**)arg1;
     ptr2 = *(char**)arg2;
     for(;;) {
-       c1 = *ptr1++;
-       c2 = *ptr2++;
-       if(c1 == '\0' || c1 == '=') {
-           if(c1 == c2)
-               break;
-
-           return -1; // string 1 < string 2
-       }
-       else if(c2 == '\0' || c2 == '=')
-           return 1; // string 1 > string 2
-       else if(c1 != c2) {
-           c1 = toupper(c1);
-           c2 = toupper(c2);
-           if(c1 != c2) {
-               if(c1 < c2)
-                   return -1; // string 1 < string 2
-
-               return 1; // string 1 > string 2
-           }
-       }
+        c1 = *ptr1++;
+        c2 = *ptr2++;
+        if(c1 == '\0' || c1 == '=') {
+            if(c1 == c2)
+                break;
+
+            return -1; // string 1 < string 2
+        }
+        else if(c2 == '\0' || c2 == '=')
+            return 1; // string 1 > string 2
+        else if(c1 != c2) {
+            c1 = toupper(c1);
+            c2 = toupper(c2);
+            if(c1 != c2) {
+                if(c1 < c2)
+                    return -1; // string 1 < string 2
+
+                return 1; // string 1 > string 2
+            }
+        }
     }
     return 0;
 }
@@ -2180,35 +2181,29 @@ compare(const void *arg1, const void *arg2)
 void
 CPerlHost::Add(LPCSTR lpStr)
 {
-    char szBuffer[1024];
     LPSTR *lpPtr;
-    int index, length = strlen(lpStr)+1;
-
-    for(index = 0; lpStr[index] != '\0' && lpStr[index] != '='; ++index)
-       szBuffer[index] = lpStr[index];
-
-    szBuffer[index] = '\0';
+    STRLEN length = strlen(lpStr)+1;
 
     // replacing ?
-    lpPtr = Lookup(szBuffer);
+    lpPtr = Lookup(lpStr);
     if (lpPtr != NULL) {
-       // must allocate things via host memory allocation functions 
-       // rather than perl's Renew() et al, as the perl interpreter
-       // may either not be initialized enough when we allocate these,
-       // or may already be dead when we go to free these
-       *lpPtr = (char*)Realloc(*lpPtr, length * sizeof(char));
-       strcpy(*lpPtr, lpStr);
+        // must allocate things via host memory allocation functions 
+        // rather than perl's Renew() et al, as the perl interpreter
+        // may either not be initialized enough when we allocate these,
+        // or may already be dead when we go to free these
+        *lpPtr = (char*)Realloc(*lpPtr, length * sizeof(char));
+        strcpy(*lpPtr, lpStr);
     }
     else {
-       m_lppEnvList = (LPSTR*)Realloc(m_lppEnvList, (m_dwEnvCount+1) * sizeof(LPSTR));
-       if (m_lppEnvList) {
-           m_lppEnvList[m_dwEnvCount] = (char*)Malloc(length * sizeof(char));
-           if (m_lppEnvList[m_dwEnvCount] != NULL) {
-               strcpy(m_lppEnvList[m_dwEnvCount], lpStr);
-               ++m_dwEnvCount;
-               qsort(m_lppEnvList, m_dwEnvCount, sizeof(LPSTR), compare);
-           }
-       }
+        m_lppEnvList = (LPSTR*)Realloc(m_lppEnvList, (m_dwEnvCount+1) * sizeof(LPSTR));
+        if (m_lppEnvList) {
+            m_lppEnvList[m_dwEnvCount] = (char*)Malloc(length * sizeof(char));
+            if (m_lppEnvList[m_dwEnvCount] != NULL) {
+                strcpy(m_lppEnvList[m_dwEnvCount], lpStr);
+                ++m_dwEnvCount;
+                qsort(m_lppEnvList, m_dwEnvCount, sizeof(LPSTR), compare);
+            }
+        }
     }
 }
 
@@ -2218,7 +2213,7 @@ CPerlHost::CalculateEnvironmentSpace(void)
     DWORD index;
     DWORD dwSize = 0;
     for(index = 0; index < m_dwEnvCount; ++index)
-       dwSize += strlen(m_lppEnvList[index]) + 1;
+        dwSize += strlen(m_lppEnvList[index]) + 1;
 
     return dwSize;
 }
@@ -2263,13 +2258,13 @@ CPerlHost::CreateLocalEnvironmentStrings(VDir &vDir)
 
     // step over current directory stuff
     while(*lpTmp == '=')
-       lpTmp += strlen(lpTmp) + 1;
+        lpTmp += strlen(lpTmp) + 1;
 
     // save the start of the environment strings
     lpEnvPtr = lpTmp;
     for(dwSize = 1; *lpTmp != '\0'; lpTmp += strlen(lpTmp) + 1) {
-       // calculate the size of the environment strings
-       dwSize += strlen(lpTmp) + 1;
+        // calculate the size of the environment strings
+        dwSize += strlen(lpTmp) + 1;
     }
 
     // add the size of current directories
@@ -2281,57 +2276,57 @@ CPerlHost::CreateLocalEnvironmentStrings(VDir &vDir)
     Newx(lpStr, dwSize, char);
     lpPtr = lpStr;
     if(lpStr != NULL) {
-       // build the local environment
-       lpStr = vDir.BuildEnvironmentSpace(lpStr);
-
-       dwEnvIndex = 0;
-       lpLocalEnv = GetIndex(dwEnvIndex);
-       while(*lpEnvPtr != '\0') {
-           if(!lpLocalEnv) {
-               // all environment overrides have been added
-               // so copy string into place
-               strcpy(lpStr, lpEnvPtr);
-               nLength = strlen(lpEnvPtr) + 1;
-               lpStr += nLength;
-               lpEnvPtr += nLength;
-           }
-           else {
-               // determine which string to copy next
-               compVal = compare(&lpEnvPtr, &lpLocalEnv);
-               if(compVal < 0) {
-                   strcpy(lpStr, lpEnvPtr);
-                   nLength = strlen(lpEnvPtr) + 1;
-                   lpStr += nLength;
-                   lpEnvPtr += nLength;
-               }
-               else {
-                   char *ptr = strchr(lpLocalEnv, '=');
-                   if(ptr && ptr[1]) {
-                       strcpy(lpStr, lpLocalEnv);
-                       lpStr += strlen(lpLocalEnv) + 1;
-                   }
-                   lpLocalEnv = GetIndex(dwEnvIndex);
-                   if(compVal == 0) {
-                       // this string was replaced
-                       lpEnvPtr += strlen(lpEnvPtr) + 1;
-                   }
-               }
-           }
-       }
-
-       while(lpLocalEnv) {
-           // still have environment overrides to add
-           // so copy the strings into place if not an override
-           char *ptr = strchr(lpLocalEnv, '=');
-           if(ptr && ptr[1]) {
-               strcpy(lpStr, lpLocalEnv);
-               lpStr += strlen(lpLocalEnv) + 1;
-           }
-           lpLocalEnv = GetIndex(dwEnvIndex);
-       }
-
-       // add final NULL
-       *lpStr = '\0';
+        // build the local environment
+        lpStr = vDir.BuildEnvironmentSpace(lpStr);
+
+        dwEnvIndex = 0;
+        lpLocalEnv = GetIndex(dwEnvIndex);
+        while(*lpEnvPtr != '\0') {
+            if(!lpLocalEnv) {
+                // all environment overrides have been added
+                // so copy string into place
+                strcpy(lpStr, lpEnvPtr);
+                nLength = strlen(lpEnvPtr) + 1;
+                lpStr += nLength;
+                lpEnvPtr += nLength;
+            }
+            else {
+                // determine which string to copy next
+                compVal = compare(&lpEnvPtr, &lpLocalEnv);
+                if(compVal < 0) {
+                    strcpy(lpStr, lpEnvPtr);
+                    nLength = strlen(lpEnvPtr) + 1;
+                    lpStr += nLength;
+                    lpEnvPtr += nLength;
+                }
+                else {
+                    char *ptr = strchr(lpLocalEnv, '=');
+                    if(ptr && ptr[1]) {
+                        strcpy(lpStr, lpLocalEnv);
+                        lpStr += strlen(lpLocalEnv) + 1;
+                    }
+                    lpLocalEnv = GetIndex(dwEnvIndex);
+                    if(compVal == 0) {
+                        // this string was replaced
+                        lpEnvPtr += strlen(lpEnvPtr) + 1;
+                    }
+                }
+            }
+        }
+
+        while(lpLocalEnv) {
+            // still have environment overrides to add
+            // so copy the strings into place if not an override
+            char *ptr = strchr(lpLocalEnv, '=');
+            if(ptr && ptr[1]) {
+                strcpy(lpStr, lpLocalEnv);
+                lpStr += strlen(lpLocalEnv) + 1;
+            }
+            lpLocalEnv = GetIndex(dwEnvIndex);
+        }
+
+        // add final NULL
+        *lpStr = '\0';
     }
 
     // release the process environment strings
@@ -2344,10 +2339,10 @@ void
 CPerlHost::Reset(void)
 {
     if(m_lppEnvList != NULL) {
-       for(DWORD index = 0; index < m_dwEnvCount; ++index) {
-           Free(m_lppEnvList[index]);
-           m_lppEnvList[index] = NULL;
-       }
+        for(DWORD index = 0; index < m_dwEnvCount; ++index) {
+            Free(m_lppEnvList[index]);
+            m_lppEnvList[index] = NULL;
+        }
     }
     m_dwEnvCount = 0;
     Free(m_lppEnvList);
@@ -2360,13 +2355,13 @@ CPerlHost::Clearenv(void)
     char ch;
     LPSTR lpPtr, lpStr, lpEnvPtr;
     if (m_lppEnvList != NULL) {
-       /* set every entry to an empty string */
-       for(DWORD index = 0; index < m_dwEnvCount; ++index) {
-           char* ptr = strchr(m_lppEnvList[index], '=');
-           if(ptr) {
-               *++ptr = 0;
-           }
-       }
+        /* set every entry to an empty string */
+        for(DWORD index = 0; index < m_dwEnvCount; ++index) {
+            char* ptr = strchr(m_lppEnvList[index], '=');
+            if(ptr) {
+                *++ptr = 0;
+            }
+        }
     }
 
     /* get the process environment strings */
@@ -2374,19 +2369,19 @@ CPerlHost::Clearenv(void)
 
     /* step over current directory stuff */
     while(*lpStr == '=')
-       lpStr += strlen(lpStr) + 1;
+        lpStr += strlen(lpStr) + 1;
 
     while(*lpStr) {
-       lpPtr = strchr(lpStr, '=');
-       if(lpPtr) {
-           ch = *++lpPtr;
-           *lpPtr = 0;
-           Add(lpStr);
-           if (m_bTopLevel)
-               (void)win32_putenv(lpStr);
-           *lpPtr = ch;
-       }
-       lpStr += strlen(lpStr) + 1;
+        lpPtr = strchr(lpStr, '=');
+        if(lpPtr) {
+            ch = *++lpPtr;
+            *lpPtr = 0;
+            Add(lpStr);
+            if (m_bTopLevel)
+                (void)win32_putenv(lpStr);
+            *lpPtr = ch;
+        }
+        lpStr += strlen(lpStr) + 1;
     }
 
     win32_freeenvironmentstrings(lpEnvPtr);
@@ -2397,9 +2392,9 @@ char*
 CPerlHost::Getenv(const char *varname)
 {
     if (!m_bTopLevel) {
-       char *pEnv = Find(varname);
-       if (pEnv && *pEnv)
-           return pEnv;
+        char *pEnv = Find(varname);
+        if (pEnv && *pEnv)
+            return pEnv;
     }
     return win32_getenv(varname);
 }
@@ -2409,7 +2404,7 @@ CPerlHost::Putenv(const char *envstring)
 {
     Add(envstring);
     if (m_bTopLevel)
-       return win32_putenv(envstring);
+        return win32_putenv(envstring);
 
     return 0;
 }
@@ -2419,12 +2414,12 @@ CPerlHost::Chdir(const char *dirname)
 {
     int ret;
     if (!dirname) {
-       errno = ENOENT;
-       return -1;
+        errno = ENOENT;
+        return -1;
     }
     ret = m_pvDir->SetCurrentDirectoryA((char*)dirname);
     if(ret < 0) {
-       errno = ENOENT;
+        errno = ENOENT;
     }
     return ret;
 }