summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
authorMichael G. Schwern <schwern@pobox.com>2020-12-28 18:04:52 -0800
committerKarl Williamson <khw@cpan.org>2021-01-17 09:18:15 -0700
commit1604cfb0273418ed479719f39def5ee559bffda2 (patch)
tree166a5ab935a029ab86cf6295d6f3cb77da22e559 /win32
parent557ff1b2a4ecd18fe9229e7e0eb8fa123adc5670 (diff)
downloadperl-1604cfb0273418ed479719f39def5ee559bffda2.tar.gz
style: Detabify indentation of the C code maintained by the core.
This just detabifies to get rid of the mixed tab/space indentation. Applying consistent indentation and dealing with other tabs are another issue. Done with `expand -i`. * vutil.* left alone, it's part of version. * Left regen managed files alone for now.
Diffstat (limited to 'win32')
-rw-r--r--win32/fcrypt.c418
-rw-r--r--win32/include/dirent.h20
-rw-r--r--win32/include/sys/socket.h2
-rw-r--r--win32/perlglob.c22
-rw-r--r--win32/perlhost.h544
-rw-r--r--win32/perllib.c176
-rw-r--r--win32/vdir.h720
-rw-r--r--win32/vmem.h788
-rw-r--r--win32/win32.c2370
-rw-r--r--win32/win32.h10
-rw-r--r--win32/win32io.c4
-rw-r--r--win32/win32iop.h2
-rw-r--r--win32/win32sck.c406
-rw-r--r--win32/win32thread.h98
14 files changed, 2790 insertions, 2790 deletions
diff --git a/win32/fcrypt.c b/win32/fcrypt.c
index 4433e684c9..edc80b19dd 100644
--- a/win32/fcrypt.c
+++ b/win32/fcrypt.c
@@ -13,15 +13,15 @@
typedef unsigned char des_cblock[8];
typedef struct des_ks_struct
- {
- union {
- des_cblock _;
- /* make sure things are correct size on machines with
- * 8 byte longs */
- unsigned long pad[2];
- } ks;
+ {
+ union {
+ des_cblock _;
+ /* make sure things are correct size on machines with
+ * 8 byte longs */
+ unsigned long pad[2];
+ } ks;
#define _ ks._
- } des_key_schedule[16];
+ } des_key_schedule[16];
#define DES_KEY_SZ (sizeof(des_cblock))
#define DES_ENCRYPT 1
@@ -31,14 +31,14 @@ typedef struct des_ks_struct
#define HALF_ITERATIONS 8
#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
- l|=((unsigned long)(*((c)++)))<< 8, \
- l|=((unsigned long)(*((c)++)))<<16, \
- l|=((unsigned long)(*((c)++)))<<24)
+ l|=((unsigned long)(*((c)++)))<< 8, \
+ l|=((unsigned long)(*((c)++)))<<16, \
+ l|=((unsigned long)(*((c)++)))<<24)
#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
- *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
- *((c)++)=(unsigned char)(((l)>>16)&0xff), \
- *((c)++)=(unsigned char)(((l)>>24)&0xff))
+ *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>16)&0xff), \
+ *((c)++)=(unsigned char)(((l)>>24)&0xff))
static const unsigned long SPtrans[8][64]={
{ /* nibble 0 */
@@ -319,77 +319,77 @@ static const unsigned long skb[8][64]={
/* See ecb_encrypt.c for a pseudo description of these macros. */
#define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\
- (b)^=(t),\
- (a)^=((t)<<(n)))
+ (b)^=(t),\
+ (a)^=((t)<<(n)))
#define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\
- (a)=(a)^(t)^(t>>(16-(n))))\
+ (a)=(a)^(t)^(t>>(16-(n))))\
static const char shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0};
static int body(
- unsigned long *out0,
- unsigned long *out1,
- des_key_schedule ks,
- unsigned long Eswap0,
- unsigned long Eswap1);
+ unsigned long *out0,
+ unsigned long *out1,
+ des_key_schedule ks,
+ unsigned long Eswap0,
+ unsigned long Eswap1);
static int
des_set_key(des_cblock *key, des_key_schedule schedule)
- {
- unsigned long c,d,t,s;
- unsigned char *in;
- unsigned long *k;
- int i;
-
- k=(unsigned long *)schedule;
- in=(unsigned char *)key;
-
- c2l(in,c);
- c2l(in,d);
-
- /* I now do it in 47 simple operations :-)
- * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
- * for the inspiration. :-) */
- PERM_OP (d,c,t,4,0x0f0f0f0f);
- HPERM_OP(c,t,-2,0xcccc0000);
- HPERM_OP(d,t,-2,0xcccc0000);
- PERM_OP (d,c,t,1,0x55555555);
- PERM_OP (c,d,t,8,0x00ff00ff);
- PERM_OP (d,c,t,1,0x55555555);
- d= (((d&0x000000ff)<<16)| (d&0x0000ff00) |
- ((d&0x00ff0000)>>16)|((c&0xf0000000)>>4));
- c&=0x0fffffff;
-
- for (i=0; i<ITERATIONS; i++)
- {
- if (shifts2[i])
- { c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26)); }
- else
- { c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); }
- c&=0x0fffffff;
- d&=0x0fffffff;
- /* could be a few less shifts but I am to lazy at this
- * point in time to investigate */
- s= skb[0][ (c )&0x3f ]|
- skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]|
- skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]|
- skb[3][((c>>20)&0x01)|((c>>21)&0x06) |
- ((c>>22)&0x38)];
- t= skb[4][ (d )&0x3f ]|
- skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]|
- skb[6][ (d>>15)&0x3f ]|
- skb[7][((d>>21)&0x0f)|((d>>22)&0x30)];
-
- /* table contained 0213 4657 */
- *(k++)=((t<<16)|(s&0x0000ffff))&0xffffffff;
- s= ((s>>16)|(t&0xffff0000));
-
- s=(s<<4)|(s>>28);
- *(k++)=s&0xffffffff;
- }
- return(0);
- }
+ {
+ unsigned long c,d,t,s;
+ unsigned char *in;
+ unsigned long *k;
+ int i;
+
+ k=(unsigned long *)schedule;
+ in=(unsigned char *)key;
+
+ c2l(in,c);
+ c2l(in,d);
+
+ /* I now do it in 47 simple operations :-)
+ * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
+ * for the inspiration. :-) */
+ PERM_OP (d,c,t,4,0x0f0f0f0f);
+ HPERM_OP(c,t,-2,0xcccc0000);
+ HPERM_OP(d,t,-2,0xcccc0000);
+ PERM_OP (d,c,t,1,0x55555555);
+ PERM_OP (c,d,t,8,0x00ff00ff);
+ PERM_OP (d,c,t,1,0x55555555);
+ d= (((d&0x000000ff)<<16)| (d&0x0000ff00) |
+ ((d&0x00ff0000)>>16)|((c&0xf0000000)>>4));
+ c&=0x0fffffff;
+
+ for (i=0; i<ITERATIONS; i++)
+ {
+ if (shifts2[i])
+ { c=((c>>2)|(c<<26)); d=((d>>2)|(d<<26)); }
+ else
+ { c=((c>>1)|(c<<27)); d=((d>>1)|(d<<27)); }
+ c&=0x0fffffff;
+ d&=0x0fffffff;
+ /* could be a few less shifts but I am to lazy at this
+ * point in time to investigate */
+ s= skb[0][ (c )&0x3f ]|
+ skb[1][((c>> 6)&0x03)|((c>> 7)&0x3c)]|
+ skb[2][((c>>13)&0x0f)|((c>>14)&0x30)]|
+ skb[3][((c>>20)&0x01)|((c>>21)&0x06) |
+ ((c>>22)&0x38)];
+ t= skb[4][ (d )&0x3f ]|
+ skb[5][((d>> 7)&0x03)|((d>> 8)&0x3c)]|
+ skb[6][ (d>>15)&0x3f ]|
+ skb[7][((d>>21)&0x0f)|((d>>22)&0x30)];
+
+ /* table contained 0213 4657 */
+ *(k++)=((t<<16)|(s&0x0000ffff))&0xffffffff;
+ s= ((s>>16)|(t&0xffff0000));
+
+ s=(s<<4)|(s>>28);
+ *(k++)=s&0xffffffff;
+ }
+ return(0);
+ }
/******************************************************************
* modified stuff for crypt.
@@ -402,37 +402,37 @@ des_set_key(des_cblock *key, des_key_schedule schedule)
*/
#ifdef ALT_ECB
#define D_ENCRYPT(L,R,S) \
- v=(R^(R>>16)); \
- u=(v&E0); \
- v=(v&E1); \
- u=((u^(u<<16))^R^s[S ])<<2; \
- t=(v^(v<<16))^R^s[S+1]; \
- t=(t>>2)|(t<<30); \
- L^= \
- *(unsigned long *)(des_SP+0x0100+((t )&0xfc))+ \
- *(unsigned long *)(des_SP+0x0300+((t>> 8)&0xfc))+ \
- *(unsigned long *)(des_SP+0x0500+((t>>16)&0xfc))+ \
- *(unsigned long *)(des_SP+0x0700+((t>>24)&0xfc))+ \
- *(unsigned long *)(des_SP+ ((u )&0xfc))+ \
- *(unsigned long *)(des_SP+0x0200+((u>> 8)&0xfc))+ \
- *(unsigned long *)(des_SP+0x0400+((u>>16)&0xfc))+ \
- *(unsigned long *)(des_SP+0x0600+((u>>24)&0xfc));
+ v=(R^(R>>16)); \
+ u=(v&E0); \
+ v=(v&E1); \
+ u=((u^(u<<16))^R^s[S ])<<2; \
+ t=(v^(v<<16))^R^s[S+1]; \
+ t=(t>>2)|(t<<30); \
+ L^= \
+ *(unsigned long *)(des_SP+0x0100+((t )&0xfc))+ \
+ *(unsigned long *)(des_SP+0x0300+((t>> 8)&0xfc))+ \
+ *(unsigned long *)(des_SP+0x0500+((t>>16)&0xfc))+ \
+ *(unsigned long *)(des_SP+0x0700+((t>>24)&0xfc))+ \
+ *(unsigned long *)(des_SP+ ((u )&0xfc))+ \
+ *(unsigned long *)(des_SP+0x0200+((u>> 8)&0xfc))+ \
+ *(unsigned long *)(des_SP+0x0400+((u>>16)&0xfc))+ \
+ *(unsigned long *)(des_SP+0x0600+((u>>24)&0xfc));
#else /* original version */
#define D_ENCRYPT(L,R,S) \
- v=(R^(R>>16)); \
- u=(v&E0); \
- v=(v&E1); \
- u=(u^(u<<16))^R^s[S ]; \
- t=(v^(v<<16))^R^s[S+1]; \
- t=(t>>4)|(t<<28); \
- L^= SPtrans[1][(t )&0x3f]| \
- SPtrans[3][(t>> 8)&0x3f]| \
- SPtrans[5][(t>>16)&0x3f]| \
- SPtrans[7][(t>>24)&0x3f]| \
- SPtrans[0][(u )&0x3f]| \
- SPtrans[2][(u>> 8)&0x3f]| \
- SPtrans[4][(u>>16)&0x3f]| \
- SPtrans[6][(u>>24)&0x3f];
+ v=(R^(R>>16)); \
+ u=(v&E0); \
+ v=(v&E1); \
+ u=(u^(u<<16))^R^s[S ]; \
+ t=(v^(v<<16))^R^s[S+1]; \
+ t=(t>>4)|(t<<28); \
+ L^= SPtrans[1][(t )&0x3f]| \
+ SPtrans[3][(t>> 8)&0x3f]| \
+ SPtrans[5][(t>>16)&0x3f]| \
+ SPtrans[7][(t>>24)&0x3f]| \
+ SPtrans[0][(u )&0x3f]| \
+ SPtrans[2][(u>> 8)&0x3f]| \
+ SPtrans[4][(u>>16)&0x3f]| \
+ SPtrans[6][(u>>24)&0x3f];
#endif
unsigned const char con_salt[128]={
@@ -475,119 +475,119 @@ unsigned const char cov_2char[64]={
char *
des_fcrypt(const char *buf, const char *salt, char *buff)
- {
- unsigned int i,j,x,y;
- unsigned long Eswap0,Eswap1;
- unsigned long out[2],ll;
- des_cblock key;
- des_key_schedule ks;
- unsigned char bb[9];
- unsigned char *b=bb;
- unsigned char c,u;
+ {
+ unsigned int i,j,x,y;
+ unsigned long Eswap0,Eswap1;
+ unsigned long out[2],ll;
+ des_cblock key;
+ des_key_schedule ks;
+ unsigned char bb[9];
+ unsigned char *b=bb;
+ unsigned char c,u;
if (!good_for_salt(salt[0]) || !good_for_salt(salt[1])) {
errno = EINVAL;
return NULL;
}
- /* eay 25/08/92
- * If you call crypt("pwd","*") as often happens when you
- * have * as the pwd field in /etc/passwd, the function
- * returns *\0XXXXXXXXX
- * The \0 makes the string look like * so the pwd "*" would
- * crypt to "*". This was found when replacing the crypt in
- * our shared libraries. People found that the disbled
- * accounts effectivly had no passwd :-(. */
- x=buff[0]=((salt[0] == '\0')?(char)'A':salt[0]);
- Eswap0=con_salt[x];
- x=buff[1]=((salt[1] == '\0')?(char)'A':salt[1]);
- Eswap1=con_salt[x]<<4;
-
- for (i=0; i<8; i++)
- {
- c= *(buf++);
- if (!c) break;
- key[i]=(char)(c<<1);
- }
- for (; i<8; i++)
- key[i]=0;
-
- des_set_key((des_cblock *)(key),ks);
- body(&out[0],&out[1],ks,Eswap0,Eswap1);
-
- ll=out[0]; l2c(ll,b);
- ll=out[1]; l2c(ll,b);
- y=0;
- u=0x80;
- bb[8]=0;
- for (i=2; i<13; i++)
- {
- c=0;
- for (j=0; j<6; j++)
- {
- c<<=1;
- if (bb[y] & u) c|=1;
- u>>=1;
- if (!u)
- {
- y++;
- u=0x80;
- }
- }
- buff[i]=cov_2char[c];
- }
- buff[13]='\0';
- return buff;
- }
+ /* eay 25/08/92
+ * If you call crypt("pwd","*") as often happens when you
+ * have * as the pwd field in /etc/passwd, the function
+ * returns *\0XXXXXXXXX
+ * The \0 makes the string look like * so the pwd "*" would
+ * crypt to "*". This was found when replacing the crypt in
+ * our shared libraries. People found that the disbled
+ * accounts effectivly had no passwd :-(. */
+ x=buff[0]=((salt[0] == '\0')?(char)'A':salt[0]);
+ Eswap0=con_salt[x];
+ x=buff[1]=((salt[1] == '\0')?(char)'A':salt[1]);
+ Eswap1=con_salt[x]<<4;
+
+ for (i=0; i<8; i++)
+ {
+ c= *(buf++);
+ if (!c) break;
+ key[i]=(char)(c<<1);
+ }
+ for (; i<8; i++)
+ key[i]=0;
+
+ des_set_key((des_cblock *)(key),ks);
+ body(&out[0],&out[1],ks,Eswap0,Eswap1);
+
+ ll=out[0]; l2c(ll,b);
+ ll=out[1]; l2c(ll,b);
+ y=0;
+ u=0x80;
+ bb[8]=0;
+ for (i=2; i<13; i++)
+ {
+ c=0;
+ for (j=0; j<6; j++)
+ {
+ c<<=1;
+ if (bb[y] & u) c|=1;
+ u>>=1;
+ if (!u)
+ {
+ y++;
+ u=0x80;
+ }
+ }
+ buff[i]=cov_2char[c];
+ }
+ buff[13]='\0';
+ return buff;
+ }
static int
body( unsigned long *out0,
- unsigned long *out1,
- des_key_schedule ks,
- unsigned long Eswap0,
- unsigned long Eswap1)
- {
- unsigned long l,r,t,u,v;
+ unsigned long *out1,
+ des_key_schedule ks,
+ unsigned long Eswap0,
+ unsigned long Eswap1)
+ {
+ unsigned long l,r,t,u,v;
#ifdef ALT_ECB
- unsigned char *des_SP=(unsigned char *)SPtrans;
+ unsigned char *des_SP=(unsigned char *)SPtrans;
#endif
- unsigned long *s;
- int i,j;
- unsigned long E0,E1;
-
- l=0;
- r=0;
-
- s=(unsigned long *)ks;
- E0=Eswap0;
- E1=Eswap1;
-
- for (j=0; j<25; j++)
- {
- for (i=0; i<(ITERATIONS*2); i+=4)
- {
- D_ENCRYPT(l,r, i); /* 1 */
- D_ENCRYPT(r,l, i+2); /* 2 */
- }
- t=l;
- l=r;
- r=t;
- }
- t=r;
- r=(l>>1)|(l<<31);
- l=(t>>1)|(t<<31);
- /* clear the top bits on machines with 8byte longs */
- l&=0xffffffff;
- r&=0xffffffff;
-
- PERM_OP(r,l,t, 1,0x55555555);
- PERM_OP(l,r,t, 8,0x00ff00ff);
- PERM_OP(r,l,t, 2,0x33333333);
- PERM_OP(l,r,t,16,0x0000ffff);
- PERM_OP(r,l,t, 4,0x0f0f0f0f);
-
- *out0=l;
- *out1=r;
- return(0);
- }
+ unsigned long *s;
+ int i,j;
+ unsigned long E0,E1;
+
+ l=0;
+ r=0;
+
+ s=(unsigned long *)ks;
+ E0=Eswap0;
+ E1=Eswap1;
+
+ for (j=0; j<25; j++)
+ {
+ for (i=0; i<(ITERATIONS*2); i+=4)
+ {
+ D_ENCRYPT(l,r, i); /* 1 */
+ D_ENCRYPT(r,l, i+2); /* 2 */
+ }
+ t=l;
+ l=r;
+ r=t;
+ }
+ t=r;
+ r=(l>>1)|(l<<31);
+ l=(t>>1)|(t<<31);
+ /* clear the top bits on machines with 8byte longs */
+ l&=0xffffffff;
+ r&=0xffffffff;
+
+ PERM_OP(r,l,t, 1,0x55555555);
+ PERM_OP(l,r,t, 8,0x00ff00ff);
+ PERM_OP(r,l,t, 2,0x33333333);
+ PERM_OP(l,r,t,16,0x0000ffff);
+ PERM_OP(r,l,t, 4,0x0f0f0f0f);
+
+ *out0=l;
+ *out1=r;
+ return(0);
+ }
diff --git a/win32/include/dirent.h b/win32/include/dirent.h
index 5037825425..9396743c0d 100644
--- a/win32/include/dirent.h
+++ b/win32/include/dirent.h
@@ -24,21 +24,21 @@
/* structure of a directory entry */
typedef struct direct
{
- long d_ino; /* inode number (not used by MS-DOS) */
- long d_namlen; /* name length */
- char d_name[257]; /* file name */
+ long d_ino; /* inode number (not used by MS-DOS) */
+ long d_namlen; /* name length */
+ char d_name[257]; /* file name */
} _DIRECT;
/* structure for dir operations */
typedef struct _dir_struc
{
- char *start; /* starting position */
- char *curr; /* current position */
- long size; /* allocated size of string table */
- long nfiles; /* number of filenames in table */
- struct direct dirstr; /* directory structure to return */
- void* handle; /* system handle */
- char *end; /* position after last filename */
+ char *start; /* starting position */
+ char *curr; /* current position */
+ long size; /* allocated size of string table */
+ long nfiles; /* number of filenames in table */
+ struct direct dirstr; /* directory structure to return */
+ void* handle; /* system handle */
+ char *end; /* position after last filename */
} DIR;
#if 0 /* these have moved to win32iop.h */
diff --git a/win32/include/sys/socket.h b/win32/include/sys/socket.h
index 5374a806f5..8f93fa0429 100644
--- a/win32/include/sys/socket.h
+++ b/win32/include/sys/socket.h
@@ -73,7 +73,7 @@ int win32_recv (SOCKET s, char * buf, int len, int flags);
int win32_recvfrom (SOCKET s, char * buf, int len, int flags,
struct sockaddr *from, int * fromlen);
int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
- const struct timeval *timeout);
+ const struct timeval *timeout);
int win32_send (SOCKET s, const char * buf, int len, int flags);
int win32_sendto (SOCKET s, const char * buf, int len, int flags,
const struct sockaddr *to, int tolen);
diff --git a/win32/perlglob.c b/win32/perlglob.c
index 305fd3bee5..09061a4de0 100644
--- a/win32/perlglob.c
+++ b/win32/perlglob.c
@@ -40,12 +40,12 @@ main(int argc, char *argv[])
/* check out the file system characteristics */
if (GetFullPathName(".", MAX_PATH, root, &dummy)) {
dummy = strchr(root,'\\');
- if (dummy)
- *++dummy = '\0';
- if (GetVolumeInformation(root, volname, MAX_PATH,
- &serial, &maxname, &flags, 0, 0)) {
- downcase = !(flags & FS_CASE_IS_PRESERVED);
- }
+ if (dummy)
+ *++dummy = '\0';
+ if (GetVolumeInformation(root, volname, MAX_PATH,
+ &serial, &maxname, &flags, 0, 0)) {
+ downcase = !(flags & FS_CASE_IS_PRESERVED);
+ }
}
fd = fileno(stdout);
@@ -56,11 +56,11 @@ main(int argc, char *argv[])
assert(fd >= 0 && fd < SHRT_MAX);
setmode(fd, O_BINARY);
for (i = 1; i < argc; i++) {
- len = strlen(argv[i]);
- if (downcase)
- strlwr(argv[i]);
- if (i > 1) fwrite("\0", sizeof(char), 1, stdout);
- fwrite(argv[i], sizeof(char), len, stdout);
+ len = strlen(argv[i]);
+ if (downcase)
+ strlwr(argv[i]);
+ if (i > 1) fwrite("\0", sizeof(char), 1, stdout);
+ fwrite(argv[i], sizeof(char), len, stdout);
}
return 0;
}
diff --git a/win32/perlhost.h b/win32/perlhost.h
index 6d12abf252..5ce496590f 100644
--- a/win32/perlhost.h
+++ b/win32/perlhost.h
@@ -32,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);
@@ -61,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(); };
@@ -78,33 +78,33 @@ 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 */
@@ -119,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 */
@@ -131,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); };
@@ -146,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:
@@ -524,7 +524,7 @@ PerlEnvSiteLibPath(struct IPerlEnv* piPerl, const char *pl, STRLEN *const len)
char*
PerlEnvVendorLibPath(struct IPerlEnv* piPerl, const char *pl,
- STRLEN *const len)
+ STRLEN *const len)
{
return win32_get_vendorlib(pl, len);
}
@@ -833,17 +833,17 @@ PerlStdIOFdupopen(struct IPerlStdIO* piPerl, FILE* pf)
/* open the file in the same mode */
if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RD) {
- mode[0] = 'r';
- mode[1] = 0;
+ mode[0] = 'r';
+ mode[1] = 0;
}
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_WR) {
- mode[0] = 'a';
- mode[1] = 0;
+ mode[0] = 'a';
+ mode[1] = 0;
}
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RW) {
- mode[0] = 'r';
- mode[1] = '+';
- mode[2] = 0;
+ mode[0] = 'r';
+ mode[1] = '+';
+ mode[2] = 0;
}
/* it appears that the binmode is attached to the
@@ -854,7 +854,7 @@ 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;
}
@@ -1724,24 +1724,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
@@ -1752,48 +1752,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) */
@@ -1820,22 +1820,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
@@ -1849,15 +1849,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;
@@ -1985,20 +1985,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);
@@ -2073,7 +2073,7 @@ CPerlHost::CPerlHost(CPerlHost& host)
LPSTR lpPtr;
DWORD dwIndex = 0;
while(lpPtr = host.GetIndex(dwIndex))
- Add(lpPtr);
+ Add(lpPtr);
}
CPerlHost::~CPerlHost(void)
@@ -2092,13 +2092,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;
}
@@ -2112,26 +2112,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;
}
@@ -2140,7 +2140,7 @@ LPSTR*
CPerlHost::Lookup(LPCSTR lpStr)
{
if (!lpStr)
- return NULL;
+ return NULL;
return (LPSTR*)bsearch(&lpStr, m_lppEnvList, m_dwEnvCount, sizeof(LPSTR), lookup);
}
@@ -2153,26 +2153,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;
}
@@ -2186,23 +2186,23 @@ CPerlHost::Add(LPCSTR lpStr)
// replacing ?
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);
+ }
+ }
}
}
@@ -2212,7 +2212,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;
}
@@ -2257,13 +2257,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
@@ -2275,57 +2275,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
@@ -2338,10 +2338,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);
@@ -2354,13 +2354,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 */
@@ -2368,19 +2368,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);
@@ -2391,9 +2391,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);
}
@@ -2403,7 +2403,7 @@ CPerlHost::Putenv(const char *envstring)
{
Add(envstring);
if (m_bTopLevel)
- return win32_putenv(envstring);
+ return win32_putenv(envstring);
return 0;
}
@@ -2413,12 +2413,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;
}
diff --git a/win32/perllib.c b/win32/perllib.c
index 9948a1a3ba..a8fe7af9c0 100644
--- a/win32/perllib.c
+++ b/win32/perllib.c
@@ -51,85 +51,85 @@ win32_checkTLS(PerlInterpreter *host_perl)
{
dTHX;
if (host_perl != my_perl) {
- int *nowhere = NULL;
- abort();
+ int *nowhere = NULL;
+ abort();
}
}
EXTERN_C void
perl_get_host_info(struct IPerlMemInfo* perlMemInfo,
- struct IPerlMemInfo* perlMemSharedInfo,
- struct IPerlMemInfo* perlMemParseInfo,
- struct IPerlEnvInfo* perlEnvInfo,
- struct IPerlStdIOInfo* perlStdIOInfo,
- struct IPerlLIOInfo* perlLIOInfo,
- struct IPerlDirInfo* perlDirInfo,
- struct IPerlSockInfo* perlSockInfo,
- struct IPerlProcInfo* perlProcInfo)
+ struct IPerlMemInfo* perlMemSharedInfo,
+ struct IPerlMemInfo* perlMemParseInfo,
+ struct IPerlEnvInfo* perlEnvInfo,
+ struct IPerlStdIOInfo* perlStdIOInfo,
+ struct IPerlLIOInfo* perlLIOInfo,
+ struct IPerlDirInfo* perlDirInfo,
+ struct IPerlSockInfo* perlSockInfo,
+ struct IPerlProcInfo* perlProcInfo)
{
if (perlMemInfo) {
- Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
- perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
+ Copy(&perlMem, &perlMemInfo->perlMemList, perlMemInfo->nCount, void*);
+ perlMemInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
}
if (perlMemSharedInfo) {
- Copy(&perlMem, &perlMemSharedInfo->perlMemList, perlMemSharedInfo->nCount, void*);
- perlMemSharedInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
+ Copy(&perlMem, &perlMemSharedInfo->perlMemList, perlMemSharedInfo->nCount, void*);
+ perlMemSharedInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
}
if (perlMemParseInfo) {
- Copy(&perlMem, &perlMemParseInfo->perlMemList, perlMemParseInfo->nCount, void*);
- perlMemParseInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
+ Copy(&perlMem, &perlMemParseInfo->perlMemList, perlMemParseInfo->nCount, void*);
+ perlMemParseInfo->nCount = (sizeof(struct IPerlMem)/sizeof(void*));
}
if (perlEnvInfo) {
- Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
- perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
+ Copy(&perlEnv, &perlEnvInfo->perlEnvList, perlEnvInfo->nCount, void*);
+ perlEnvInfo->nCount = (sizeof(struct IPerlEnv)/sizeof(void*));
}
if (perlStdIOInfo) {
- Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
- perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
+ Copy(&perlStdIO, &perlStdIOInfo->perlStdIOList, perlStdIOInfo->nCount, void*);
+ perlStdIOInfo->nCount = (sizeof(struct IPerlStdIO)/sizeof(void*));
}
if (perlLIOInfo) {
- Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
- perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
+ Copy(&perlLIO, &perlLIOInfo->perlLIOList, perlLIOInfo->nCount, void*);
+ perlLIOInfo->nCount = (sizeof(struct IPerlLIO)/sizeof(void*));
}
if (perlDirInfo) {
- Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
- perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
+ Copy(&perlDir, &perlDirInfo->perlDirList, perlDirInfo->nCount, void*);
+ perlDirInfo->nCount = (sizeof(struct IPerlDir)/sizeof(void*));
}
if (perlSockInfo) {
- Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
- perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
+ Copy(&perlSock, &perlSockInfo->perlSockList, perlSockInfo->nCount, void*);
+ perlSockInfo->nCount = (sizeof(struct IPerlSock)/sizeof(void*));
}
if (perlProcInfo) {
- Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
- perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
+ Copy(&perlProc, &perlProcInfo->perlProcList, perlProcInfo->nCount, void*);
+ perlProcInfo->nCount = (sizeof(struct IPerlProc)/sizeof(void*));
}
}
EXTERN_C PerlInterpreter*
perl_alloc_override(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)
{
PerlInterpreter *my_perl = NULL;
CPerlHost* pHost = new CPerlHost(ppMem, ppMemShared, ppMemParse, ppEnv,
- ppStdIO, ppLIO, ppDir, ppSock, ppProc);
+ ppStdIO, ppLIO, ppDir, ppSock, ppProc);
if (pHost) {
- my_perl = perl_alloc_using(pHost->m_pHostperlMem,
- pHost->m_pHostperlMemShared,
- pHost->m_pHostperlMemParse,
- pHost->m_pHostperlEnv,
- pHost->m_pHostperlStdIO,
- pHost->m_pHostperlLIO,
- pHost->m_pHostperlDir,
- pHost->m_pHostperlSock,
- pHost->m_pHostperlProc);
- if (my_perl) {
- w32_internal_host = pHost;
- pHost->host_perl = my_perl;
- }
+ my_perl = perl_alloc_using(pHost->m_pHostperlMem,
+ pHost->m_pHostperlMemShared,
+ pHost->m_pHostperlMemParse,
+ pHost->m_pHostperlEnv,
+ pHost->m_pHostperlStdIO,
+ pHost->m_pHostperlLIO,
+ pHost->m_pHostperlDir,
+ pHost->m_pHostperlSock,
+ pHost->m_pHostperlProc);
+ if (my_perl) {
+ w32_internal_host = pHost;
+ pHost->host_perl = my_perl;
+ }
}
return my_perl;
}
@@ -140,19 +140,19 @@ perl_alloc(void)
PerlInterpreter* my_perl = NULL;
CPerlHost* pHost = new CPerlHost();
if (pHost) {
- my_perl = perl_alloc_using(pHost->m_pHostperlMem,
- pHost->m_pHostperlMemShared,
- pHost->m_pHostperlMemParse,
- pHost->m_pHostperlEnv,
- pHost->m_pHostperlStdIO,
- pHost->m_pHostperlLIO,
- pHost->m_pHostperlDir,
- pHost->m_pHostperlSock,
- pHost->m_pHostperlProc);
- if (my_perl) {
- w32_internal_host = pHost;
+ my_perl = perl_alloc_using(pHost->m_pHostperlMem,
+ pHost->m_pHostperlMemShared,
+ pHost->m_pHostperlMemParse,
+ pHost->m_pHostperlEnv,
+ pHost->m_pHostperlStdIO,
+ pHost->m_pHostperlLIO,
+ pHost->m_pHostperlDir,
+ pHost->m_pHostperlSock,
+ pHost->m_pHostperlProc);
+ if (my_perl) {
+ w32_internal_host = pHost;
pHost->host_perl = my_perl;
- }
+ }
}
return my_perl;
}
@@ -178,7 +178,7 @@ RunPerl(int argc, char **argv, char **env)
PERL_SYS_INIT(&argc,&argv);
if (!(my_perl = perl_alloc()))
- return (1);
+ return (1);
perl_construct(my_perl);
PL_perl_destruct_level = 0;
@@ -194,11 +194,11 @@ RunPerl(int argc, char **argv, char **env)
if (!perl_parse(my_perl, xs_init, argc, argv, env)) {
#if defined(TOP_CLONE) && defined(USE_ITHREADS) /* XXXXXX testing */
- new_perl = perl_clone(my_perl, 1);
- (void) perl_run(new_perl);
- PERL_SET_THX(my_perl);
+ new_perl = perl_clone(my_perl, 1);
+ (void) perl_run(new_perl);
+ PERL_SET_THX(my_perl);
#else
- (void) perl_run(my_perl);
+ (void) perl_run(my_perl);
#endif
}
@@ -206,9 +206,9 @@ RunPerl(int argc, char **argv, char **env)
perl_free(my_perl);
#ifdef USE_ITHREADS
if (new_perl) {
- PERL_SET_THX(new_perl);
- exitstatus = perl_destruct(new_perl);
- perl_free(new_perl);
+ PERL_SET_THX(new_perl);
+ exitstatus = perl_destruct(new_perl);
+ perl_free(new_perl);
}
#endif
@@ -229,23 +229,23 @@ EXTERN_C /* GCC in C++ mode mangles the name, otherwise */
#endif
BOOL APIENTRY
DllMain(HINSTANCE hModule, /* DLL module handle */
- DWORD fdwReason, /* reason called */
- LPVOID lpvReserved) /* reserved */
+ DWORD fdwReason, /* reason called */
+ LPVOID lpvReserved) /* reserved */
{
switch (fdwReason) {
- /* The DLL is attaching to a process due to process
- * initialization or a call to LoadLibrary.
- */
+ /* The DLL is attaching to a process due to process
+ * initialization or a call to LoadLibrary.
+ */
case DLL_PROCESS_ATTACH:
- DisableThreadLibraryCalls((HMODULE)hModule);
+ DisableThreadLibraryCalls((HMODULE)hModule);
- w32_perldll_handle = hModule;
- set_w32_module_name();
- break;
+ w32_perldll_handle = hModule;
+ set_w32_module_name();
+ break;
- /* The DLL is detaching from a process due to
- * process termination or call to FreeLibrary.
- */
+ /* The DLL is detaching from a process due to
+ * process termination or call to FreeLibrary.
+ */
case DLL_PROCESS_DETACH:
/* As long as we use TerminateProcess()/TerminateThread() etc. for mimicing kill()
anything here had better be harmless if:
@@ -253,23 +253,23 @@ DllMain(HINSTANCE hModule, /* DLL module handle */
B. Called after memory allocation for Heap has been forcibly removed by OS.
PerlIO_cleanup() was done here but fails (B).
*/
- EndSockets();
+ EndSockets();
#if defined(USE_ITHREADS)
- if (PL_curinterp)
- FREE_THREAD_KEY;
+ if (PL_curinterp)
+ FREE_THREAD_KEY;
#endif
- break;
+ break;
- /* The attached process creates a new thread. */
+ /* The attached process creates a new thread. */
case DLL_THREAD_ATTACH:
- break;
+ break;
- /* The thread of the attached process terminates. */
+ /* The thread of the attached process terminates. */
case DLL_THREAD_DETACH:
- break;
+ break;
default:
- break;
+ break;
}
return TRUE;
}
@@ -295,6 +295,6 @@ perl_clone_host(PerlInterpreter* proto_perl, UV flags) {
proto_perl->Isys_intern.internal_host = h;
h->host_perl = proto_perl;
return proto_perl;
-
+
}
#endif
diff --git a/win32/vdir.h b/win32/vdir.h
index c21ec7c400..f06830af41 100644
--- a/win32/vdir.h
+++ b/win32/vdir.h
@@ -34,25 +34,25 @@ public:
inline char* GetCurrentDirectoryA(int dwBufSize, char *lpBuffer)
{
- char* ptr = dirTableA[nDefault];
- while (--dwBufSize)
- {
- if ((*lpBuffer++ = *ptr++) == '\0')
- break;
- }
+ char* ptr = dirTableA[nDefault];
+ while (--dwBufSize)
+ {
+ if ((*lpBuffer++ = *ptr++) == '\0')
+ break;
+ }
*lpBuffer = '\0';
- return /* unused */ NULL;
+ return /* unused */ NULL;
};
inline WCHAR* GetCurrentDirectoryW(int dwBufSize, WCHAR *lpBuffer)
{
- WCHAR* ptr = dirTableW[nDefault];
- while (--dwBufSize)
- {
- if ((*lpBuffer++ = *ptr++) == '\0')
- break;
- }
+ WCHAR* ptr = dirTableW[nDefault];
+ while (--dwBufSize)
+ {
+ if ((*lpBuffer++ = *ptr++) == '\0')
+ break;
+ }
*lpBuffer = '\0';
- return /* unused */ NULL;
+ return /* unused */ NULL;
};
DWORD CalculateEnvironmentSpace(void);
@@ -66,54 +66,54 @@ protected:
inline const char *GetDefaultDirA(void)
{
- return dirTableA[nDefault];
+ return dirTableA[nDefault];
};
inline void SetDefaultDirA(char const *pPath, int index)
{
- SetDirA(pPath, index);
- nDefault = index;
+ SetDirA(pPath, index);
+ nDefault = index;
};
inline const WCHAR *GetDefaultDirW(void)
{
- return dirTableW[nDefault];
+ return dirTableW[nDefault];
};
inline void SetDefaultDirW(WCHAR const *pPath, int index)
{
- SetDirW(pPath, index);
- nDefault = index;
+ SetDirW(pPath, index);
+ nDefault = index;
};
inline const char *GetDirA(int index)
{
- char *ptr = dirTableA[index];
- if (!ptr) {
- /* simulate the existence of this drive */
- ptr = szLocalBufferA;
- ptr[0] = 'A' + index;
- ptr[1] = ':';
- ptr[2] = '\\';
- ptr[3] = 0;
- }
- return ptr;
+ char *ptr = dirTableA[index];
+ if (!ptr) {
+ /* simulate the existence of this drive */
+ ptr = szLocalBufferA;
+ ptr[0] = 'A' + index;
+ ptr[1] = ':';
+ ptr[2] = '\\';
+ ptr[3] = 0;
+ }
+ return ptr;
};
inline const WCHAR *GetDirW(int index)
{
- WCHAR *ptr = dirTableW[index];
- if (!ptr) {
- /* simulate the existence of this drive */
- ptr = szLocalBufferW;
- ptr[0] = 'A' + index;
- ptr[1] = ':';
- ptr[2] = '\\';
- ptr[3] = 0;
- }
- return ptr;
+ WCHAR *ptr = dirTableW[index];
+ if (!ptr) {
+ /* simulate the existence of this drive */
+ ptr = szLocalBufferW;
+ ptr[0] = 'A' + index;
+ ptr[1] = ':';
+ ptr[2] = '\\';
+ ptr[3] = 0;
+ }
+ return ptr;
};
inline int DriveIndex(char chr)
{
- if (chr == '\\' || chr == '/')
- return ('Z'-'A')+1;
- return (chr | 0x20)-'a';
+ if (chr == '\\' || chr == '/')
+ return ('Z'-'A')+1;
+ return (chr | 0x20)-'a';
};
VMem *pMem;
@@ -139,16 +139,16 @@ void VDir::Init(VDir* pDir, VMem *p)
pMem = p;
if (pDir) {
- for (index = 0; index < driveCount; ++index) {
- SetDirW(pDir->GetDirW(index), index);
- }
- nDefault = pDir->GetDefault();
+ for (index = 0; index < driveCount; ++index) {
+ SetDirW(pDir->GetDirW(index), index);
+ }
+ nDefault = pDir->GetDefault();
}
else {
- int bSave = bManageDirectory;
- DWORD driveBits = GetLogicalDrives();
+ int bSave = bManageDirectory;
+ DWORD driveBits = GetLogicalDrives();
- bManageDirectory = 0;
+ bManageDirectory = 0;
WCHAR szBuffer[MAX_PATH*driveCount];
if (GetLogicalDriveStringsW(sizeof(szBuffer), szBuffer)) {
WCHAR* pEnv = GetEnvironmentStringsW();
@@ -162,7 +162,7 @@ void VDir::Init(VDir* pDir, VMem *p)
FreeEnvironmentStringsW(pEnv);
}
SetDefaultW(L".");
- bManageDirectory = bSave;
+ bManageDirectory = bSave;
}
}
@@ -172,30 +172,30 @@ int VDir::SetDirA(char const *pPath, int index)
int length = 0;
WCHAR wBuffer[MAX_PATH+1];
if (index < driveCount && pPath != NULL) {
- length = strlen(pPath);
- pMem->Free(dirTableA[index]);
- ptr = dirTableA[index] = (char*)pMem->Malloc(length+2);
- if (ptr != NULL) {
- strcpy(ptr, pPath);
- ptr += length-1;
- chr = *ptr++;
- if (chr != '\\' && chr != '/') {
- *ptr++ = '\\';
- *ptr = '\0';
- }
- MultiByteToWideChar(CP_ACP, 0, dirTableA[index], -1,
- wBuffer, (sizeof(wBuffer)/sizeof(WCHAR)));
- length = wcslen(wBuffer);
- pMem->Free(dirTableW[index]);
- dirTableW[index] = (WCHAR*)pMem->Malloc((length+1)*2);
- if (dirTableW[index] != NULL) {
- wcscpy(dirTableW[index], wBuffer);
- }
- }
+ length = strlen(pPath);
+ pMem->Free(dirTableA[index]);
+ ptr = dirTableA[index] = (char*)pMem->Malloc(length+2);
+ if (ptr != NULL) {
+ strcpy(ptr, pPath);
+ ptr += length-1;
+ chr = *ptr++;
+ if (chr != '\\' && chr != '/') {
+ *ptr++ = '\\';
+ *ptr = '\0';
+ }
+ MultiByteToWideChar(CP_ACP, 0, dirTableA[index], -1,
+ wBuffer, (sizeof(wBuffer)/sizeof(WCHAR)));
+ length = wcslen(wBuffer);
+ pMem->Free(dirTableW[index]);
+ dirTableW[index] = (WCHAR*)pMem->Malloc((length+1)*2);
+ if (dirTableW[index] != NULL) {
+ wcscpy(dirTableW[index], wBuffer);
+ }
+ }
}
if(bManageDirectory)
- ::SetCurrentDirectoryA(pPath);
+ ::SetCurrentDirectoryA(pPath);
return length;
}
@@ -203,26 +203,26 @@ int VDir::SetDirA(char const *pPath, int index)
void VDir::FromEnvA(char *pEnv, int index)
{ /* gets the directory for index from the environment variable. */
while (*pEnv != '\0') {
- if ((pEnv[0] == '=') && (DriveIndex(pEnv[1]) == index)
+ if ((pEnv[0] == '=') && (DriveIndex(pEnv[1]) == index)
&& pEnv[2] == ':' && pEnv[3] == '=') {
- SetDirA(&pEnv[4], index);
- break;
- }
- else
- pEnv += strlen(pEnv)+1;
+ SetDirA(&pEnv[4], index);
+ break;
+ }
+ else
+ pEnv += strlen(pEnv)+1;
}
}
void VDir::FromEnvW(WCHAR *pEnv, int index)
{ /* gets the directory for index from the environment variable. */
while (*pEnv != '\0') {
- if ((pEnv[0] == '=') && (DriveIndex((char)pEnv[1]) == index)
+ if ((pEnv[0] == '=') && (DriveIndex((char)pEnv[1]) == index)
&& pEnv[2] == ':' && pEnv[3] == '=') {
- SetDirW(&pEnv[4], index);
- break;
- }
- else
- pEnv += wcslen(pEnv)+1;
+ SetDirW(&pEnv[4], index);
+ break;
+ }
+ else
+ pEnv += wcslen(pEnv)+1;
}
}
@@ -233,9 +233,9 @@ void VDir::SetDefaultA(char const *pDefault)
if (GetFullPathNameA(pDefault, sizeof(szBuffer), szBuffer, &pPtr)) {
if (*pDefault != '.' && pPtr != NULL)
- *pPtr = '\0';
+ *pPtr = '\0';
- SetDefaultDirA(szBuffer, DriveIndex(szBuffer[0]));
+ SetDefaultDirA(szBuffer, DriveIndex(szBuffer[0]));
}
}
@@ -244,31 +244,31 @@ int VDir::SetDirW(WCHAR const *pPath, int index)
WCHAR chr, *ptr;
int length = 0;
if (index < driveCount && pPath != NULL) {
- length = wcslen(pPath);
- pMem->Free(dirTableW[index]);
- ptr = dirTableW[index] = (WCHAR*)pMem->Malloc((length+2)*2);
- if (ptr != NULL) {
+ length = wcslen(pPath);
+ pMem->Free(dirTableW[index]);
+ ptr = dirTableW[index] = (WCHAR*)pMem->Malloc((length+2)*2);
+ if (ptr != NULL) {
char *ansi;
- wcscpy(ptr, pPath);
- ptr += length-1;
- chr = *ptr++;
- if (chr != '\\' && chr != '/') {
- *ptr++ = '\\';
- *ptr = '\0';
- }
+ wcscpy(ptr, pPath);
+ ptr += length-1;
+ chr = *ptr++;
+ if (chr != '\\' && chr != '/') {
+ *ptr++ = '\\';
+ *ptr = '\0';
+ }
ansi = win32_ansipath(dirTableW[index]);
- length = strlen(ansi);
- pMem->Free(dirTableA[index]);
- dirTableA[index] = (char*)pMem->Malloc(length+1);
- if (dirTableA[index] != NULL) {
- strcpy(dirTableA[index], ansi);
- }
+ length = strlen(ansi);
+ pMem->Free(dirTableA[index]);
+ dirTableA[index] = (char*)pMem->Malloc(length+1);
+ if (dirTableA[index] != NULL) {
+ strcpy(dirTableA[index], ansi);
+ }
win32_free(ansi);
- }
+ }
}
if(bManageDirectory)
- ::SetCurrentDirectoryW(pPath);
+ ::SetCurrentDirectoryW(pPath);
return length;
}
@@ -280,9 +280,9 @@ void VDir::SetDefaultW(WCHAR const *pDefault)
if (GetFullPathNameW(pDefault, (sizeof(szBuffer)/sizeof(WCHAR)), szBuffer, &pPtr)) {
if (*pDefault != '.' && pPtr != NULL)
- *pPtr = '\0';
+ *pPtr = '\0';
- SetDefaultDirW(szBuffer, DriveIndex((char)szBuffer[0]));
+ SetDefaultDirW(szBuffer, DriveIndex((char)szBuffer[0]));
}
}
@@ -314,69 +314,69 @@ inline bool IsSpecialFileName(const char* pName)
char ch = (pName[0] & ~0x20);
switch (ch)
{
- case 'A': /* AUX */
- if (((pName[1] & ~0x20) == 'U')
- && ((pName[2] & ~0x20) == 'X')
- && !pName[3])
- return true;
- break;
- case 'C': /* CLOCK$, COMx, CON, CONIN$ CONOUT$ */
- ch = (pName[1] & ~0x20);
- switch (ch)
- {
- case 'L': /* CLOCK$ */
- if (((pName[2] & ~0x20) == 'O')
- && ((pName[3] & ~0x20) == 'C')
- && ((pName[4] & ~0x20) == 'K')
- && (pName[5] == '$')
- && !pName[6])
- return true;
- break;
- case 'O': /* COMx, CON, CONIN$ CONOUT$ */
- if ((pName[2] & ~0x20) == 'M') {
- if ( inRANGE(pName[3], '1', '9')
- && !pName[4])
- return true;
- }
- else if ((pName[2] & ~0x20) == 'N') {
- if (!pName[3])
- return true;
- else if ((pName[3] & ~0x20) == 'I') {
- if (((pName[4] & ~0x20) == 'N')
- && (pName[5] == '$')
- && !pName[6])
- return true;
- }
- else if ((pName[3] & ~0x20) == 'O') {
- if (((pName[4] & ~0x20) == 'U')
- && ((pName[5] & ~0x20) == 'T')
- && (pName[6] == '$')
- && !pName[7])
- return true;
- }
- }
- break;
- }
- break;
- case 'L': /* LPTx */
- if (((pName[1] & ~0x20) == 'U')
- && ((pName[2] & ~0x20) == 'X')
- && inRANGE(pName[3], '1', '9')
- && !pName[4])
- return true;
- break;
- case 'N': /* NUL */
- if (((pName[1] & ~0x20) == 'U')
- && ((pName[2] & ~0x20) == 'L')
- && !pName[3])
- return true;
- break;
- case 'P': /* PRN */
- if (((pName[1] & ~0x20) == 'R')
- && ((pName[2] & ~0x20) == 'N')
- && !pName[3])
- return true;
- break;
+ case 'A': /* AUX */
+ if (((pName[1] & ~0x20) == 'U')
+ && ((pName[2] & ~0x20) == 'X')
+ && !pName[3])
+ return true;
+ break;
+ case 'C': /* CLOCK$, COMx, CON, CONIN$ CONOUT$ */
+ ch = (pName[1] & ~0x20);
+ switch (ch)
+ {
+ case 'L': /* CLOCK$ */
+ if (((pName[2] & ~0x20) == 'O')
+ && ((pName[3] & ~0x20) == 'C')
+ && ((pName[4] & ~0x20) == 'K')
+ && (pName[5] == '$')
+ && !pName[6])
+ return true;
+ break;
+ case 'O': /* COMx, CON, CONIN$ CONOUT$ */
+ if ((pName[2] & ~0x20) == 'M') {
+ if ( inRANGE(pName[3], '1', '9')
+ && !pName[4])
+ return true;
+ }
+ else if ((pName[2] & ~0x20) == 'N') {
+ if (!pName[3])
+ return true;
+ else if ((pName[3] & ~0x20) == 'I') {
+ if (((pName[4] & ~0x20) == 'N')
+ && (pName[5] == '$')
+ && !pName[6])
+ return true;
+ }
+ else if ((pName[3] & ~0x20) == 'O') {
+ if (((pName[4] & ~0x20) == 'U')
+ && ((pName[5] & ~0x20) == 'T')
+ && (pName[6] == '$')
+ && !pName[7])
+ return true;
+ }
+ }
+ break;
+ }
+ break;
+ case 'L': /* LPTx */
+ if (((pName[1] & ~0x20) == 'U')
+ && ((pName[2] & ~0x20) == 'X')
+ && inRANGE(pName[3], '1', '9')
+ && !pName[4])
+ return true;
+ break;
+ case 'N': /* NUL */
+ if (((pName[1] & ~0x20) == 'U')
+ && ((pName[2] & ~0x20) == 'L')
+ && !pName[3])
+ return true;
+ break;
+ case 'P': /* PRN */
+ if (((pName[1] & ~0x20) == 'R')
+ && ((pName[2] & ~0x20) == 'N')
+ && !pName[3])
+ return true;
+ break;
}
return false;
}
@@ -392,66 +392,66 @@ char *VDir::MapPathA(const char *pInName)
int length = strlen(pInName);
if (!length)
- return (char*)pInName;
+ return (char*)pInName;
if (length > MAX_PATH) {
- strncpy(szlBuf, pInName, MAX_PATH);
- if (IsPathSep(pInName[0]) && !IsPathSep(pInName[1])) {
- /* absolute path - reduce length by 2 for drive specifier */
- szlBuf[MAX_PATH-2] = '\0';
- }
- else
- szlBuf[MAX_PATH] = '\0';
- pInName = szlBuf;
+ strncpy(szlBuf, pInName, MAX_PATH);
+ if (IsPathSep(pInName[0]) && !IsPathSep(pInName[1])) {
+ /* absolute path - reduce length by 2 for drive specifier */
+ szlBuf[MAX_PATH-2] = '\0';
+ }
+ else
+ szlBuf[MAX_PATH] = '\0';
+ pInName = szlBuf;
}
/* strlen(pInName) is now <= MAX_PATH */
if (length > 1 && pInName[1] == ':') {
- /* has drive letter */
- if (length > 2 && IsPathSep(pInName[2])) {
- /* absolute with drive letter */
- DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
- }
- else {
- /* relative path with drive letter */
+ /* has drive letter */
+ if (length > 2 && IsPathSep(pInName[2])) {
+ /* absolute with drive letter */
+ DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
+ }
+ else {
+ /* relative path with drive letter */
driveIndex = DriveIndex(*pInName);
if (driveIndex < 0 || driveIndex >= driveLetterCount)
return (char *)pInName;
- strcpy(szBuffer, GetDirA(driveIndex));
- strcat(szBuffer, &pInName[2]);
- if(strlen(szBuffer) > MAX_PATH)
- szBuffer[MAX_PATH] = '\0';
+ strcpy(szBuffer, GetDirA(driveIndex));
+ strcat(szBuffer, &pInName[2]);
+ if(strlen(szBuffer) > MAX_PATH)
+ szBuffer[MAX_PATH] = '\0';
- DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
- }
+ DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
+ }
}
else {
- /* no drive letter */
- if (length > 1 && IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
- /* UNC name */
- DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
- }
- else {
- strcpy(szBuffer, GetDefaultDirA());
- if (IsPathSep(pInName[0])) {
- /* absolute path */
- strcpy(&szBuffer[2], pInName);
- DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
- }
- else {
- /* relative path */
- if (IsSpecialFileName(pInName)) {
- return (char*)pInName;
- }
- else {
- strcat(szBuffer, pInName);
- if (strlen(szBuffer) > MAX_PATH)
- szBuffer[MAX_PATH] = '\0';
-
- DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
- }
- }
- }
+ /* no drive letter */
+ if (length > 1 && IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
+ /* UNC name */
+ DoGetFullPathNameA((char*)pInName, sizeof(szLocalBufferA), szLocalBufferA);
+ }
+ else {
+ strcpy(szBuffer, GetDefaultDirA());
+ if (IsPathSep(pInName[0])) {
+ /* absolute path */
+ strcpy(&szBuffer[2], pInName);
+ DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
+ }
+ else {
+ /* relative path */
+ if (IsSpecialFileName(pInName)) {
+ return (char*)pInName;
+ }
+ else {
+ strcat(szBuffer, pInName);
+ if (strlen(szBuffer) > MAX_PATH)
+ szBuffer[MAX_PATH] = '\0';
+
+ DoGetFullPathNameA(szBuffer, sizeof(szLocalBufferA), szLocalBufferA);
+ }
+ }
+ }
}
return szLocalBufferA;
@@ -465,17 +465,17 @@ int VDir::SetCurrentDirectoryA(char *lpBuffer)
pPtr = MapPathA(lpBuffer);
length = strlen(pPtr);
if(length > 3 && IsPathSep(pPtr[length-1])) {
- /* don't remove the trailing slash from 'x:\' */
- pPtr[length-1] = '\0';
+ /* don't remove the trailing slash from 'x:\' */
+ pPtr[length-1] = '\0';
}
DWORD r = GetFileAttributesA(pPtr);
if ((r != 0xffffffff) && (r & FILE_ATTRIBUTE_DIRECTORY))
{
- char szBuffer[(MAX_PATH+1)*2];
- DoGetFullPathNameA(pPtr, sizeof(szBuffer), szBuffer);
- SetDefaultDirA(szBuffer, DriveIndex(szBuffer[0]));
- nRet = 0;
+ char szBuffer[(MAX_PATH+1)*2];
+ DoGetFullPathNameA(pPtr, sizeof(szBuffer), szBuffer);
+ SetDefaultDirA(szBuffer, DriveIndex(szBuffer[0]));
+ nRet = 0;
}
return nRet;
@@ -486,9 +486,9 @@ DWORD VDir::CalculateEnvironmentSpace(void)
int index;
DWORD dwSize = 0;
for (index = 0; index < driveCount; ++index) {
- if (dirTableA[index] != NULL) {
- dwSize += strlen(dirTableA[index]) + 5; /* add 1 for trailing NULL and 4 for '=D:=' */
- }
+ if (dirTableA[index] != NULL) {
+ dwSize += strlen(dirTableA[index]) + 5; /* add 1 for trailing NULL and 4 for '=D:=' */
+ }
}
return dwSize;
}
@@ -498,22 +498,22 @@ LPSTR VDir::BuildEnvironmentSpace(LPSTR lpStr)
int index, length;
LPSTR lpDirStr;
for (index = 0; index < driveCount; ++index) {
- lpDirStr = dirTableA[index];
- if (lpDirStr != NULL) {
- lpStr[0] = '=';
- lpStr[1] = lpDirStr[0];
- lpStr[2] = '\0';
- CharUpper(&lpStr[1]);
- lpStr[2] = ':';
- lpStr[3] = '=';
- strcpy(&lpStr[4], lpDirStr);
- length = strlen(lpDirStr);
- lpStr += length + 5; /* add 1 for trailing NULL and 4 for '=D:=' */
- if (length > 3 && IsPathSep(lpStr[-2])) {
- lpStr[-2] = '\0'; /* remove the trailing path separator */
- --lpStr;
- }
- }
+ lpDirStr = dirTableA[index];
+ if (lpDirStr != NULL) {
+ lpStr[0] = '=';
+ lpStr[1] = lpDirStr[0];
+ lpStr[2] = '\0';
+ CharUpper(&lpStr[1]);
+ lpStr[2] = ':';
+ lpStr[3] = '=';
+ strcpy(&lpStr[4], lpDirStr);
+ length = strlen(lpDirStr);
+ lpStr += length + 5; /* add 1 for trailing NULL and 4 for '=D:=' */
+ if (length > 3 && IsPathSep(lpStr[-2])) {
+ lpStr[-2] = '\0'; /* remove the trailing path separator */
+ --lpStr;
+ }
+ }
}
return lpStr;
}
@@ -546,69 +546,69 @@ inline bool IsSpecialFileName(const WCHAR* pName)
WCHAR ch = (pName[0] & ~0x20);
switch (ch)
{
- case 'A': /* AUX */
- if (((pName[1] & ~0x20) == 'U')
- && ((pName[2] & ~0x20) == 'X')
- && !pName[3])
- return true;
- break;
- case 'C': /* CLOCK$, COMx, CON, CONIN$ CONOUT$ */
- ch = (pName[1] & ~0x20);
- switch (ch)
- {
- case 'L': /* CLOCK$ */
- if (((pName[2] & ~0x20) == 'O')
- && ((pName[3] & ~0x20) == 'C')
- && ((pName[4] & ~0x20) == 'K')
- && (pName[5] == '$')
- && !pName[6])
- return true;
- break;
- case 'O': /* COMx, CON, CONIN$ CONOUT$ */
- if ((pName[2] & ~0x20) == 'M') {
- if ( inRANGE(pName[3], '1', '9')
- && !pName[4])
- return true;
- }
- else if ((pName[2] & ~0x20) == 'N') {
- if (!pName[3])
- return true;
- else if ((pName[3] & ~0x20) == 'I') {
- if (((pName[4] & ~0x20) == 'N')
- && (pName[5] == '$')
- && !pName[6])
- return true;
- }
- else if ((pName[3] & ~0x20) == 'O') {
- if (((pName[4] & ~0x20) == 'U')
- && ((pName[5] & ~0x20) == 'T')
- && (pName[6] == '$')
- && !pName[7])
- return true;
- }
- }
- break;
- }
- break;
- case 'L': /* LPTx */
- if (((pName[1] & ~0x20) == 'U')
- && ((pName[2] & ~0x20) == 'X')
- && inRANGE(pName[3], '1', '9')
- && !pName[4])
- return true;
- break;
- case 'N': /* NUL */
- if (((pName[1] & ~0x20) == 'U')
- && ((pName[2] & ~0x20) == 'L')
- && !pName[3])
- return true;
- break;
- case 'P': /* PRN */
- if (((pName[1] & ~0x20) == 'R')
- && ((pName[2] & ~0x20) == 'N')
- && !pName[3])
- return true;
- break;
+ case 'A': /* AUX */
+ if (((pName[1] & ~0x20) == 'U')
+ && ((pName[2] & ~0x20) == 'X')
+ && !pName[3])
+ return true;
+ break;
+ case 'C': /* CLOCK$, COMx, CON, CONIN$ CONOUT$ */
+ ch = (pName[1] & ~0x20);
+ switch (ch)
+ {
+ case 'L': /* CLOCK$ */
+ if (((pName[2] & ~0x20) == 'O')
+ && ((pName[3] & ~0x20) == 'C')
+ && ((pName[4] & ~0x20) == 'K')
+ && (pName[5] == '$')
+ && !pName[6])
+ return true;
+ break;
+ case 'O': /* COMx, CON, CONIN$ CONOUT$ */
+ if ((pName[2] & ~0x20) == 'M') {
+ if ( inRANGE(pName[3], '1', '9')
+ && !pName[4])
+ return true;
+ }
+ else if ((pName[2] & ~0x20) == 'N') {
+ if (!pName[3])
+ return true;
+ else if ((pName[3] & ~0x20) == 'I') {
+ if (((pName[4] & ~0x20) == 'N')
+ && (pName[5] == '$')
+ && !pName[6])
+ return true;
+ }
+ else if ((pName[3] & ~0x20) == 'O') {
+ if (((pName[4] & ~0x20) == 'U')
+ && ((pName[5] & ~0x20) == 'T')
+ && (pName[6] == '$')
+ && !pName[7])
+ return true;
+ }
+ }
+ break;
+ }
+ break;
+ case 'L': /* LPTx */
+ if (((pName[1] & ~0x20) == 'U')
+ && ((pName[2] & ~0x20) == 'X')
+ && inRANGE(pName[3], '1', '9')
+ && !pName[4])
+ return true;
+ break;
+ case 'N': /* NUL */
+ if (((pName[1] & ~0x20) == 'U')
+ && ((pName[2] & ~0x20) == 'L')
+ && !pName[3])
+ return true;
+ break;
+ case 'P': /* PRN */
+ if (((pName[1] & ~0x20) == 'R')
+ && ((pName[2] & ~0x20) == 'N')
+ && !pName[3])
+ return true;
+ break;
}
return false;
}
@@ -624,66 +624,66 @@ WCHAR* VDir::MapPathW(const WCHAR *pInName)
int length = wcslen(pInName);
if (!length)
- return (WCHAR*)pInName;
+ return (WCHAR*)pInName;
if (length > MAX_PATH) {
- wcsncpy(szlBuf, pInName, MAX_PATH);
- if (IsPathSep(pInName[0]) && !IsPathSep(pInName[1])) {
- /* absolute path - reduce length by 2 for drive specifier */
- szlBuf[MAX_PATH-2] = '\0';
- }
- else
- szlBuf[MAX_PATH] = '\0';
- pInName = szlBuf;
+ wcsncpy(szlBuf, pInName, MAX_PATH);
+ if (IsPathSep(pInName[0]) && !IsPathSep(pInName[1])) {
+ /* absolute path - reduce length by 2 for drive specifier */
+ szlBuf[MAX_PATH-2] = '\0';
+ }
+ else
+ szlBuf[MAX_PATH] = '\0';
+ pInName = szlBuf;
}
/* strlen(pInName) is now <= MAX_PATH */
if (length > 1 && pInName[1] == ':') {
- /* has drive letter */
- if (IsPathSep(pInName[2])) {
- /* absolute with drive letter */
- DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
- }
- else {
- /* relative path with drive letter */
+ /* has drive letter */
+ if (IsPathSep(pInName[2])) {
+ /* absolute with drive letter */
+ DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
+ }
+ else {
+ /* relative path with drive letter */
driveIndex = DriveIndex(*pInName);
if (driveIndex < 0 || driveIndex >= driveLetterCount)
return (WCHAR *)pInName;
- wcscpy(szBuffer, GetDirW(driveIndex));
- wcscat(szBuffer, &pInName[2]);
- if(wcslen(szBuffer) > MAX_PATH)
- szBuffer[MAX_PATH] = '\0';
+ wcscpy(szBuffer, GetDirW(driveIndex));
+ wcscat(szBuffer, &pInName[2]);
+ if(wcslen(szBuffer) > MAX_PATH)
+ szBuffer[MAX_PATH] = '\0';
- DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
- }
+ DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
+ }
}
else {
- /* no drive letter */
- if (length > 1 && IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
- /* UNC name */
- DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
- }
- else {
- wcscpy(szBuffer, GetDefaultDirW());
- if (IsPathSep(pInName[0])) {
- /* absolute path */
- wcscpy(&szBuffer[2], pInName);
- DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
- }
- else {
- /* relative path */
- if (IsSpecialFileName(pInName)) {
- return (WCHAR*)pInName;
- }
- else {
- wcscat(szBuffer, pInName);
- if (wcslen(szBuffer) > MAX_PATH)
- szBuffer[MAX_PATH] = '\0';
-
- DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
- }
- }
- }
+ /* no drive letter */
+ if (length > 1 && IsPathSep(pInName[1]) && IsPathSep(pInName[0])) {
+ /* UNC name */
+ DoGetFullPathNameW((WCHAR*)pInName, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
+ }
+ else {
+ wcscpy(szBuffer, GetDefaultDirW());
+ if (IsPathSep(pInName[0])) {
+ /* absolute path */
+ wcscpy(&szBuffer[2], pInName);
+ DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
+ }
+ else {
+ /* relative path */
+ if (IsSpecialFileName(pInName)) {
+ return (WCHAR*)pInName;
+ }
+ else {
+ wcscat(szBuffer, pInName);
+ if (wcslen(szBuffer) > MAX_PATH)
+ szBuffer[MAX_PATH] = '\0';
+
+ DoGetFullPathNameW(szBuffer, (sizeof(szLocalBufferW)/sizeof(WCHAR)), szLocalBufferW);
+ }
+ }
+ }
}
return szLocalBufferW;
}
@@ -696,17 +696,17 @@ int VDir::SetCurrentDirectoryW(WCHAR *lpBuffer)
pPtr = MapPathW(lpBuffer);
length = wcslen(pPtr);
if(length > 3 && IsPathSep(pPtr[length-1])) {
- /* don't remove the trailing slash from 'x:\' */
- pPtr[length-1] = '\0';
+ /* don't remove the trailing slash from 'x:\' */
+ pPtr[length-1] = '\0';
}
DWORD r = GetFileAttributesW(pPtr);
if ((r != 0xffffffff) && (r & FILE_ATTRIBUTE_DIRECTORY))
{
- WCHAR wBuffer[(MAX_PATH+1)*2];
- DoGetFullPathNameW(pPtr, (sizeof(wBuffer)/sizeof(WCHAR)), wBuffer);
- SetDefaultDirW(wBuffer, DriveIndex((char)wBuffer[0]));
- nRet = 0;
+ WCHAR wBuffer[(MAX_PATH+1)*2];
+ DoGetFullPathNameW(pPtr, (sizeof(wBuffer)/sizeof(WCHAR)), wBuffer);
+ SetDefaultDirW(wBuffer, DriveIndex((char)wBuffer[0]));
+ nRet = 0;
}
return nRet;
diff --git a/win32/vmem.h b/win32/vmem.h
index 3fd7e169fc..bd765f68e2 100644
--- a/win32/vmem.h
+++ b/win32/vmem.h
@@ -93,26 +93,26 @@ public:
inline BOOL CreateOk(void)
{
- return TRUE;
+ return TRUE;
};
protected:
#ifdef _USE_LINKED_LIST
void LinkBlock(PMEMORY_BLOCK_HEADER ptr)
{
- PMEMORY_BLOCK_HEADER next = m_Dummy.pNext;
- m_Dummy.pNext = ptr;
- ptr->pPrev = &m_Dummy;
- ptr->pNext = next;
+ PMEMORY_BLOCK_HEADER next = m_Dummy.pNext;
+ m_Dummy.pNext = ptr;
+ ptr->pPrev = &m_Dummy;
+ ptr->pNext = next;
ptr->owner = this;
- next->pPrev = ptr;
+ next->pPrev = ptr;
}
void UnlinkBlock(PMEMORY_BLOCK_HEADER ptr)
{
- PMEMORY_BLOCK_HEADER next = ptr->pNext;
- PMEMORY_BLOCK_HEADER prev = ptr->pPrev;
- prev->pNext = next;
- next->pPrev = prev;
+ PMEMORY_BLOCK_HEADER next = ptr->pNext;
+ PMEMORY_BLOCK_HEADER prev = ptr->pPrev;
+ prev->pNext = next;
+ next->pPrev = prev;
}
MEMORY_BLOCK_HEADER m_Dummy;
@@ -136,7 +136,7 @@ VMem::~VMem(void)
{
#ifdef _USE_LINKED_LIST
while (m_Dummy.pNext != &m_Dummy) {
- Free(m_Dummy.pNext+1);
+ Free(m_Dummy.pNext+1);
}
DeleteCriticalSection(&m_cs);
#endif
@@ -148,8 +148,8 @@ void* VMem::Malloc(size_t size)
GetLock();
PMEMORY_BLOCK_HEADER ptr = (PMEMORY_BLOCK_HEADER)malloc(size+sizeof(MEMORY_BLOCK_HEADER));
if (!ptr) {
- FreeLock();
- return NULL;
+ FreeLock();
+ return NULL;
}
LinkBlock(ptr);
FreeLock();
@@ -163,11 +163,11 @@ void* VMem::Realloc(void* pMem, size_t size)
{
#ifdef _USE_LINKED_LIST
if (!pMem)
- return Malloc(size);
+ return Malloc(size);
if (!size) {
- Free(pMem);
- return NULL;
+ Free(pMem);
+ return NULL;
}
GetLock();
@@ -175,8 +175,8 @@ void* VMem::Realloc(void* pMem, size_t size)
UnlinkBlock(ptr);
ptr = (PMEMORY_BLOCK_HEADER)realloc(ptr, size+sizeof(MEMORY_BLOCK_HEADER));
if (!ptr) {
- FreeLock();
- return NULL;
+ FreeLock();
+ return NULL;
}
LinkBlock(ptr);
FreeLock();
@@ -191,25 +191,25 @@ void VMem::Free(void* pMem)
{
#ifdef _USE_LINKED_LIST
if (pMem) {
- PMEMORY_BLOCK_HEADER ptr = (PMEMORY_BLOCK_HEADER)(((char*)pMem)-sizeof(MEMORY_BLOCK_HEADER));
+ PMEMORY_BLOCK_HEADER ptr = (PMEMORY_BLOCK_HEADER)(((char*)pMem)-sizeof(MEMORY_BLOCK_HEADER));
if (ptr->owner != this) {
- if (ptr->owner) {
+ if (ptr->owner) {
#if 1
- int *nowhere = NULL;
- Perl_warn_nocontext("Free to wrong pool %p not %p",this,ptr->owner);
- *nowhere = 0; /* this segfault is deliberate,
- so you can see the stack trace */
+ int *nowhere = NULL;
+ Perl_warn_nocontext("Free to wrong pool %p not %p",this,ptr->owner);
+ *nowhere = 0; /* this segfault is deliberate,
+ so you can see the stack trace */
#else
ptr->owner->Free(pMem);
#endif
- }
- return;
+ }
+ return;
}
- GetLock();
- UnlinkBlock(ptr);
- ptr->owner = NULL;
- free(ptr);
- FreeLock();
+ GetLock();
+ UnlinkBlock(ptr);
+ ptr->owner = NULL;
+ free(ptr);
+ FreeLock();
}
#else /*_USE_LINKED_LIST*/
free(pMem);
@@ -238,7 +238,7 @@ int VMem::IsLocked(void)
* skirt the issue for now. */
BOOL bAccessed = TryEnterCriticalSection(&m_cs);
if(bAccessed) {
- LeaveCriticalSection(&m_cs);
+ LeaveCriticalSection(&m_cs);
}
return !bAccessed;
#else
@@ -251,7 +251,7 @@ long VMem::Release(void)
{
long lCount = InterlockedDecrement(&m_lRefCount);
if(!lCount)
- delete this;
+ delete this;
return lCount;
}
@@ -411,9 +411,9 @@ public:
inline BOOL CreateOk(void)
{
#ifdef _USE_BUDDY_BLOCKS
- return TRUE;
+ return TRUE;
#else
- return m_hHeap != NULL;
+ return m_hHeap != NULL;
#endif
};
@@ -425,7 +425,7 @@ protected:
int HeapAdd(void* ptr, size_t size
#ifdef USE_BIGBLOCK_ALLOC
- , BOOL bBigBlock
+ , BOOL bBigBlock
#endif
);
@@ -434,35 +434,35 @@ protected:
#ifdef _USE_BUDDY_BLOCKS
inline PBLOCK GetFreeListLink(int index)
{
- if (index >= nListEntries)
- index = nListEntries-1;
- return &m_FreeList[index].Dummy[sizeofTag];
+ if (index >= nListEntries)
+ index = nListEntries-1;
+ return &m_FreeList[index].Dummy[sizeofTag];
}
inline PBLOCK GetOverSizeFreeList(void)
{
- return &m_FreeList[nListEntries-1].Dummy[sizeofTag];
+ return &m_FreeList[nListEntries-1].Dummy[sizeofTag];
}
inline PBLOCK GetEOLFreeList(void)
{
- return &m_FreeList[nListEntries].Dummy[sizeofTag];
+ return &m_FreeList[nListEntries].Dummy[sizeofTag];
}
void AddToFreeList(PBLOCK block, size_t size)
{
- PBLOCK pFreeList = GetFreeListLink(CalcEntry(size));
- PBLOCK next = NEXT(pFreeList);
- NEXT(pFreeList) = block;
- SetLink(block, pFreeList, next);
- PREV(next) = block;
+ PBLOCK pFreeList = GetFreeListLink(CalcEntry(size));
+ PBLOCK next = NEXT(pFreeList);
+ NEXT(pFreeList) = block;
+ SetLink(block, pFreeList, next);
+ PREV(next) = block;
}
#endif
inline size_t CalcAllocSize(size_t size)
{
- /*
- * Adjust the real size of the block to be a multiple of sizeof(long), and add
- * the overhead for the boundary tags. Disallow negative or zero sizes.
- */
- return (size < minBlockSize) ? minAllocSize : (size_t)ROUND_UP(size) + blockOverhead;
+ /*
+ * Adjust the real size of the block to be a multiple of sizeof(long), and add
+ * the overhead for the boundary tags. Disallow negative or zero sizes.
+ */
+ return (size < minBlockSize) ? minAllocSize : (size_t)ROUND_UP(size) + blockOverhead;
}
#ifdef _USE_BUDDY_BLOCKS
@@ -491,8 +491,8 @@ VMem::VMem()
m_lRefCount = 1;
#ifndef _USE_BUDDY_BLOCKS
BOOL bRet = (NULL != (m_hHeap = HeapCreate(HEAP_NO_SERIALIZE,
- lAllocStart, /* initial size of heap */
- 0))); /* no upper limit on size of heap */
+ lAllocStart, /* initial size of heap */
+ 0))); /* no upper limit on size of heap */
ASSERT(bRet);
#endif
@@ -514,14 +514,14 @@ VMem::~VMem(void)
DeleteCriticalSection(&m_cs);
#ifdef _USE_BUDDY_BLOCKS
for(int index = 0; index < m_nHeaps; ++index) {
- VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
+ VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
}
#else /* !_USE_BUDDY_BLOCKS */
#ifdef USE_BIGBLOCK_ALLOC
for(int index = 0; index < m_nHeaps; ++index) {
- if (m_heaps[index].bBigBlock) {
- VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
- }
+ if (m_heaps[index].bBigBlock) {
+ VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
+ }
}
#endif
BOOL bRet = HeapDestroy(m_hHeap);
@@ -533,15 +533,15 @@ void VMem::ReInit(void)
{
for(int index = 0; index < m_nHeaps; ++index) {
#ifdef _USE_BUDDY_BLOCKS
- VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
+ VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
#else
#ifdef USE_BIGBLOCK_ALLOC
- if (m_heaps[index].bBigBlock) {
- VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
- }
- else
+ if (m_heaps[index].bBigBlock) {
+ VirtualFree(m_heaps[index].base, 0, MEM_RELEASE);
+ }
+ else
#endif
- HeapFree(m_hHeap, HEAP_NO_SERIALIZE, m_heaps[index].base);
+ HeapFree(m_hHeap, HEAP_NO_SERIALIZE, m_heaps[index].base);
#endif /* _USE_BUDDY_BLOCKS */
}
@@ -559,9 +559,9 @@ void VMem::Init(void)
* Set the next allocation size.
*/
for (int index = 0; index < nListEntries; ++index) {
- pFreeList = GetFreeListLink(index);
- SIZE(pFreeList) = PSIZE(pFreeList+minAllocSize) = 0;
- PREV(pFreeList) = NEXT(pFreeList) = pFreeList;
+ pFreeList = GetFreeListLink(index);
+ SIZE(pFreeList) = PSIZE(pFreeList+minAllocSize) = 0;
+ PREV(pFreeList) = NEXT(pFreeList) = pFreeList;
}
pFreeList = GetEOLFreeList();
SIZE(pFreeList) = PSIZE(pFreeList+minAllocSize) = 0;
@@ -592,7 +592,7 @@ void* VMem::Malloc(size_t size)
*/
size_t realsize = CalcAllocSize(size);
if((int)realsize < minAllocSize || size == 0)
- return NULL;
+ return NULL;
#ifdef _USE_BUDDY_BLOCKS
/*
@@ -602,78 +602,78 @@ void* VMem::Malloc(size_t size)
* split the block if needed, stop at end of list marker
*/
{
- int index = CalcEntry(realsize);
- if (index < nListEntries-1) {
- ptr = GetFreeListLink(index);
- lsize = SIZE(ptr);
- if (lsize >= realsize) {
- rem = lsize - realsize;
- if(rem < minAllocSize) {
- /* Unlink the block from the free list. */
- Unlink(ptr);
- }
- else {
- /*
- * split the block
- * The remainder is big enough to split off into a new block.
- * Use the end of the block, resize the beginning of the block
- * no need to change the free list.
- */
- SetTags(ptr, rem);
- ptr += SIZE(ptr);
- lsize = realsize;
- }
- SetTags(ptr, lsize | 1);
- return ptr;
- }
- ptr = m_pRover;
- lsize = SIZE(ptr);
- if (lsize >= realsize) {
- rem = lsize - realsize;
- if(rem < minAllocSize) {
- /* Unlink the block from the free list. */
- Unlink(ptr);
- }
- else {
- /*
- * split the block
- * The remainder is big enough to split off into a new block.
- * Use the end of the block, resize the beginning of the block
- * no need to change the free list.
- */
- SetTags(ptr, rem);
- ptr += SIZE(ptr);
- lsize = realsize;
- }
- SetTags(ptr, lsize | 1);
- return ptr;
- }
- ptr = GetFreeListLink(index+1);
- while (NEXT(ptr)) {
- lsize = SIZE(ptr);
- if (lsize >= realsize) {
- size_t rem = lsize - realsize;
- if(rem < minAllocSize) {
- /* Unlink the block from the free list. */
- Unlink(ptr);
- }
- else {
- /*
- * split the block
- * The remainder is big enough to split off into a new block.
- * Use the end of the block, resize the beginning of the block
- * no need to change the free list.
- */
- SetTags(ptr, rem);
- ptr += SIZE(ptr);
- lsize = realsize;
- }
- SetTags(ptr, lsize | 1);
- return ptr;
- }
- ptr += sizeof(FREE_LIST_ENTRY);
- }
- }
+ int index = CalcEntry(realsize);
+ if (index < nListEntries-1) {
+ ptr = GetFreeListLink(index);
+ lsize = SIZE(ptr);
+ if (lsize >= realsize) {
+ rem = lsize - realsize;
+ if(rem < minAllocSize) {
+ /* Unlink the block from the free list. */
+ Unlink(ptr);
+ }
+ else {
+ /*
+ * split the block
+ * The remainder is big enough to split off into a new block.
+ * Use the end of the block, resize the beginning of the block
+ * no need to change the free list.
+ */
+ SetTags(ptr, rem);
+ ptr += SIZE(ptr);
+ lsize = realsize;
+ }
+ SetTags(ptr, lsize | 1);
+ return ptr;
+ }
+ ptr = m_pRover;
+ lsize = SIZE(ptr);
+ if (lsize >= realsize) {
+ rem = lsize - realsize;
+ if(rem < minAllocSize) {
+ /* Unlink the block from the free list. */
+ Unlink(ptr);
+ }
+ else {
+ /*
+ * split the block
+ * The remainder is big enough to split off into a new block.
+ * Use the end of the block, resize the beginning of the block
+ * no need to change the free list.
+ */
+ SetTags(ptr, rem);
+ ptr += SIZE(ptr);
+ lsize = realsize;
+ }
+ SetTags(ptr, lsize | 1);
+ return ptr;
+ }
+ ptr = GetFreeListLink(index+1);
+ while (NEXT(ptr)) {
+ lsize = SIZE(ptr);
+ if (lsize >= realsize) {
+ size_t rem = lsize - realsize;
+ if(rem < minAllocSize) {
+ /* Unlink the block from the free list. */
+ Unlink(ptr);
+ }
+ else {
+ /*
+ * split the block
+ * The remainder is big enough to split off into a new block.
+ * Use the end of the block, resize the beginning of the block
+ * no need to change the free list.
+ */
+ SetTags(ptr, rem);
+ ptr += SIZE(ptr);
+ lsize = realsize;
+ }
+ SetTags(ptr, lsize | 1);
+ return ptr;
+ }
+ ptr += sizeof(FREE_LIST_ENTRY);
+ }
+ }
}
#endif
@@ -684,46 +684,46 @@ void* VMem::Malloc(size_t size)
ptr = m_pRover; /* start searching at rover */
int loops = 2; /* allow two times through the loop */
for(;;) {
- lsize = SIZE(ptr);
- ASSERT((lsize&1)==0);
- /* is block big enough? */
- if(lsize >= realsize) {
- /* if the remainder is too small, don't bother splitting the block. */
- rem = lsize - realsize;
- if(rem < minAllocSize) {
- if(m_pRover == ptr)
- m_pRover = NEXT(ptr);
-
- /* Unlink the block from the free list. */
- Unlink(ptr);
- }
- else {
- /*
- * split the block
- * The remainder is big enough to split off into a new block.
- * Use the end of the block, resize the beginning of the block
- * no need to change the free list.
- */
- SetTags(ptr, rem);
- ptr += SIZE(ptr);
- lsize = realsize;
- }
- /* Set the boundary tags to mark it as allocated. */
- SetTags(ptr, lsize | 1);
- return ((void *)ptr);
- }
-
- /*
- * This block was unsuitable. If we've gone through this list once already without
- * finding anything, allocate some new memory from the heap and try again.
- */
- ptr = NEXT(ptr);
- if(ptr == m_pRover) {
- if(!(loops-- && Getmem(realsize))) {
- return NULL;
- }
- ptr = m_pRover;
- }
+ lsize = SIZE(ptr);
+ ASSERT((lsize&1)==0);
+ /* is block big enough? */
+ if(lsize >= realsize) {
+ /* if the remainder is too small, don't bother splitting the block. */
+ rem = lsize - realsize;
+ if(rem < minAllocSize) {
+ if(m_pRover == ptr)
+ m_pRover = NEXT(ptr);
+
+ /* Unlink the block from the free list. */
+ Unlink(ptr);
+ }
+ else {
+ /*
+ * split the block
+ * The remainder is big enough to split off into a new block.
+ * Use the end of the block, resize the beginning of the block
+ * no need to change the free list.
+ */
+ SetTags(ptr, rem);
+ ptr += SIZE(ptr);
+ lsize = realsize;
+ }
+ /* Set the boundary tags to mark it as allocated. */
+ SetTags(ptr, lsize | 1);
+ return ((void *)ptr);
+ }
+
+ /*
+ * This block was unsuitable. If we've gone through this list once already without
+ * finding anything, allocate some new memory from the heap and try again.
+ */
+ ptr = NEXT(ptr);
+ if(ptr == m_pRover) {
+ if(!(loops-- && Getmem(realsize))) {
+ return NULL;
+ }
+ ptr = m_pRover;
+ }
}
}
@@ -733,24 +733,24 @@ void* VMem::Realloc(void* block, size_t size)
/* if size is zero, free the block. */
if(size == 0) {
- Free(block);
- return (NULL);
+ Free(block);
+ return (NULL);
}
/* if block pointer is NULL, do a Malloc(). */
if(block == NULL)
- return Malloc(size);
+ return Malloc(size);
/*
* Grow or shrink the block in place.
* if the block grows then the next block will be used if free
*/
if(Expand(block, size) != NULL)
- return block;
+ return block;
size_t realsize = CalcAllocSize(size);
if((int)realsize < minAllocSize)
- return NULL;
+ return NULL;
/*
* see if the previous block is free, and is it big enough to cover the new size
@@ -760,46 +760,46 @@ void* VMem::Realloc(void* block, size_t size)
size_t cursize = SIZE(ptr) & ~1;
size_t psize = PSIZE(ptr);
if((psize&1) == 0 && (psize + cursize) >= realsize) {
- PBLOCK prev = ptr - psize;
- if(m_pRover == prev)
- m_pRover = NEXT(prev);
-
- /* Unlink the next block from the free list. */
- Unlink(prev);
-
- /* Copy contents of old block to new location, make it the current block. */
- memmove(prev, ptr, cursize);
- cursize += psize; /* combine sizes */
- ptr = prev;
-
- size_t rem = cursize - realsize;
- if(rem >= minAllocSize) {
- /*
- * The remainder is big enough to be a new block. Set boundary
- * tags for the resized block and the new block.
- */
- prev = ptr + realsize;
- /*
- * add the new block to the free list.
- * next block cannot be free
- */
- SetTags(prev, rem);
+ PBLOCK prev = ptr - psize;
+ if(m_pRover == prev)
+ m_pRover = NEXT(prev);
+
+ /* Unlink the next block from the free list. */
+ Unlink(prev);
+
+ /* Copy contents of old block to new location, make it the current block. */
+ memmove(prev, ptr, cursize);
+ cursize += psize; /* combine sizes */
+ ptr = prev;
+
+ size_t rem = cursize - realsize;
+ if(rem >= minAllocSize) {
+ /*
+ * The remainder is big enough to be a new block. Set boundary
+ * tags for the resized block and the new block.
+ */
+ prev = ptr + realsize;
+ /*
+ * add the new block to the free list.
+ * next block cannot be free
+ */
+ SetTags(prev, rem);
#ifdef _USE_BUDDY_BLOCKS
- AddToFreeList(prev, rem);
+ AddToFreeList(prev, rem);
#else
- AddToFreeList(prev, m_pFreeList);
+ AddToFreeList(prev, m_pFreeList);
#endif
- cursize = realsize;
+ cursize = realsize;
}
- /* Set the boundary tags to mark it as allocated. */
- SetTags(ptr, cursize | 1);
+ /* Set the boundary tags to mark it as allocated. */
+ SetTags(ptr, cursize | 1);
return ((void *)ptr);
}
/* Allocate a new block, copy the old to the new, and free the old. */
if((ptr = (PBLOCK)Malloc(size)) != NULL) {
- memmove(ptr, block, cursize-blockOverhead);
- Free(block);
+ memmove(ptr, block, cursize-blockOverhead);
+ Free(block);
}
return ((void *)ptr);
}
@@ -810,15 +810,15 @@ void VMem::Free(void* p)
/* Ignore null pointer. */
if(p == NULL)
- return;
+ return;
PBLOCK ptr = (PBLOCK)p;
/* Check for attempt to free a block that's already free. */
size_t size = SIZE(ptr);
if((size&1) == 0) {
- MEMODSlx("Attempt to free previously freed block", (long)p);
- return;
+ MEMODSlx("Attempt to free previously freed block", (long)p);
+ return;
}
size &= ~1; /* remove allocated tag */
@@ -828,12 +828,12 @@ void VMem::Free(void* p)
#endif
size_t psize = PSIZE(ptr);
if((psize&1) == 0) {
- ptr -= psize; /* point to previous block */
- size += psize; /* merge the sizes of the two blocks */
+ ptr -= psize; /* point to previous block */
+ size += psize; /* merge the sizes of the two blocks */
#ifdef _USE_BUDDY_BLOCKS
- Unlink(ptr);
+ Unlink(ptr);
#else
- linked = TRUE; /* it's already on the free list */
+ linked = TRUE; /* it's already on the free list */
#endif
}
@@ -841,15 +841,15 @@ void VMem::Free(void* p)
PBLOCK next = ptr + size; /* point to next physical block */
size_t nsize = SIZE(next);
if((nsize&1) == 0) {
- /* block is free move rover if needed */
- if(m_pRover == next)
- m_pRover = NEXT(next);
+ /* block is free move rover if needed */
+ if(m_pRover == next)
+ m_pRover = NEXT(next);
- /* unlink the next block from the free list. */
- Unlink(next);
+ /* unlink the next block from the free list. */
+ Unlink(next);
- /* merge the sizes of this block and the next block. */
- size += nsize;
+ /* merge the sizes of this block and the next block. */
+ size += nsize;
}
/* Set the boundary tags for the block; */
@@ -857,10 +857,10 @@ void VMem::Free(void* p)
/* Link the block to the head of the free list. */
#ifdef _USE_BUDDY_BLOCKS
- AddToFreeList(ptr, size);
+ AddToFreeList(ptr, size);
#else
if(!linked) {
- AddToFreeList(ptr, m_pFreeList);
+ AddToFreeList(ptr, m_pFreeList);
}
#endif
}
@@ -883,7 +883,7 @@ int VMem::IsLocked(void)
* skirt the issue for now. */
BOOL bAccessed = TryEnterCriticalSection(&m_cs);
if(bAccessed) {
- LeaveCriticalSection(&m_cs);
+ LeaveCriticalSection(&m_cs);
}
return !bAccessed;
#else
@@ -897,7 +897,7 @@ long VMem::Release(void)
{
long lCount = InterlockedDecrement(&m_lRefCount);
if(!lCount)
- delete this;
+ delete this;
return lCount;
}
@@ -923,30 +923,30 @@ int VMem::Getmem(size_t requestSize)
* adjust up
*/
if(size < (unsigned long)m_lAllocSize)
- size = m_lAllocSize;
+ size = m_lAllocSize;
/* Update the size to allocate on the next request */
if(m_lAllocSize != lAllocMax)
- m_lAllocSize <<= 2;
+ m_lAllocSize <<= 2;
#ifndef _USE_BUDDY_BLOCKS
if(m_nHeaps != 0
#ifdef USE_BIGBLOCK_ALLOC
- && !m_heaps[m_nHeaps-1].bBigBlock
+ && !m_heaps[m_nHeaps-1].bBigBlock
#endif
- ) {
- /* Expand the last allocated heap */
- ptr = HeapReAlloc(m_hHeap, HEAP_REALLOC_IN_PLACE_ONLY|HEAP_NO_SERIALIZE,
- m_heaps[m_nHeaps-1].base,
- m_heaps[m_nHeaps-1].len + size);
- if(ptr != 0) {
- HeapAdd(((char*)ptr) + m_heaps[m_nHeaps-1].len, size
+ ) {
+ /* Expand the last allocated heap */
+ ptr = HeapReAlloc(m_hHeap, HEAP_REALLOC_IN_PLACE_ONLY|HEAP_NO_SERIALIZE,
+ m_heaps[m_nHeaps-1].base,
+ m_heaps[m_nHeaps-1].len + size);
+ if(ptr != 0) {
+ HeapAdd(((char*)ptr) + m_heaps[m_nHeaps-1].len, size
#ifdef USE_BIGBLOCK_ALLOC
- , FALSE
+ , FALSE
#endif
- );
- return -1;
- }
+ );
+ return -1;
+ }
}
#endif /* _USE_BUDDY_BLOCKS */
@@ -957,7 +957,7 @@ int VMem::Getmem(size_t requestSize)
* the above ROUND_UP64K may not have added any memory to include this.
*/
if(size == requestSize)
- size = (size_t)ROUND_UP64K(requestSize+(blockOverhead));
+ size = (size_t)ROUND_UP64K(requestSize+(blockOverhead));
Restart:
#ifdef _USE_BUDDY_BLOCKS
@@ -966,8 +966,8 @@ Restart:
#ifdef USE_BIGBLOCK_ALLOC
bBigBlock = FALSE;
if (size >= nMaxHeapAllocSize) {
- bBigBlock = TRUE;
- ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
+ bBigBlock = TRUE;
+ ptr = VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
}
else
#endif
@@ -975,28 +975,28 @@ Restart:
#endif /* _USE_BUDDY_BLOCKS */
if (!ptr) {
- /* try to allocate a smaller chunk */
- size >>= 1;
- if(size > requestSize)
- goto Restart;
+ /* try to allocate a smaller chunk */
+ size >>= 1;
+ if(size > requestSize)
+ goto Restart;
}
if(ptr == 0) {
- MEMODSlx("HeapAlloc failed on size!!!", size);
- return 0;
+ MEMODSlx("HeapAlloc failed on size!!!", size);
+ return 0;
}
#ifdef _USE_BUDDY_BLOCKS
if (HeapAdd(ptr, size)) {
- VirtualFree(ptr, 0, MEM_RELEASE);
- return 0;
+ VirtualFree(ptr, 0, MEM_RELEASE);
+ return 0;
}
#else
#ifdef USE_BIGBLOCK_ALLOC
if (HeapAdd(ptr, size, bBigBlock)) {
- if (bBigBlock) {
- VirtualFree(ptr, 0, MEM_RELEASE);
- }
+ if (bBigBlock) {
+ VirtualFree(ptr, 0, MEM_RELEASE);
+ }
}
#else
HeapAdd(ptr, size);
@@ -1015,7 +1015,7 @@ int VMem::HeapAdd(void* p, size_t size
/* Check size, then round size down to next long word boundary. */
if(size < minAllocSize)
- return -1;
+ return -1;
size = (size_t)ROUND_DOWN(size);
PBLOCK ptr = (PBLOCK)p;
@@ -1023,47 +1023,47 @@ int VMem::HeapAdd(void* p, size_t size
#ifdef USE_BIGBLOCK_ALLOC
if (!bBigBlock) {
#endif
- /*
- * Search for another heap area that's contiguous with the bottom of this new area.
- * (It should be extremely unusual to find one that's contiguous with the top).
- */
- for(index = 0; index < m_nHeaps; ++index) {
- if(ptr == m_heaps[index].base + (int)m_heaps[index].len) {
- /*
- * The new block is contiguous with a previously allocated heap area. Add its
- * length to that of the previous heap. Merge it with the dummy end-of-heap
- * area marker of the previous heap.
- */
- m_heaps[index].len += size;
- break;
- }
- }
+ /*
+ * Search for another heap area that's contiguous with the bottom of this new area.
+ * (It should be extremely unusual to find one that's contiguous with the top).
+ */
+ for(index = 0; index < m_nHeaps; ++index) {
+ if(ptr == m_heaps[index].base + (int)m_heaps[index].len) {
+ /*
+ * The new block is contiguous with a previously allocated heap area. Add its
+ * length to that of the previous heap. Merge it with the dummy end-of-heap
+ * area marker of the previous heap.
+ */
+ m_heaps[index].len += size;
+ break;
+ }
+ }
#ifdef USE_BIGBLOCK_ALLOC
}
else {
- index = m_nHeaps;
+ index = m_nHeaps;
}
#endif
if(index == m_nHeaps) {
- /* The new block is not contiguous, or is BigBlock. Add it to the heap list. */
- if(m_nHeaps == maxHeaps) {
- return -1; /* too many non-contiguous heaps */
- }
- m_heaps[m_nHeaps].base = ptr;
- m_heaps[m_nHeaps].len = size;
+ /* The new block is not contiguous, or is BigBlock. Add it to the heap list. */
+ if(m_nHeaps == maxHeaps) {
+ return -1; /* too many non-contiguous heaps */
+ }
+ m_heaps[m_nHeaps].base = ptr;
+ m_heaps[m_nHeaps].len = size;
#ifdef USE_BIGBLOCK_ALLOC
- m_heaps[m_nHeaps].bBigBlock = bBigBlock;
+ m_heaps[m_nHeaps].bBigBlock = bBigBlock;
#endif
- m_nHeaps++;
-
- /*
- * Reserve the first LONG in the block for the ending boundary tag of a dummy
- * block at the start of the heap area.
- */
- size -= blockOverhead;
- ptr += blockOverhead;
- PSIZE(ptr) = 1; /* mark the dummy previous block as allocated */
+ m_nHeaps++;
+
+ /*
+ * Reserve the first LONG in the block for the ending boundary tag of a dummy
+ * block at the start of the heap area.
+ */
+ size -= blockOverhead;
+ ptr += blockOverhead;
+ PSIZE(ptr) = 1; /* mark the dummy previous block as allocated */
}
/*
@@ -1091,36 +1091,36 @@ void* VMem::Expand(void* block, size_t size)
*/
size_t realsize = CalcAllocSize(size);
if((int)realsize < minAllocSize || size == 0)
- return NULL;
+ return NULL;
PBLOCK ptr = (PBLOCK)block;
/* if the current size is the same as requested, do nothing. */
size_t cursize = SIZE(ptr) & ~1;
if(cursize == realsize) {
- return block;
+ return block;
}
/* if the block is being shrunk, convert the remainder of the block into a new free block. */
if(realsize <= cursize) {
- size_t nextsize = cursize - realsize; /* size of new remainder block */
- if(nextsize >= minAllocSize) {
- /*
- * Split the block
- * Set boundary tags for the resized block and the new block.
- */
- SetTags(ptr, realsize | 1);
- ptr += realsize;
-
- /*
- * add the new block to the free list.
- * call Free to merge this block with next block if free
- */
- SetTags(ptr, nextsize | 1);
- Free(ptr);
- }
-
- return block;
+ size_t nextsize = cursize - realsize; /* size of new remainder block */
+ if(nextsize >= minAllocSize) {
+ /*
+ * Split the block
+ * Set boundary tags for the resized block and the new block.
+ */
+ SetTags(ptr, realsize | 1);
+ ptr += realsize;
+
+ /*
+ * add the new block to the free list.
+ * call Free to merge this block with next block if free
+ */
+ SetTags(ptr, nextsize | 1);
+ Free(ptr);
+ }
+
+ return block;
}
PBLOCK next = ptr + cursize;
@@ -1128,39 +1128,39 @@ void* VMem::Expand(void* block, size_t size)
/* Check the next block for consistency.*/
if((nextsize&1) == 0 && (nextsize + cursize) >= realsize) {
- /*
- * The next block is free and big enough. Add the part that's needed
- * to our block, and split the remainder off into a new block.
- */
- if(m_pRover == next)
- m_pRover = NEXT(next);
-
- /* Unlink the next block from the free list. */
- Unlink(next);
- cursize += nextsize; /* combine sizes */
-
- size_t rem = cursize - realsize; /* size of remainder */
- if(rem >= minAllocSize) {
- /*
- * The remainder is big enough to be a new block.
- * Set boundary tags for the resized block and the new block.
- */
- next = ptr + realsize;
- /*
- * add the new block to the free list.
- * next block cannot be free
- */
- SetTags(next, rem);
+ /*
+ * The next block is free and big enough. Add the part that's needed
+ * to our block, and split the remainder off into a new block.
+ */
+ if(m_pRover == next)
+ m_pRover = NEXT(next);
+
+ /* Unlink the next block from the free list. */
+ Unlink(next);
+ cursize += nextsize; /* combine sizes */
+
+ size_t rem = cursize - realsize; /* size of remainder */
+ if(rem >= minAllocSize) {
+ /*
+ * The remainder is big enough to be a new block.
+ * Set boundary tags for the resized block and the new block.
+ */
+ next = ptr + realsize;
+ /*
+ * add the new block to the free list.
+ * next block cannot be free
+ */
+ SetTags(next, rem);
#ifdef _USE_BUDDY_BLOCKS
- AddToFreeList(next, rem);
+ AddToFreeList(next, rem);
#else
- AddToFreeList(next, m_pFreeList);
+ AddToFreeList(next, m_pFreeList);
#endif
- cursize = realsize;
+ cursize = realsize;
}
- /* Set the boundary tags to mark it as allocated. */
- SetTags(ptr, cursize | 1);
- return ((void *)ptr);
+ /* Set the boundary tags to mark it as allocated. */
+ SetTags(ptr, cursize | 1);
+ return ((void *)ptr);
}
return NULL;
}
@@ -1172,70 +1172,70 @@ void VMem::MemoryUsageMessage(char *str, long x, long y, int c)
{
char szBuffer[512];
if(str) {
- if(!m_pLog)
- m_pLog = fopen(LOG_FILENAME, "w");
- sprintf(szBuffer, str, x, y, c);
- fputs(szBuffer, m_pLog);
+ if(!m_pLog)
+ m_pLog = fopen(LOG_FILENAME, "w");
+ sprintf(szBuffer, str, x, y, c);
+ fputs(szBuffer, m_pLog);
}
else {
- if(m_pLog) {
- fflush(m_pLog);
- fclose(m_pLog);
- m_pLog = 0;
- }
+ if(m_pLog) {
+ fflush(m_pLog);
+ fclose(m_pLog);
+ m_pLog = 0;
+ }
}
}
void VMem::WalkHeap(int complete)
{
if(complete) {
- MemoryUsageMessage(NULL, 0, 0, 0);
- size_t total = 0;
- for(int i = 0; i < m_nHeaps; ++i) {
- total += m_heaps[i].len;
- }
- MemoryUsageMessage("VMem heaps used %d. Total memory %08x\n", m_nHeaps, total, 0);
-
- /* Walk all the heaps - verify structures */
- for(int index = 0; index < m_nHeaps; ++index) {
- PBLOCK ptr = m_heaps[index].base;
- size_t size = m_heaps[index].len;
+ MemoryUsageMessage(NULL, 0, 0, 0);
+ size_t total = 0;
+ for(int i = 0; i < m_nHeaps; ++i) {
+ total += m_heaps[i].len;
+ }
+ MemoryUsageMessage("VMem heaps used %d. Total memory %08x\n", m_nHeaps, total, 0);
+
+ /* Walk all the heaps - verify structures */
+ for(int index = 0; index < m_nHeaps; ++index) {
+ PBLOCK ptr = m_heaps[index].base;
+ size_t size = m_heaps[index].len;
#ifndef _USE_BUDDY_BLOCKS
#ifdef USE_BIGBLOCK_ALLOC
- if (!m_heaps[m_nHeaps].bBigBlock)
+ if (!m_heaps[m_nHeaps].bBigBlock)
#endif
- ASSERT(HeapValidate(m_hHeap, HEAP_NO_SERIALIZE, ptr));
+ ASSERT(HeapValidate(m_hHeap, HEAP_NO_SERIALIZE, ptr));
#endif
- /* set over reserved header block */
- size -= blockOverhead;
- ptr += blockOverhead;
- PBLOCK pLast = ptr + size;
- ASSERT(PSIZE(ptr) == 1); /* dummy previous block is allocated */
- ASSERT(SIZE(pLast) == 1); /* dummy next block is allocated */
- while(ptr < pLast) {
- ASSERT(ptr > m_heaps[index].base);
- size_t cursize = SIZE(ptr) & ~1;
- ASSERT((PSIZE(ptr+cursize) & ~1) == cursize);
- MemoryUsageMessage("Memory Block %08x: Size %08x %c\n", (long)ptr, cursize, (SIZE(ptr)&1) ? 'x' : ' ');
- if(!(SIZE(ptr)&1)) {
- /* this block is on the free list */
- PBLOCK tmp = NEXT(ptr);
- while(tmp != ptr) {
- ASSERT((SIZE(tmp)&1)==0);
- if(tmp == m_pFreeList)
- break;
- ASSERT(NEXT(tmp));
- tmp = NEXT(tmp);
- }
- if(tmp == ptr) {
- MemoryUsageMessage("Memory Block %08x: Size %08x free but not in free list\n", (long)ptr, cursize, 0);
- }
- }
- ptr += cursize;
- }
- }
- MemoryUsageMessage(NULL, 0, 0, 0);
+ /* set over reserved header block */
+ size -= blockOverhead;
+ ptr += blockOverhead;
+ PBLOCK pLast = ptr + size;
+ ASSERT(PSIZE(ptr) == 1); /* dummy previous block is allocated */
+ ASSERT(SIZE(pLast) == 1); /* dummy next block is allocated */
+ while(ptr < pLast) {
+ ASSERT(ptr > m_heaps[index].base);
+ size_t cursize = SIZE(ptr) & ~1;
+ ASSERT((PSIZE(ptr+cursize) & ~1) == cursize);
+ MemoryUsageMessage("Memory Block %08x: Size %08x %c\n", (long)ptr, cursize, (SIZE(ptr)&1) ? 'x' : ' ');
+ if(!(SIZE(ptr)&1)) {
+ /* this block is on the free list */
+ PBLOCK tmp = NEXT(ptr);
+ while(tmp != ptr) {
+ ASSERT((SIZE(tmp)&1)==0);
+ if(tmp == m_pFreeList)
+ break;
+ ASSERT(NEXT(tmp));
+ tmp = NEXT(tmp);
+ }
+ if(tmp == ptr) {
+ MemoryUsageMessage("Memory Block %08x: Size %08x free but not in free list\n", (long)ptr, cursize, 0);
+ }
+ }
+ ptr += cursize;
+ }
+ }
+ MemoryUsageMessage(NULL, 0, 0, 0);
}
}
#endif /* _DEBUG_MEM */
diff --git a/win32/win32.c b/win32/win32.c
index 9f0259a807..cdd5685c41 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -110,8 +110,8 @@ END_EXTERN_C
#ifdef SET_INVALID_PARAMETER_HANDLER
static BOOL set_silent_invalid_parameter_handler(BOOL newvalue);
static void my_invalid_parameter_handler(const wchar_t* expression,
- const wchar_t* function, const wchar_t* file,
- unsigned int line, uintptr_t pReserved);
+ const wchar_t* function, const wchar_t* file,
+ unsigned int line, uintptr_t pReserved);
#endif
#ifndef WIN32_NO_REGISTRY
@@ -120,10 +120,10 @@ static char* get_regstr(const char *valuename, SV **svp);
#endif
static char* get_emd_part(SV **prev_pathp, STRLEN *const len,
- char *trailing, ...);
+ char *trailing, ...);
static char* win32_get_xlib(const char *pl,
- WIN32_NO_REGISTRY_M_(const char *xlib)
- const char *libname, STRLEN *const len);
+ WIN32_NO_REGISTRY_M_(const char *xlib)
+ const char *libname, STRLEN *const len);
static BOOL has_shell_metachars(const char *ptr);
static long tokenize(const char *str, char **dest, char ***destv);
@@ -135,7 +135,7 @@ static int do_spawn2_handles(pTHX_ const char *cmd, int exectype,
static int do_spawnvp_handles(int mode, const char *cmdname,
const char * const *argv, const int *handles);
static PerlIO * do_popen(const char *mode, const char *command, IV narg,
- SV **args);
+ SV **args);
static long find_pid(pTHX_ int pid);
static void remove_dead_process(long child);
static int terminate_process(DWORD pid, HANDLE process_handle, int sig);
@@ -146,11 +146,11 @@ static char* wstr_to_str(const wchar_t* wstr);
static long filetime_to_clock(PFILETIME ft);
static BOOL filetime_from_time(PFILETIME ft, time_t t);
static char* create_command_line(char *cname, STRLEN clen,
- const char * const *args);
+ const char * const *args);
static char* qualified_path(const char *cmd, bool other_exts);
static void ansify_path(void);
static LRESULT win32_process_message(HWND hwnd, UINT msg,
- WPARAM wParam, LPARAM lParam);
+ WPARAM wParam, LPARAM lParam);
#ifdef USE_ITHREADS
static long find_pseudo_pid(pTHX_ int pid);
@@ -221,7 +221,7 @@ my_invalid_parameter_handler(const wchar_t* expression,
char* ansi_function;
char* ansi_file;
if (silent_invalid_parameter_handler)
- return;
+ return;
ansi_expression = wstr_to_str(expression);
ansi_function = wstr_to_str(function);
ansi_file = wstr_to_str(file);
@@ -277,9 +277,9 @@ set_w32_module_name(void)
/* normalize to forward slashes */
ptr = w32_module_name;
while (*ptr) {
- if (*ptr == '\\')
- *ptr = '/';
- ++ptr;
+ if (*ptr == '\\')
+ *ptr = '/';
+ ++ptr;
}
}
@@ -296,18 +296,18 @@ get_regstr_from(HKEY handle, const char *valuename, SV **svp)
retval = RegQueryValueEx(handle, valuename, 0, &type, NULL, &datalen);
if (retval == ERROR_SUCCESS
- && (type == REG_SZ || type == REG_EXPAND_SZ))
+ && (type == REG_SZ || type == REG_EXPAND_SZ))
{
- dTHX;
- if (!*svp)
- *svp = sv_2mortal(newSVpvs(""));
- SvGROW(*svp, datalen);
- retval = RegQueryValueEx(handle, valuename, 0, NULL,
- (PBYTE)SvPVX(*svp), &datalen);
- if (retval == ERROR_SUCCESS) {
- str = SvPVX(*svp);
- SvCUR_set(*svp,datalen-1);
- }
+ dTHX;
+ if (!*svp)
+ *svp = sv_2mortal(newSVpvs(""));
+ SvGROW(*svp, datalen);
+ retval = RegQueryValueEx(handle, valuename, 0, NULL,
+ (PBYTE)SvPVX(*svp), &datalen);
+ if (retval == ERROR_SUCCESS) {
+ str = SvPVX(*svp);
+ SvCUR_set(*svp,datalen-1);
+ }
}
return str;
}
@@ -318,16 +318,16 @@ get_regstr(const char *valuename, SV **svp)
{
char *str;
if (HKCU_Perl_hnd) {
- str = get_regstr_from(HKCU_Perl_hnd, valuename, svp);
- if (!str)
- goto try_HKLM;
+ str = get_regstr_from(HKCU_Perl_hnd, valuename, svp);
+ if (!str)
+ goto try_HKLM;
}
else {
- try_HKLM:
- if (HKLM_Perl_hnd)
- str = get_regstr_from(HKLM_Perl_hnd, valuename, svp);
- else
- str = NULL;
+ try_HKLM:
+ if (HKLM_Perl_hnd)
+ str = get_regstr_from(HKLM_Perl_hnd, valuename, svp);
+ else
+ str = NULL;
}
return str;
}
@@ -352,49 +352,49 @@ get_emd_part(SV **prev_pathp, STRLEN *const len, char *trailing_path, ...)
baselen = strlen(base);
if (!*w32_module_name) {
- set_w32_module_name();
+ set_w32_module_name();
}
strcpy(mod_name, w32_module_name);
ptr = strrchr(mod_name, '/');
while (ptr && strip) {
/* look for directories to skip back */
- optr = ptr;
- *ptr = '\0';
- ptr = strrchr(mod_name, '/');
- /* avoid stripping component if there is no slash,
- * or it doesn't match ... */
- if (!ptr || stricmp(ptr+1, strip) != 0) {
- /* ... but not if component matches m|5\.$patchlevel.*| */
- if (!ptr || !(*strip == '5' && *(ptr+1) == '5'
- && strnEQ(strip, base, baselen)
- && strnEQ(ptr+1, base, baselen)))
- {
- *optr = '/';
- ptr = optr;
- }
- }
- strip = va_arg(ap, char *);
+ optr = ptr;
+ *ptr = '\0';
+ ptr = strrchr(mod_name, '/');
+ /* avoid stripping component if there is no slash,
+ * or it doesn't match ... */
+ if (!ptr || stricmp(ptr+1, strip) != 0) {
+ /* ... but not if component matches m|5\.$patchlevel.*| */
+ if (!ptr || !(*strip == '5' && *(ptr+1) == '5'
+ && strnEQ(strip, base, baselen)
+ && strnEQ(ptr+1, base, baselen)))
+ {
+ *optr = '/';
+ ptr = optr;
+ }
+ }
+ strip = va_arg(ap, char *);
}
if (!ptr) {
- ptr = mod_name;
- *ptr++ = '.';
- *ptr = '/';
+ ptr = mod_name;
+ *ptr++ = '.';
+ *ptr = '/';
}
va_end(ap);
strcpy(++ptr, trailing_path);
/* only add directory if it exists */
if (GetFileAttributes(mod_name) != (DWORD) -1) {
- /* directory exists */
- dTHX;
- if (!*prev_pathp)
- *prev_pathp = sv_2mortal(newSVpvs(""));
- else if (SvPVX(*prev_pathp))
- sv_catpvs(*prev_pathp, ";");
- sv_catpv(*prev_pathp, mod_name);
- if(len)
- *len = SvCUR(*prev_pathp);
- return SvPVX(*prev_pathp);
+ /* directory exists */
+ dTHX;
+ if (!*prev_pathp)
+ *prev_pathp = sv_2mortal(newSVpvs(""));
+ else if (SvPVX(*prev_pathp))
+ sv_catpvs(*prev_pathp, ";");
+ sv_catpv(*prev_pathp, mod_name);
+ if(len)
+ *len = SvCUR(*prev_pathp);
+ return SvPVX(*prev_pathp);
}
return NULL;
@@ -411,7 +411,7 @@ win32_get_privlib(WIN32_NO_REGISTRY_M_(const char *pl) STRLEN *const len)
/* $stdlib = $HKCU{"lib-$]"} || $HKLM{"lib-$]"} || $HKCU{"lib"} || $HKLM{"lib"} || ""; */
sprintf(buffer, "%s-%s", stdlib, pl);
if (!get_regstr(buffer, &sv))
- (void)get_regstr(stdlib, &sv);
+ (void)get_regstr(stdlib, &sv);
#endif
/* $stdlib .= ";$EMD/../../lib" */
@@ -420,7 +420,7 @@ win32_get_privlib(WIN32_NO_REGISTRY_M_(const char *pl) STRLEN *const len)
static char *
win32_get_xlib(const char *pl, WIN32_NO_REGISTRY_M_(const char *xlib)
- const char *libname, STRLEN *const len)
+ const char *libname, STRLEN *const len)
{
#ifndef WIN32_NO_REGISTRY
char regstr[40];
@@ -451,17 +451,17 @@ win32_get_xlib(const char *pl, WIN32_NO_REGISTRY_M_(const char *xlib)
(void)get_emd_part(&sv2, NULL, pathstr, ARCHNAME, "bin", pl, NULL);
if (!sv1 && !sv2)
- return NULL;
+ return NULL;
if (!sv1) {
- sv1 = sv2;
+ sv1 = sv2;
} else if (sv2) {
dTHX;
- sv_catpvs(sv1, ";");
- sv_catsv(sv1, sv2);
+ sv_catpvs(sv1, ";");
+ sv_catsv(sv1, sv2);
}
if (len)
- *len = SvCUR(sv1);
+ *len = SvCUR(sv1);
return SvPVX(sv1);
}
@@ -493,31 +493,31 @@ has_shell_metachars(const char *ptr)
* Shell variable interpolation (%VAR%) can also happen inside strings.
*/
while (*ptr) {
- switch(*ptr) {
- case '%':
- return TRUE;
- case '\'':
- case '\"':
- if (inquote) {
- if (quote == *ptr) {
- inquote = 0;
- quote = '\0';
- }
- }
- else {
- quote = *ptr;
- inquote++;
- }
- break;
- case '>':
- case '<':
- case '|':
- if (!inquote)
- return TRUE;
- default:
- break;
- }
- ++ptr;
+ switch(*ptr) {
+ case '%':
+ return TRUE;
+ case '\'':
+ case '\"':
+ if (inquote) {
+ if (quote == *ptr) {
+ inquote = 0;
+ quote = '\0';
+ }
+ }
+ else {
+ quote = *ptr;
+ inquote++;
+ }
+ break;
+ case '>':
+ case '<':
+ case '|':
+ if (!inquote)
+ return TRUE;
+ default:
+ break;
+ }
+ ++ptr;
}
return FALSE;
}
@@ -552,7 +552,7 @@ win32_getpid(void)
#ifdef USE_ITHREADS
dTHX;
if (w32_pseudo_id)
- return -((int)w32_pseudo_id);
+ return -((int)w32_pseudo_id);
#endif
return _getpid();
}
@@ -570,39 +570,39 @@ tokenize(const char *str, char **dest, char ***destv)
char **retvstart = 0;
int items = -1;
if (str) {
- int slen = strlen(str);
- char *ret;
- char **retv;
- Newx(ret, slen+2, char);
- Newx(retv, (slen+3)/2, char*);
-
- retstart = ret;
- retvstart = retv;
- *retv = ret;
- items = 0;
- while (*str) {
- *ret = *str++;
- if (*ret == '\\' && *str)
- *ret = *str++;
- else if (*ret == ' ') {
- while (*str == ' ')
- str++;
- if (ret == retstart)
- ret--;
- else {
- *ret = '\0';
- ++items;
- if (*str)
- *++retv = ret+1;
- }
- }
- else if (!*str)
- ++items;
- ret++;
- }
- retvstart[items] = NULL;
- *ret++ = '\0';
- *ret = '\0';
+ int slen = strlen(str);
+ char *ret;
+ char **retv;
+ Newx(ret, slen+2, char);
+ Newx(retv, (slen+3)/2, char*);
+
+ retstart = ret;
+ retvstart = retv;
+ *retv = ret;
+ items = 0;
+ while (*str) {
+ *ret = *str++;
+ if (*ret == '\\' && *str)
+ *ret = *str++;
+ else if (*ret == ' ') {
+ while (*str == ' ')
+ str++;
+ if (ret == retstart)
+ ret--;
+ else {
+ *ret = '\0';
+ ++items;
+ if (*str)
+ *++retv = ret+1;
+ }
+ }
+ else if (!*str)
+ ++items;
+ ret++;
+ }
+ retvstart[items] = NULL;
+ *ret++ = '\0';
+ *ret = '\0';
}
*dest = retstart;
*destv = retvstart;
@@ -614,18 +614,18 @@ get_shell(void)
{
dTHX;
if (!w32_perlshell_tokens) {
- /* we don't use COMSPEC here for two reasons:
- * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
- * uncontrolled unportability of the ensuing scripts.
- * 2. PERL5SHELL could be set to a shell that may not be fit for
- * interactive use (which is what most programs look in COMSPEC
- * for).
- */
- const char* defaultshell = "cmd.exe /x/d/c";
- const char *usershell = PerlEnv_getenv("PERL5SHELL");
- w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
- &w32_perlshell_tokens,
- &w32_perlshell_vec);
+ /* we don't use COMSPEC here for two reasons:
+ * 1. the same reason perl on UNIX doesn't use SHELL--rampant and
+ * uncontrolled unportability of the ensuing scripts.
+ * 2. PERL5SHELL could be set to a shell that may not be fit for
+ * interactive use (which is what most programs look in COMSPEC
+ * for).
+ */
+ const char* defaultshell = "cmd.exe /x/d/c";
+ const char *usershell = PerlEnv_getenv("PERL5SHELL");
+ w32_perlshell_items = tokenize(usershell ? usershell : defaultshell,
+ &w32_perlshell_tokens,
+ &w32_perlshell_vec);
}
}
@@ -642,54 +642,54 @@ Perl_do_aspawn(pTHX_ SV *really, SV **mark, SV **sp)
PERL_ARGS_ASSERT_DO_ASPAWN;
if (sp <= mark)
- return -1;
+ return -1;
get_shell();
Newx(argv, (sp - mark) + w32_perlshell_items + 2, char*);
if (SvNIOKp(*(mark+1)) && !SvPOKp(*(mark+1))) {
- ++mark;
- flag = SvIVx(*mark);
+ ++mark;
+ flag = SvIVx(*mark);
}
while (++mark <= sp) {
- if (*mark && (str = SvPV_nolen(*mark)))
- argv[index++] = str;
- else
- argv[index++] = "";
+ if (*mark && (str = SvPV_nolen(*mark)))
+ argv[index++] = str;
+ else
+ argv[index++] = "";
}
argv[index++] = 0;
status = win32_spawnvp(flag,
- (const char*)(really ? SvPV_nolen(really) : argv[0]),
- (const char* const*)argv);
+ (const char*)(really ? SvPV_nolen(really) : argv[0]),
+ (const char* const*)argv);
if (status < 0 && (eno = errno, (eno == ENOEXEC || eno == ENOENT))) {
- /* possible shell-builtin, invoke with shell */
- int sh_items;
- sh_items = w32_perlshell_items;
- while (--index >= 0)
- argv[index+sh_items] = argv[index];
- while (--sh_items >= 0)
- argv[sh_items] = w32_perlshell_vec[sh_items];
+ /* possible shell-builtin, invoke with shell */
+ int sh_items;
+ sh_items = w32_perlshell_items;
+ while (--index >= 0)
+ argv[index+sh_items] = argv[index];
+ while (--sh_items >= 0)
+ argv[sh_items] = w32_perlshell_vec[sh_items];
- status = win32_spawnvp(flag,
- (const char*)(really ? SvPV_nolen(really) : argv[0]),
- (const char* const*)argv);
+ status = win32_spawnvp(flag,
+ (const char*)(really ? SvPV_nolen(really) : argv[0]),
+ (const char* const*)argv);
}
if (flag == P_NOWAIT) {
- PL_statusvalue = -1; /* >16bits hint for pp_system() */
+ PL_statusvalue = -1; /* >16bits hint for pp_system() */
}
else {
- if (status < 0) {
- if (ckWARN(WARN_EXEC))
- Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't spawn \"%s\": %s", argv[0], strerror(errno));
- status = 255 * 256;
- }
- else
- status *= 256;
- PL_statusvalue = status;
+ if (status < 0) {
+ if (ckWARN(WARN_EXEC))
+ Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't spawn \"%s\": %s", argv[0], strerror(errno));
+ status = 255 * 256;
+ }
+ else
+ status *= 256;
+ PL_statusvalue = status;
}
Safefree(argv);
return (status);
@@ -701,20 +701,20 @@ find_next_space(const char *s)
{
bool in_quotes = FALSE;
while (*s) {
- /* ignore doubled backslashes, or backslash+quote */
- if (*s == '\\' && (s[1] == '\\' || s[1] == '"')) {
- s += 2;
- }
- /* keep track of when we're within quotes */
- else if (*s == '"') {
- s++;
- in_quotes = !in_quotes;
- }
- /* break it up only at spaces that aren't in quotes */
- else if (!in_quotes && isSPACE(*s))
- return (char*)s;
- else
- s++;
+ /* ignore doubled backslashes, or backslash+quote */
+ if (*s == '\\' && (s[1] == '\\' || s[1] == '"')) {
+ s += 2;
+ }
+ /* keep track of when we're within quotes */
+ else if (*s == '"') {
+ s++;
+ in_quotes = !in_quotes;
+ }
+ /* break it up only at spaces that aren't in quotes */
+ else if (!in_quotes && isSPACE(*s))
+ return (char*)s;
+ else
+ s++;
}
return (char*)s;
}
@@ -737,79 +737,79 @@ do_spawn2_handles(pTHX_ const char *cmd, int exectype, const int *handles)
/* Save an extra exec if possible. See if there are shell
* metacharacters in it */
if (!has_shell_metachars(cmd)) {
- Newx(argv, strlen(cmd) / 2 + 2, char*);
- Newx(cmd2, strlen(cmd) + 1, char);
- strcpy(cmd2, cmd);
- a = argv;
- for (s = cmd2; *s;) {
- while (*s && isSPACE(*s))
- s++;
- if (*s)
- *(a++) = s;
- s = find_next_space(s);
- if (*s)
- *s++ = '\0';
- }
- *a = NULL;
- if (argv[0]) {
- switch (exectype) {
- case EXECF_SPAWN:
- status = win32_spawnvp(P_WAIT, argv[0],
- (const char* const*)argv);
- break;
- case EXECF_SPAWN_NOWAIT:
- status = do_spawnvp_handles(P_NOWAIT, argv[0],
- (const char* const*)argv, handles);
- break;
- case EXECF_EXEC:
- status = win32_execvp(argv[0], (const char* const*)argv);
- break;
- }
- if (status != -1 || errno == 0)
- needToTry = FALSE;
- }
- Safefree(argv);
- Safefree(cmd2);
+ Newx(argv, strlen(cmd) / 2 + 2, char*);
+ Newx(cmd2, strlen(cmd) + 1, char);
+ strcpy(cmd2, cmd);
+ a = argv;
+ for (s = cmd2; *s;) {
+ while (*s && isSPACE(*s))
+ s++;
+ if (*s)
+ *(a++) = s;
+ s = find_next_space(s);
+ if (*s)
+ *s++ = '\0';
+ }
+ *a = NULL;
+ if (argv[0]) {
+ switch (exectype) {
+ case EXECF_SPAWN:
+ status = win32_spawnvp(P_WAIT, argv[0],
+ (const char* const*)argv);
+ break;
+ case EXECF_SPAWN_NOWAIT:
+ status = do_spawnvp_handles(P_NOWAIT, argv[0],
+ (const char* const*)argv, handles);
+ break;
+ case EXECF_EXEC:
+ status = win32_execvp(argv[0], (const char* const*)argv);
+ break;
+ }
+ if (status != -1 || errno == 0)
+ needToTry = FALSE;
+ }
+ Safefree(argv);
+ Safefree(cmd2);
}
if (needToTry) {
- char **argv;
- int i = -1;
- get_shell();
- Newx(argv, w32_perlshell_items + 2, char*);
- while (++i < w32_perlshell_items)
- argv[i] = w32_perlshell_vec[i];
- argv[i++] = (char *)cmd;
- argv[i] = NULL;
- switch (exectype) {
- case EXECF_SPAWN:
- status = win32_spawnvp(P_WAIT, argv[0],
- (const char* const*)argv);
- break;
- case EXECF_SPAWN_NOWAIT:
- status = do_spawnvp_handles(P_NOWAIT, argv[0],
- (const char* const*)argv, handles);
- break;
- case EXECF_EXEC:
- status = win32_execvp(argv[0], (const char* const*)argv);
- break;
- }
- cmd = argv[0];
- Safefree(argv);
+ char **argv;
+ int i = -1;
+ get_shell();
+ Newx(argv, w32_perlshell_items + 2, char*);
+ while (++i < w32_perlshell_items)
+ argv[i] = w32_perlshell_vec[i];
+ argv[i++] = (char *)cmd;
+ argv[i] = NULL;
+ switch (exectype) {
+ case EXECF_SPAWN:
+ status = win32_spawnvp(P_WAIT, argv[0],
+ (const char* const*)argv);
+ break;
+ case EXECF_SPAWN_NOWAIT:
+ status = do_spawnvp_handles(P_NOWAIT, argv[0],
+ (const char* const*)argv, handles);
+ break;
+ case EXECF_EXEC:
+ status = win32_execvp(argv[0], (const char* const*)argv);
+ break;
+ }
+ cmd = argv[0];
+ Safefree(argv);
}
if (exectype == EXECF_SPAWN_NOWAIT) {
- PL_statusvalue = -1; /* >16bits hint for pp_system() */
+ PL_statusvalue = -1; /* >16bits hint for pp_system() */
}
else {
- if (status < 0) {
- if (ckWARN(WARN_EXEC))
- Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't %s \"%s\": %s",
- (exectype == EXECF_EXEC ? "exec" : "spawn"),
- cmd, strerror(errno));
- status = 255 * 256;
- }
- else
- status *= 256;
- PL_statusvalue = status;
+ if (status < 0) {
+ if (ckWARN(WARN_EXEC))
+ Perl_warner(aTHX_ packWARN(WARN_EXEC), "Can't %s \"%s\": %s",
+ (exectype == EXECF_EXEC ? "exec" : "spawn"),
+ cmd, strerror(errno));
+ status = 255 * 256;
+ }
+ else
+ status *= 256;
+ PL_statusvalue = status;
}
return (status);
}
@@ -858,12 +858,12 @@ win32_opendir(const char *filename)
len = strlen(filename);
if (len == 0) {
- errno = ENOENT;
- return NULL;
+ errno = ENOENT;
+ return NULL;
}
if (len > MAX_PATH) {
- errno = ENAMETOOLONG;
- return NULL;
+ errno = ENAMETOOLONG;
+ return NULL;
}
/* Get us a DIR structure */
@@ -874,11 +874,11 @@ win32_opendir(const char *filename)
/* bare drive name means look in cwd for drive */
if (len == 2 && isALPHA(scanname[0]) && scanname[1] == ':') {
- scanname[len++] = '.';
- scanname[len++] = '/';
+ scanname[len++] = '.';
+ scanname[len++] = '/';
}
else if (scanname[len-1] != '/' && scanname[len-1] != '\\') {
- scanname[len++] = '/';
+ scanname[len++] = '/';
}
scanname[len++] = '*';
scanname[len] = '\0';
@@ -889,24 +889,24 @@ win32_opendir(const char *filename)
dirp->handle = FindFirstFileW(PerlDir_mapW(wscanname), &wFindData);
if (dirp->handle == INVALID_HANDLE_VALUE) {
- DWORD err = GetLastError();
- /* FindFirstFile() fails on empty drives! */
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- return dirp;
- case ERROR_NO_MORE_FILES:
- case ERROR_PATH_NOT_FOUND:
- errno = ENOENT;
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- errno = ENOMEM;
- break;
- default:
- errno = EINVAL;
- break;
- }
- Safefree(dirp);
- return NULL;
+ DWORD err = GetLastError();
+ /* FindFirstFile() fails on empty drives! */
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ return dirp;
+ case ERROR_NO_MORE_FILES:
+ case ERROR_PATH_NOT_FOUND:
+ errno = ENOENT;
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ errno = ENOMEM;
+ break;
+ default:
+ errno = EINVAL;
+ break;
+ }
+ Safefree(dirp);
+ return NULL;
}
use_default = FALSE;
@@ -924,9 +924,9 @@ win32_opendir(const char *filename)
*/
idx = strlen(buffer)+1;
if (idx < 256)
- dirp->size = 256;
+ dirp->size = 256;
else
- dirp->size = idx;
+ dirp->size = idx;
Newx(dirp->start, dirp->size, char);
strcpy(dirp->start, buffer);
dirp->nfiles++;
@@ -945,30 +945,30 @@ win32_readdir(DIR *dirp)
long len;
if (dirp->curr) {
- /* first set up the structure to return */
- len = strlen(dirp->curr);
- strcpy(dirp->dirstr.d_name, dirp->curr);
- dirp->dirstr.d_namlen = len;
+ /* first set up the structure to return */
+ len = strlen(dirp->curr);
+ strcpy(dirp->dirstr.d_name, dirp->curr);
+ dirp->dirstr.d_namlen = len;
- /* Fake an inode */
- dirp->dirstr.d_ino = dirp->curr - dirp->start;
+ /* Fake an inode */
+ dirp->dirstr.d_ino = dirp->curr - dirp->start;
- /* Now set up for the next call to readdir */
- dirp->curr += len + 1;
- if (dirp->curr >= dirp->end) {
- BOOL res;
- char buffer[MAX_PATH*2];
+ /* Now set up for the next call to readdir */
+ dirp->curr += len + 1;
+ if (dirp->curr >= dirp->end) {
+ BOOL res;
+ char buffer[MAX_PATH*2];
if (dirp->handle == INVALID_HANDLE_VALUE) {
res = 0;
}
- /* finding the next file that matches the wildcard
- * (which should be all of them in this directory!).
- */
- else {
+ /* finding the next file that matches the wildcard
+ * (which should be all of them in this directory!).
+ */
+ else {
WIN32_FIND_DATAW wFindData;
- res = FindNextFileW(dirp->handle, &wFindData);
- if (res) {
+ res = FindNextFileW(dirp->handle, &wFindData);
+ if (res) {
BOOL use_default = FALSE;
WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS,
wFindData.cFileName, -1,
@@ -980,33 +980,33 @@ win32_readdir(DIR *dirp)
}
}
}
- if (res) {
- long endpos = dirp->end - dirp->start;
- long newsize = endpos + strlen(buffer) + 1;
- /* bump the string table size by enough for the
- * new name and its null terminator */
- while (newsize > dirp->size) {
- long curpos = dirp->curr - dirp->start;
- Renew(dirp->start, dirp->size * 2, char);
- dirp->size *= 2;
- dirp->curr = dirp->start + curpos;
- }
- strcpy(dirp->start + endpos, buffer);
- dirp->end = dirp->start + newsize;
- dirp->nfiles++;
- }
- else {
- dirp->curr = NULL;
+ if (res) {
+ long endpos = dirp->end - dirp->start;
+ long newsize = endpos + strlen(buffer) + 1;
+ /* bump the string table size by enough for the
+ * new name and its null terminator */
+ while (newsize > dirp->size) {
+ long curpos = dirp->curr - dirp->start;
+ Renew(dirp->start, dirp->size * 2, char);
+ dirp->size *= 2;
+ dirp->curr = dirp->start + curpos;
+ }
+ strcpy(dirp->start + endpos, buffer);
+ dirp->end = dirp->start + newsize;
+ dirp->nfiles++;
+ }
+ else {
+ dirp->curr = NULL;
if (dirp->handle != INVALID_HANDLE_VALUE) {
FindClose(dirp->handle);
dirp->handle = INVALID_HANDLE_VALUE;
}
}
- }
- return &(dirp->dirstr);
+ }
+ return &(dirp->dirstr);
}
else
- return NULL;
+ return NULL;
}
/* Telldir returns the current string pointer position */
@@ -1038,7 +1038,7 @@ DllExport int
win32_closedir(DIR *dirp)
{
if (dirp->handle != INVALID_HANDLE_VALUE)
- FindClose(dirp->handle);
+ FindClose(dirp->handle);
Safefree(dirp->start);
Safefree(dirp);
return 1;
@@ -1145,7 +1145,7 @@ getlogin(void)
char *buf = w32_getlogin_buffer;
DWORD size = sizeof(w32_getlogin_buffer);
if (GetUserName(buf,&size))
- return buf;
+ return buf;
return (char*)NULL;
}
@@ -1169,16 +1169,16 @@ int mkstemp(const char *path)
retry:
if (i++ > 10) { /* give up */
- errno = ENOENT;
- return -1;
+ errno = ENOENT;
+ return -1;
}
if (!GetTempFileNameA((LPCSTR)path, "plr", 1, buf)) {
- errno = ENOENT;
- return -1;
+ errno = ENOENT;
+ return -1;
}
fd = PerlLIO_open3(buf, O_CREAT|O_RDWR|O_EXCL, 0600);
if (fd == -1)
- goto retry;
+ goto retry;
return fd;
}
#endif
@@ -1188,8 +1188,8 @@ find_pid(pTHX_ int pid)
{
long child = w32_num_children;
while (--child >= 0) {
- if ((int)w32_child_pids[child] == pid)
- return child;
+ if ((int)w32_child_pids[child] == pid)
+ return child;
}
return -1;
}
@@ -1198,13 +1198,13 @@ static void
remove_dead_process(long child)
{
if (child >= 0) {
- dTHX;
- CloseHandle(w32_child_handles[child]);
- Move(&w32_child_handles[child+1], &w32_child_handles[child],
- (w32_num_children-child-1), HANDLE);
- Move(&w32_child_pids[child+1], &w32_child_pids[child],
- (w32_num_children-child-1), DWORD);
- w32_num_children--;
+ dTHX;
+ CloseHandle(w32_child_handles[child]);
+ Move(&w32_child_handles[child+1], &w32_child_handles[child],
+ (w32_num_children-child-1), HANDLE);
+ Move(&w32_child_pids[child+1], &w32_child_pids[child],
+ (w32_num_children-child-1), DWORD);
+ w32_num_children--;
}
}
@@ -1214,8 +1214,8 @@ find_pseudo_pid(pTHX_ int pid)
{
long child = w32_num_pseudo_children;
while (--child >= 0) {
- if ((int)w32_pseudo_child_pids[child] == pid)
- return child;
+ if ((int)w32_pseudo_child_pids[child] == pid)
+ return child;
}
return -1;
}
@@ -1224,17 +1224,17 @@ static void
remove_dead_pseudo_process(long child)
{
if (child >= 0) {
- dTHX;
- CloseHandle(w32_pseudo_child_handles[child]);
- Move(&w32_pseudo_child_handles[child+1], &w32_pseudo_child_handles[child],
- (w32_num_pseudo_children-child-1), HANDLE);
- Move(&w32_pseudo_child_pids[child+1], &w32_pseudo_child_pids[child],
- (w32_num_pseudo_children-child-1), DWORD);
- Move(&w32_pseudo_child_message_hwnds[child+1], &w32_pseudo_child_message_hwnds[child],
- (w32_num_pseudo_children-child-1), HWND);
- Move(&w32_pseudo_child_sigterm[child+1], &w32_pseudo_child_sigterm[child],
- (w32_num_pseudo_children-child-1), char);
- w32_num_pseudo_children--;
+ dTHX;
+ CloseHandle(w32_pseudo_child_handles[child]);
+ Move(&w32_pseudo_child_handles[child+1], &w32_pseudo_child_handles[child],
+ (w32_num_pseudo_children-child-1), HANDLE);
+ Move(&w32_pseudo_child_pids[child+1], &w32_pseudo_child_pids[child],
+ (w32_num_pseudo_children-child-1), DWORD);
+ Move(&w32_pseudo_child_message_hwnds[child+1], &w32_pseudo_child_message_hwnds[child],
+ (w32_num_pseudo_children-child-1), HWND);
+ Move(&w32_pseudo_child_sigterm[child+1], &w32_pseudo_child_sigterm[child],
+ (w32_num_pseudo_children-child-1), char);
+ w32_num_pseudo_children--;
}
}
@@ -1373,14 +1373,14 @@ get_hwnd_delay(pTHX, long child, DWORD tries)
if (hwnd != INVALID_HANDLE_VALUE) return hwnd;
{
- unsigned int count = 0;
- /* No Sleep(1) if tries==0, just fail instead if we get this far. */
- while (count++ < tries) {
- Sleep(1);
- win32_async_check(aTHX);
- hwnd = w32_pseudo_child_message_hwnds[child];
- if (hwnd != INVALID_HANDLE_VALUE) return hwnd;
- }
+ unsigned int count = 0;
+ /* No Sleep(1) if tries==0, just fail instead if we get this far. */
+ while (count++ < tries) {
+ Sleep(1);
+ win32_async_check(aTHX);
+ hwnd = w32_pseudo_child_message_hwnds[child];
+ if (hwnd != INVALID_HANDLE_VALUE) return hwnd;
+ }
}
Perl_croak(aTHX_ "panic: child pseudo-process was never scheduled");
@@ -1394,64 +1394,64 @@ win32_kill(int pid, int sig)
long child;
#ifdef USE_ITHREADS
if (pid < 0) {
- /* it is a pseudo-forked child */
- child = find_pseudo_pid(aTHX_ -pid);
- if (child >= 0) {
- HANDLE hProcess = w32_pseudo_child_handles[child];
- switch (sig) {
- case 0:
- /* "Does process exist?" use of kill */
- return 0;
-
- case 9: {
- /* kill -9 style un-graceful exit */
- /* Do a wait to make sure child starts and isn't in DLL
- * Loader Lock */
- HWND hwnd = get_hwnd_delay(aTHX, child, 5);
- if (TerminateThread(hProcess, sig)) {
- /* Allow the scheduler to finish cleaning up the other
- * thread.
- * Otherwise, if we ExitProcess() before another context
- * switch happens we will end up with a process exit
- * code of "sig" instead of our own exit status.
- * https://rt.cpan.org/Ticket/Display.html?id=66016#txn-908976
- */
- Sleep(0);
- remove_dead_pseudo_process(child);
- return 0;
- }
- break;
- }
-
- default: {
- HWND hwnd = get_hwnd_delay(aTHX, child, 5);
- /* We fake signals to pseudo-processes using Win32
- * message queue. */
- if ((hwnd != NULL && PostMessage(hwnd, WM_USER_KILL, sig, 0)) ||
- PostThreadMessage(-pid, WM_USER_KILL, sig, 0))
- {
- /* Don't wait for child process to terminate after we send a
- * SIGTERM because the child may be blocked in a system call
- * and never receive the signal.
- */
- if (sig == SIGTERM) {
- Sleep(0);
- w32_pseudo_child_sigterm[child] = 1;
- }
- /* It might be us ... */
- PERL_ASYNC_CHECK();
- return 0;
- }
- break;
- }
- } /* switch */
- }
+ /* it is a pseudo-forked child */
+ child = find_pseudo_pid(aTHX_ -pid);
+ if (child >= 0) {
+ HANDLE hProcess = w32_pseudo_child_handles[child];
+ switch (sig) {
+ case 0:
+ /* "Does process exist?" use of kill */
+ return 0;
+
+ case 9: {
+ /* kill -9 style un-graceful exit */
+ /* Do a wait to make sure child starts and isn't in DLL
+ * Loader Lock */
+ HWND hwnd = get_hwnd_delay(aTHX, child, 5);
+ if (TerminateThread(hProcess, sig)) {
+ /* Allow the scheduler to finish cleaning up the other
+ * thread.
+ * Otherwise, if we ExitProcess() before another context
+ * switch happens we will end up with a process exit
+ * code of "sig" instead of our own exit status.
+ * https://rt.cpan.org/Ticket/Display.html?id=66016#txn-908976
+ */
+ Sleep(0);
+ remove_dead_pseudo_process(child);
+ return 0;
+ }
+ break;
+ }
+
+ default: {
+ HWND hwnd = get_hwnd_delay(aTHX, child, 5);
+ /* We fake signals to pseudo-processes using Win32
+ * message queue. */
+ if ((hwnd != NULL && PostMessage(hwnd, WM_USER_KILL, sig, 0)) ||
+ PostThreadMessage(-pid, WM_USER_KILL, sig, 0))
+ {
+ /* Don't wait for child process to terminate after we send a
+ * SIGTERM because the child may be blocked in a system call
+ * and never receive the signal.
+ */
+ if (sig == SIGTERM) {
+ Sleep(0);
+ w32_pseudo_child_sigterm[child] = 1;
+ }
+ /* It might be us ... */
+ PERL_ASYNC_CHECK();
+ return 0;
+ }
+ break;
+ }
+ } /* switch */
+ }
}
else
#endif
{
- child = find_pid(aTHX_ pid);
- if (child >= 0) {
+ child = find_pid(aTHX_ pid);
+ if (child >= 0) {
if (my_kill(pid, sig)) {
DWORD exitcode = 0;
if (GetExitCodeProcess(w32_child_handles[child], &exitcode) &&
@@ -1461,11 +1461,11 @@ win32_kill(int pid, int sig)
}
return 0;
}
- }
- else {
+ }
+ else {
if (my_kill(pid, sig))
return 0;
- }
+ }
}
errno = EINVAL;
return -1;
@@ -1871,13 +1871,13 @@ win32_lstat(const char *path, Stat_t *sbuf)
#define isSLASH(c) ((c) == '/' || (c) == '\\')
#define SKIP_SLASHES(s) \
STMT_START { \
- while (*(s) && isSLASH(*(s))) \
- ++(s); \
+ while (*(s) && isSLASH(*(s))) \
+ ++(s); \
} STMT_END
#define COPY_NONSLASHES(d,s) \
STMT_START { \
- while (*(s) && !isSLASH(*(s))) \
- *(d)++ = *(s)++; \
+ while (*(s) && !isSLASH(*(s))) \
+ *(d)++ = *(s)++; \
} STMT_END
/* Find the longname of a given path. path is destructively modified.
@@ -1892,78 +1892,78 @@ win32_longpath(char *path)
char *start = path;
char sep;
if (!path)
- return NULL;
+ return NULL;
/* drive prefix */
if (isALPHA(path[0]) && path[1] == ':') {
- start = path + 2;
- *tmpstart++ = path[0];
- *tmpstart++ = ':';
+ start = path + 2;
+ *tmpstart++ = path[0];
+ *tmpstart++ = ':';
}
/* UNC prefix */
else if (isSLASH(path[0]) && isSLASH(path[1])) {
- start = path + 2;
- *tmpstart++ = path[0];
- *tmpstart++ = path[1];
- SKIP_SLASHES(start);
- COPY_NONSLASHES(tmpstart,start); /* copy machine name */
- if (*start) {
- *tmpstart++ = *start++;
- SKIP_SLASHES(start);
- COPY_NONSLASHES(tmpstart,start); /* copy share name */
- }
+ start = path + 2;
+ *tmpstart++ = path[0];
+ *tmpstart++ = path[1];
+ SKIP_SLASHES(start);
+ COPY_NONSLASHES(tmpstart,start); /* copy machine name */
+ if (*start) {
+ *tmpstart++ = *start++;
+ SKIP_SLASHES(start);
+ COPY_NONSLASHES(tmpstart,start); /* copy share name */
+ }
}
*tmpstart = '\0';
while (*start) {
- /* copy initial slash, if any */
- if (isSLASH(*start)) {
- *tmpstart++ = *start++;
- *tmpstart = '\0';
- SKIP_SLASHES(start);
- }
-
- /* FindFirstFile() expands "." and "..", so we need to pass
- * those through unmolested */
- if (*start == '.'
- && (!start[1] || isSLASH(start[1])
- || (start[1] == '.' && (!start[2] || isSLASH(start[2])))))
- {
- COPY_NONSLASHES(tmpstart,start); /* copy "." or ".." */
- *tmpstart = '\0';
- continue;
- }
-
- /* if this is the end, bust outta here */
- if (!*start)
- break;
-
- /* now we're at a non-slash; walk up to next slash */
- while (*start && !isSLASH(*start))
- ++start;
-
- /* stop and find full name of component */
- sep = *start;
- *start = '\0';
- fhand = FindFirstFile(path,&fdata);
- *start = sep;
- if (fhand != INVALID_HANDLE_VALUE) {
- STRLEN len = strlen(fdata.cFileName);
- if ((STRLEN)(tmpbuf + sizeof(tmpbuf) - tmpstart) > len) {
- strcpy(tmpstart, fdata.cFileName);
- tmpstart += len;
- FindClose(fhand);
- }
- else {
- FindClose(fhand);
- errno = ERANGE;
- return NULL;
- }
- }
- else {
- /* failed a step, just return without side effects */
- errno = EINVAL;
- return NULL;
- }
+ /* copy initial slash, if any */
+ if (isSLASH(*start)) {
+ *tmpstart++ = *start++;
+ *tmpstart = '\0';
+ SKIP_SLASHES(start);
+ }
+
+ /* FindFirstFile() expands "." and "..", so we need to pass
+ * those through unmolested */
+ if (*start == '.'
+ && (!start[1] || isSLASH(start[1])
+ || (start[1] == '.' && (!start[2] || isSLASH(start[2])))))
+ {
+ COPY_NONSLASHES(tmpstart,start); /* copy "." or ".." */
+ *tmpstart = '\0';
+ continue;
+ }
+
+ /* if this is the end, bust outta here */
+ if (!*start)
+ break;
+
+ /* now we're at a non-slash; walk up to next slash */
+ while (*start && !isSLASH(*start))
+ ++start;
+
+ /* stop and find full name of component */
+ sep = *start;
+ *start = '\0';
+ fhand = FindFirstFile(path,&fdata);
+ *start = sep;
+ if (fhand != INVALID_HANDLE_VALUE) {
+ STRLEN len = strlen(fdata.cFileName);
+ if ((STRLEN)(tmpbuf + sizeof(tmpbuf) - tmpstart) > len) {
+ strcpy(tmpstart, fdata.cFileName);
+ tmpstart += len;
+ FindClose(fhand);
+ }
+ else {
+ FindClose(fhand);
+ errno = ERANGE;
+ return NULL;
+ }
+ }
+ else {
+ /* failed a step, just return without side effects */
+ errno = EINVAL;
+ return NULL;
+ }
}
strcpy(path,tmpbuf);
return path;
@@ -1974,7 +1974,7 @@ out_of_memory(void)
{
if (PL_curinterp)
- croak_no_mem();
+ croak_no_mem();
exit(1);
}
@@ -2101,7 +2101,7 @@ win32_getenv(const char *name)
needlen = GetEnvironmentVariableA(name,NULL,0);
if (needlen != 0) {
- curitem = sv_2mortal(newSVpvs(""));
+ curitem = sv_2mortal(newSVpvs(""));
do {
SvGROW(curitem, needlen+1);
needlen = GetEnvironmentVariableA(name,SvPVX(curitem),
@@ -2110,42 +2110,42 @@ win32_getenv(const char *name)
SvCUR_set(curitem, needlen);
}
else {
- last_err = GetLastError();
- if (last_err == ERROR_NOT_ENOUGH_MEMORY) {
- /* It appears the variable is in the env, but the Win32 API
- doesn't have a canned way of getting it. So we fall back to
- grabbing the whole env and pulling this value out if possible */
- char *envv = GetEnvironmentStrings();
- char *cur = envv;
- STRLEN len;
- while (*cur) {
- char *end = strchr(cur,'=');
- if (end && end != cur) {
- *end = '\0';
- if (strEQ(cur,name)) {
- curitem = sv_2mortal(newSVpv(end+1,0));
- *end = '=';
- break;
- }
- *end = '=';
- cur = end + strlen(end+1)+2;
- }
- else if ((len = strlen(cur)))
- cur += len+1;
- }
- FreeEnvironmentStrings(envv);
- }
+ last_err = GetLastError();
+ if (last_err == ERROR_NOT_ENOUGH_MEMORY) {
+ /* It appears the variable is in the env, but the Win32 API
+ doesn't have a canned way of getting it. So we fall back to
+ grabbing the whole env and pulling this value out if possible */
+ char *envv = GetEnvironmentStrings();
+ char *cur = envv;
+ STRLEN len;
+ while (*cur) {
+ char *end = strchr(cur,'=');
+ if (end && end != cur) {
+ *end = '\0';
+ if (strEQ(cur,name)) {
+ curitem = sv_2mortal(newSVpv(end+1,0));
+ *end = '=';
+ break;
+ }
+ *end = '=';
+ cur = end + strlen(end+1)+2;
+ }
+ else if ((len = strlen(cur)))
+ cur += len+1;
+ }
+ FreeEnvironmentStrings(envv);
+ }
#ifndef WIN32_NO_REGISTRY
- else {
- /* last ditch: allow any environment variables that begin with 'PERL'
- to be obtained from the registry, if found there */
- if (strBEGINs(name, "PERL"))
- (void)get_regstr(name, &curitem);
- }
+ else {
+ /* last ditch: allow any environment variables that begin with 'PERL'
+ to be obtained from the registry, if found there */
+ if (strBEGINs(name, "PERL"))
+ (void)get_regstr(name, &curitem);
+ }
#endif
}
if (curitem && SvCUR(curitem))
- return SvPVX(curitem);
+ return SvPVX(curitem);
return NULL;
}
@@ -2206,16 +2206,16 @@ win32_times(struct tms *timebuf)
clock_t process_time_so_far = clock();
if (GetProcessTimes(GetCurrentProcess(), &dummy, &dummy,
&kernel,&user)) {
- timebuf->tms_utime = filetime_to_clock(&user);
- timebuf->tms_stime = filetime_to_clock(&kernel);
- timebuf->tms_cutime = 0;
- timebuf->tms_cstime = 0;
+ timebuf->tms_utime = filetime_to_clock(&user);
+ timebuf->tms_stime = filetime_to_clock(&kernel);
+ timebuf->tms_cutime = 0;
+ timebuf->tms_cstime = 0;
} else {
/* That failed - e.g. Win95 fallback to clock() */
- timebuf->tms_utime = process_time_so_far;
- timebuf->tms_stime = 0;
- timebuf->tms_cutime = 0;
- timebuf->tms_cstime = 0;
+ timebuf->tms_utime = process_time_so_far;
+ timebuf->tms_stime = 0;
+ timebuf->tms_cutime = 0;
+ timebuf->tms_cstime = 0;
}
return process_time_so_far;
}
@@ -2308,7 +2308,7 @@ win32_utime(const char *filename, struct utimbuf *times)
}
if (filetime_from_time(&ftAccess, times->actime) &&
- filetime_from_time(&ftWrite, times->modtime)) {
+ filetime_from_time(&ftWrite, times->modtime)) {
if (SetFileTime(handle, NULL, &ftAccess, &ftWrite)) {
rc = 0;
}
@@ -2394,49 +2394,49 @@ win32_uname(struct utsname *name)
/* nodename */
hep = win32_gethostbyname("localhost");
if (hep) {
- STRLEN len = strlen(hep->h_name);
- if (len <= nodemax) {
- strcpy(name->nodename, hep->h_name);
- }
- else {
- strncpy(name->nodename, hep->h_name, nodemax);
- name->nodename[nodemax] = '\0';
- }
+ STRLEN len = strlen(hep->h_name);
+ if (len <= nodemax) {
+ strcpy(name->nodename, hep->h_name);
+ }
+ else {
+ strncpy(name->nodename, hep->h_name, nodemax);
+ name->nodename[nodemax] = '\0';
+ }
}
else {
- DWORD sz = nodemax;
- if (!GetComputerName(name->nodename, &sz))
- *name->nodename = '\0';
+ DWORD sz = nodemax;
+ if (!GetComputerName(name->nodename, &sz))
+ *name->nodename = '\0';
}
/* machine (architecture) */
{
- SYSTEM_INFO info;
- DWORD procarch;
- char *arch;
- GetSystemInfo(&info);
+ SYSTEM_INFO info;
+ DWORD procarch;
+ char *arch;
+ GetSystemInfo(&info);
#if (defined(__MINGW32__) && !defined(_ANONYMOUS_UNION) && !defined(__MINGW_EXTENSION))
- procarch = info.u.s.wProcessorArchitecture;
+ procarch = info.u.s.wProcessorArchitecture;
#else
- procarch = info.wProcessorArchitecture;
+ procarch = info.wProcessorArchitecture;
#endif
- switch (procarch) {
- case PROCESSOR_ARCHITECTURE_INTEL:
- arch = "x86"; break;
- case PROCESSOR_ARCHITECTURE_IA64:
- arch = "ia64"; break;
- case PROCESSOR_ARCHITECTURE_AMD64:
- arch = "amd64"; break;
- case PROCESSOR_ARCHITECTURE_UNKNOWN:
- arch = "unknown"; break;
- default:
- sprintf(name->machine, "unknown(0x%x)", procarch);
- arch = name->machine;
- break;
- }
- if (name->machine != arch)
- strcpy(name->machine, arch);
+ switch (procarch) {
+ case PROCESSOR_ARCHITECTURE_INTEL:
+ arch = "x86"; break;
+ case PROCESSOR_ARCHITECTURE_IA64:
+ arch = "ia64"; break;
+ case PROCESSOR_ARCHITECTURE_AMD64:
+ arch = "amd64"; break;
+ case PROCESSOR_ARCHITECTURE_UNKNOWN:
+ arch = "unknown"; break;
+ default:
+ sprintf(name->machine, "unknown(0x%x)", procarch);
+ arch = name->machine;
+ break;
+ }
+ if (name->machine != arch)
+ strcpy(name->machine, arch);
}
return 0;
}
@@ -2447,30 +2447,30 @@ int
do_raise(pTHX_ int sig)
{
if (sig < SIG_SIZE) {
- Sighandler_t handler = w32_sighandler[sig];
- if (handler == SIG_IGN) {
- return 0;
- }
- else if (handler != SIG_DFL) {
- (*handler)(sig);
- return 0;
- }
- else {
- /* Choose correct default behaviour */
- switch (sig) {
+ Sighandler_t handler = w32_sighandler[sig];
+ if (handler == SIG_IGN) {
+ return 0;
+ }
+ else if (handler != SIG_DFL) {
+ (*handler)(sig);
+ return 0;
+ }
+ else {
+ /* Choose correct default behaviour */
+ switch (sig) {
#ifdef SIGCLD
- case SIGCLD:
+ case SIGCLD:
#endif
#ifdef SIGCHLD
- case SIGCHLD:
+ case SIGCHLD:
#endif
- case 0:
- return 0;
- case SIGTERM:
- default:
- break;
- }
- }
+ case 0:
+ return 0;
+ case SIGTERM:
+ default:
+ break;
+ }
+ }
}
/* Tell caller to exit thread/process as appropriate */
return 1;
@@ -2545,9 +2545,9 @@ win32_msgwait(pTHX_ DWORD count, LPHANDLE handles, DWORD timeout, LPDWORD result
FT_t ticks = {0};
unsigned __int64 endtime = timeout;
if (timeout != INFINITE) {
- GetSystemTimeAsFileTime(&ticks.ft_val);
- ticks.ft_i64 /= 10000;
- endtime += ticks.ft_i64;
+ GetSystemTimeAsFileTime(&ticks.ft_val);
+ ticks.ft_i64 /= 10000;
+ endtime += ticks.ft_i64;
}
/* This was a race condition. Do not let a non INFINITE timeout to
* MsgWaitForMultipleObjects roll under 0 creating a near
@@ -2564,41 +2564,41 @@ win32_msgwait(pTHX_ DWORD count, LPHANDLE handles, DWORD timeout, LPDWORD result
* causes msctf.dll to be loaded into Perl by kernel), see [perl #33096].
*/
while (ticks.ft_i64 <= endtime) {
- /* if timeout's type is lengthened, remember to split 64b timeout
- * into multiple non-infinity runs of MWFMO */
- DWORD result = MsgWaitForMultipleObjects(count, handles, FALSE,
- (DWORD)(endtime - ticks.ft_i64),
- QS_POSTMESSAGE|QS_TIMER|QS_SENDMESSAGE);
- if (resultp)
- *resultp = result;
- if (result == WAIT_TIMEOUT) {
- /* Ran out of time - explicit return of zero to avoid -ve if we
- have scheduling issues
+ /* if timeout's type is lengthened, remember to split 64b timeout
+ * into multiple non-infinity runs of MWFMO */
+ DWORD result = MsgWaitForMultipleObjects(count, handles, FALSE,
+ (DWORD)(endtime - ticks.ft_i64),
+ QS_POSTMESSAGE|QS_TIMER|QS_SENDMESSAGE);
+ if (resultp)
+ *resultp = result;
+ if (result == WAIT_TIMEOUT) {
+ /* Ran out of time - explicit return of zero to avoid -ve if we
+ have scheduling issues
*/
- return 0;
- }
- if (timeout != INFINITE) {
- GetSystemTimeAsFileTime(&ticks.ft_val);
- ticks.ft_i64 /= 10000;
- }
- if (result == WAIT_OBJECT_0 + count) {
- /* Message has arrived - check it */
- (void)win32_async_check(aTHX);
+ return 0;
+ }
+ if (timeout != INFINITE) {
+ GetSystemTimeAsFileTime(&ticks.ft_val);
+ ticks.ft_i64 /= 10000;
+ }
+ if (result == WAIT_OBJECT_0 + count) {
+ /* Message has arrived - check it */
+ (void)win32_async_check(aTHX);
/* retry */
if (ticks.ft_i64 > endtime)
endtime = ticks.ft_i64;
continue;
- }
- else {
- /* Not timeout or message - one of handles is ready */
- break;
- }
+ }
+ else {
+ /* Not timeout or message - one of handles is ready */
+ break;
+ }
}
/* If we are past the end say zero */
if (!ticks.ft_i64 || ticks.ft_i64 > endtime)
- return 0;
+ return 0;
/* compute time left to wait */
ticks.ft_i64 = endtime - ticks.ft_i64;
/* if more ms than DWORD, then return max DWORD */
@@ -2616,52 +2616,52 @@ win32_internal_wait(pTHX_ int *status, DWORD timeout)
#ifdef USE_ITHREADS
if (w32_num_pseudo_children) {
- win32_msgwait(aTHX_ w32_num_pseudo_children, w32_pseudo_child_handles,
- timeout, &waitcode);
+ win32_msgwait(aTHX_ w32_num_pseudo_children, w32_pseudo_child_handles,
+ timeout, &waitcode);
/* Time out here if there are no other children to wait for. */
- if (waitcode == WAIT_TIMEOUT) {
- if (!w32_num_children) {
- return 0;
- }
- }
- else if (waitcode != WAIT_FAILED) {
- if (waitcode >= WAIT_ABANDONED_0
- && waitcode < WAIT_ABANDONED_0 + w32_num_pseudo_children)
- i = waitcode - WAIT_ABANDONED_0;
- else
- i = waitcode - WAIT_OBJECT_0;
- if (GetExitCodeThread(w32_pseudo_child_handles[i], &exitcode)) {
- *status = (int)((exitcode & 0xff) << 8);
- retval = (int)w32_pseudo_child_pids[i];
- remove_dead_pseudo_process(i);
- return -retval;
- }
- }
+ if (waitcode == WAIT_TIMEOUT) {
+ if (!w32_num_children) {
+ return 0;
+ }
+ }
+ else if (waitcode != WAIT_FAILED) {
+ if (waitcode >= WAIT_ABANDONED_0
+ && waitcode < WAIT_ABANDONED_0 + w32_num_pseudo_children)
+ i = waitcode - WAIT_ABANDONED_0;
+ else
+ i = waitcode - WAIT_OBJECT_0;
+ if (GetExitCodeThread(w32_pseudo_child_handles[i], &exitcode)) {
+ *status = (int)((exitcode & 0xff) << 8);
+ retval = (int)w32_pseudo_child_pids[i];
+ remove_dead_pseudo_process(i);
+ return -retval;
+ }
+ }
}
#endif
if (!w32_num_children) {
- errno = ECHILD;
- return -1;
+ errno = ECHILD;
+ return -1;
}
/* if a child exists, wait for it to die */
win32_msgwait(aTHX_ w32_num_children, w32_child_handles, timeout, &waitcode);
if (waitcode == WAIT_TIMEOUT) {
- return 0;
+ return 0;
}
if (waitcode != WAIT_FAILED) {
- if (waitcode >= WAIT_ABANDONED_0
- && waitcode < WAIT_ABANDONED_0 + w32_num_children)
- i = waitcode - WAIT_ABANDONED_0;
- else
- i = waitcode - WAIT_OBJECT_0;
- if (GetExitCodeProcess(w32_child_handles[i], &exitcode) ) {
- *status = (int)((exitcode & 0xff) << 8);
- retval = (int)w32_child_pids[i];
- remove_dead_process(i);
- return retval;
- }
+ if (waitcode >= WAIT_ABANDONED_0
+ && waitcode < WAIT_ABANDONED_0 + w32_num_children)
+ i = waitcode - WAIT_ABANDONED_0;
+ else
+ i = waitcode - WAIT_OBJECT_0;
+ if (GetExitCodeProcess(w32_child_handles[i], &exitcode) ) {
+ *status = (int)((exitcode & 0xff) << 8);
+ retval = (int)w32_child_pids[i];
+ remove_dead_process(i);
+ return retval;
+ }
}
errno = GetLastError();
@@ -2676,71 +2676,71 @@ win32_waitpid(int pid, int *status, int flags)
int retval = -1;
long child;
if (pid == -1) /* XXX threadid == 1 ? */
- return win32_internal_wait(aTHX_ status, timeout);
+ return win32_internal_wait(aTHX_ status, timeout);
#ifdef USE_ITHREADS
else if (pid < 0) {
- child = find_pseudo_pid(aTHX_ -pid);
- if (child >= 0) {
- HANDLE hThread = w32_pseudo_child_handles[child];
- DWORD waitcode;
- win32_msgwait(aTHX_ 1, &hThread, timeout, &waitcode);
- if (waitcode == WAIT_TIMEOUT) {
- return 0;
- }
- else if (waitcode == WAIT_OBJECT_0) {
- if (GetExitCodeThread(hThread, &waitcode)) {
- *status = (int)((waitcode & 0xff) << 8);
- retval = (int)w32_pseudo_child_pids[child];
- remove_dead_pseudo_process(child);
- return -retval;
- }
- }
- else
- errno = ECHILD;
- }
+ child = find_pseudo_pid(aTHX_ -pid);
+ if (child >= 0) {
+ HANDLE hThread = w32_pseudo_child_handles[child];
+ DWORD waitcode;
+ win32_msgwait(aTHX_ 1, &hThread, timeout, &waitcode);
+ if (waitcode == WAIT_TIMEOUT) {
+ return 0;
+ }
+ else if (waitcode == WAIT_OBJECT_0) {
+ if (GetExitCodeThread(hThread, &waitcode)) {
+ *status = (int)((waitcode & 0xff) << 8);
+ retval = (int)w32_pseudo_child_pids[child];
+ remove_dead_pseudo_process(child);
+ return -retval;
+ }
+ }
+ else
+ errno = ECHILD;
+ }
}
#endif
else {
- HANDLE hProcess;
- DWORD waitcode;
- child = find_pid(aTHX_ pid);
- if (child >= 0) {
- hProcess = w32_child_handles[child];
- win32_msgwait(aTHX_ 1, &hProcess, timeout, &waitcode);
- if (waitcode == WAIT_TIMEOUT) {
- return 0;
- }
- else if (waitcode == WAIT_OBJECT_0) {
- if (GetExitCodeProcess(hProcess, &waitcode)) {
- *status = (int)((waitcode & 0xff) << 8);
- retval = (int)w32_child_pids[child];
- remove_dead_process(child);
- return retval;
- }
- }
- else
- errno = ECHILD;
- }
- else {
- hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
- if (hProcess) {
- win32_msgwait(aTHX_ 1, &hProcess, timeout, &waitcode);
- if (waitcode == WAIT_TIMEOUT) {
+ HANDLE hProcess;
+ DWORD waitcode;
+ child = find_pid(aTHX_ pid);
+ if (child >= 0) {
+ hProcess = w32_child_handles[child];
+ win32_msgwait(aTHX_ 1, &hProcess, timeout, &waitcode);
+ if (waitcode == WAIT_TIMEOUT) {
+ return 0;
+ }
+ else if (waitcode == WAIT_OBJECT_0) {
+ if (GetExitCodeProcess(hProcess, &waitcode)) {
+ *status = (int)((waitcode & 0xff) << 8);
+ retval = (int)w32_child_pids[child];
+ remove_dead_process(child);
+ return retval;
+ }
+ }
+ else
+ errno = ECHILD;
+ }
+ else {
+ hProcess = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
+ if (hProcess) {
+ win32_msgwait(aTHX_ 1, &hProcess, timeout, &waitcode);
+ if (waitcode == WAIT_TIMEOUT) {
CloseHandle(hProcess);
- return 0;
- }
- else if (waitcode == WAIT_OBJECT_0) {
- if (GetExitCodeProcess(hProcess, &waitcode)) {
- *status = (int)((waitcode & 0xff) << 8);
- CloseHandle(hProcess);
- return pid;
- }
- }
- CloseHandle(hProcess);
- }
- else
- errno = ECHILD;
- }
+ return 0;
+ }
+ else if (waitcode == WAIT_OBJECT_0) {
+ if (GetExitCodeProcess(hProcess, &waitcode)) {
+ *status = (int)((waitcode & 0xff) << 8);
+ CloseHandle(hProcess);
+ return pid;
+ }
+ }
+ CloseHandle(hProcess);
+ }
+ else
+ errno = ECHILD;
+ }
}
return retval >= 0 ? pid : retval;
}
@@ -2758,8 +2758,8 @@ win32_sleep(unsigned int t)
dTHX;
/* Win32 times are in ms so *1000 in and /1000 out */
if (t > UINT_MAX / 1000) {
- Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
- "sleep(%lu) too large", t);
+ Perl_ck_warner(aTHX_ packWARN(WARN_OVERFLOW),
+ "sleep(%lu) too large", t);
}
return win32_msgwait(aTHX_ 0, NULL, t * 1000, NULL) / 1000;
}
@@ -2790,15 +2790,15 @@ win32_alarm(unsigned int sec)
if (w32_message_hwnd == NULL)
w32_timerid = SetTimer(NULL, w32_timerid, sec*1000, NULL);
else {
- w32_timerid = 1;
+ w32_timerid = 1;
SetTimer(w32_message_hwnd, w32_timerid, sec*1000, NULL);
}
}
else {
- if (w32_timerid) {
+ if (w32_timerid) {
KillTimer(w32_message_hwnd, w32_timerid);
- w32_timerid = 0;
- }
+ w32_timerid = 0;
+ }
}
return 0;
}
@@ -2831,29 +2831,29 @@ win32_flock(int fd, int oper)
switch(oper) {
case LOCK_SH: /* shared lock */
- if (LockFileEx(fh, 0, 0, LK_LEN, 0, &o))
+ if (LockFileEx(fh, 0, 0, LK_LEN, 0, &o))
i = 0;
- break;
+ break;
case LOCK_EX: /* exclusive lock */
- if (LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o))
+ if (LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o))
i = 0;
- break;
+ break;
case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
- if (LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o))
+ if (LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o))
i = 0;
- break;
+ break;
case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
- if (LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
- 0, LK_LEN, 0, &o))
+ if (LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
+ 0, LK_LEN, 0, &o))
i = 0;
- break;
+ break;
case LOCK_UN: /* unlock lock */
- if (UnlockFileEx(fh, 0, LK_LEN, 0, &o))
+ if (UnlockFileEx(fh, 0, LK_LEN, 0, &o))
i = 0;
- break;
+ break;
default: /* unknown */
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
if (i == -1) {
if (GetLastError() == ERROR_LOCK_VIOLATION)
@@ -2951,30 +2951,30 @@ win32_strerror(int e)
if (e < 0 || e > sys_nerr) {
dTHXa(NULL);
- if (e < 0)
- e = GetLastError();
+ if (e < 0)
+ e = GetLastError();
#ifdef ERRNO_HAS_POSIX_SUPPLEMENT
- /* VC10+ and some MinGW/gcc-4.8+ define a "POSIX supplement" of errno
- * values ranging from EADDRINUSE (100) to EWOULDBLOCK (140), but
- * sys_nerr is still 43 and strerror() returns "Unknown error" for them.
- * We must therefore still roll our own messages for these codes, and
- * additionally map them to corresponding Windows (sockets) error codes
- * first to avoid getting the wrong system message.
- */
- else if (inRANGE(e, EADDRINUSE, EWOULDBLOCK)) {
- e = convert_errno_to_wsa_error(e);
- }
+ /* VC10+ and some MinGW/gcc-4.8+ define a "POSIX supplement" of errno
+ * values ranging from EADDRINUSE (100) to EWOULDBLOCK (140), but
+ * sys_nerr is still 43 and strerror() returns "Unknown error" for them.
+ * We must therefore still roll our own messages for these codes, and
+ * additionally map them to corresponding Windows (sockets) error codes
+ * first to avoid getting the wrong system message.
+ */
+ else if (inRANGE(e, EADDRINUSE, EWOULDBLOCK)) {
+ e = convert_errno_to_wsa_error(e);
+ }
#endif
- aTHXa(PERL_GET_THX);
- if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
+ aTHXa(PERL_GET_THX);
+ if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, e, 0,
- w32_strerror_buffer, sizeof(w32_strerror_buffer),
+ w32_strerror_buffer, sizeof(w32_strerror_buffer),
NULL) == 0)
{
- strcpy(w32_strerror_buffer, "Unknown Error");
+ strcpy(w32_strerror_buffer, "Unknown Error");
}
- return w32_strerror_buffer;
+ return w32_strerror_buffer;
}
#undef strerror
return strerror(e);
@@ -2987,29 +2987,29 @@ win32_str_os_error(void *sv, DWORD dwErr)
DWORD dwLen;
char *sMsg;
dwLen = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER
- |FORMAT_MESSAGE_IGNORE_INSERTS
- |FORMAT_MESSAGE_FROM_SYSTEM, NULL,
- dwErr, 0, (char *)&sMsg, 1, NULL);
+ |FORMAT_MESSAGE_IGNORE_INSERTS
+ |FORMAT_MESSAGE_FROM_SYSTEM, NULL,
+ dwErr, 0, (char *)&sMsg, 1, NULL);
/* strip trailing whitespace and period */
if (0 < dwLen) {
- do {
- --dwLen; /* dwLen doesn't include trailing null */
- } while (0 < dwLen && isSPACE(sMsg[dwLen]));
- if ('.' != sMsg[dwLen])
- dwLen++;
- sMsg[dwLen] = '\0';
+ do {
+ --dwLen; /* dwLen doesn't include trailing null */
+ } while (0 < dwLen && isSPACE(sMsg[dwLen]));
+ if ('.' != sMsg[dwLen])
+ dwLen++;
+ sMsg[dwLen] = '\0';
}
if (0 == dwLen) {
- sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/);
- if (sMsg)
- dwLen = sprintf(sMsg,
- "Unknown error #0x%lX (lookup 0x%lX)",
- dwErr, GetLastError());
+ sMsg = (char*)LocalAlloc(0, 64/**sizeof(TCHAR)*/);
+ if (sMsg)
+ dwLen = sprintf(sMsg,
+ "Unknown error #0x%lX (lookup 0x%lX)",
+ dwErr, GetLastError());
}
if (sMsg) {
- dTHX;
- sv_setpvn((SV*)sv, sMsg, dwLen);
- LocalFree(sMsg);
+ dTHX;
+ sv_setpvn((SV*)sv, sMsg, dwLen);
+ LocalFree(sMsg);
}
}
@@ -3064,16 +3064,16 @@ win32_fopen(const char *filename, const char *mode)
FILE *f;
if (!*filename)
- return NULL;
+ return NULL;
if (stricmp(filename, "/dev/null")==0)
- filename = "NUL";
+ filename = "NUL";
aTHXa(PERL_GET_THX);
f = fopen(PerlDir_mapA(filename), mode);
/* avoid buffering headaches for child processes */
if (f && *mode == 'a')
- win32_fseek(f, 0, SEEK_END);
+ win32_fseek(f, 0, SEEK_END);
return f;
}
@@ -3084,7 +3084,7 @@ win32_fdopen(int handle, const char *mode)
f = fdopen(handle, (char *) mode);
/* avoid buffering headaches for child processes */
if (f && *mode == 'a')
- win32_fseek(f, 0, SEEK_END);
+ win32_fseek(f, 0, SEEK_END);
return f;
}
@@ -3093,7 +3093,7 @@ win32_freopen(const char *path, const char *mode, FILE *stream)
{
dTHXa(NULL);
if (stricmp(path, "/dev/null")==0)
- path = "NUL";
+ path = "NUL";
aTHXa(PERL_GET_THX);
return freopen(PerlDir_mapA(path), mode, stream);
@@ -3157,7 +3157,7 @@ win32_ftell(FILE *pf)
{
fpos_t pos;
if (fgetpos(pf, &pos))
- return -1;
+ return -1;
return (Off_t)pos;
}
@@ -3167,20 +3167,20 @@ win32_fseek(FILE *pf, Off_t offset,int origin)
fpos_t pos;
switch (origin) {
case SEEK_CUR:
- if (fgetpos(pf, &pos))
- return -1;
- offset += pos;
- break;
+ if (fgetpos(pf, &pos))
+ return -1;
+ offset += pos;
+ break;
case SEEK_END:
- fseek(pf, 0, SEEK_END);
- pos = _telli64(fileno(pf));
- offset += pos;
- break;
+ fseek(pf, 0, SEEK_END);
+ pos = _telli64(fileno(pf));
+ offset += pos;
+ break;
case SEEK_SET:
- break;
+ break;
default:
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
return fsetpos(pf, &offset);
}
@@ -3219,25 +3219,25 @@ win32_tmpfd_mode(int mode)
mode &= ~( O_ACCMODE | O_CREAT | O_EXCL );
mode |= O_RDWR;
if (len && len < MAX_PATH) {
- if (GetTempFileName(prefix, "plx", 0, filename)) {
- HANDLE fh = CreateFile(filename,
- DELETE | GENERIC_READ | GENERIC_WRITE,
- 0,
- NULL,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL
- | FILE_FLAG_DELETE_ON_CLOSE,
- NULL);
- if (fh != INVALID_HANDLE_VALUE) {
- int fd = win32_open_osfhandle((intptr_t)fh, mode);
- if (fd >= 0) {
- PERL_DEB(dTHX;)
- DEBUG_p(PerlIO_printf(Perl_debug_log,
- "Created tmpfile=%s\n",filename));
- return fd;
- }
- }
- }
+ if (GetTempFileName(prefix, "plx", 0, filename)) {
+ HANDLE fh = CreateFile(filename,
+ DELETE | GENERIC_READ | GENERIC_WRITE,
+ 0,
+ NULL,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL
+ | FILE_FLAG_DELETE_ON_CLOSE,
+ NULL);
+ if (fh != INVALID_HANDLE_VALUE) {
+ int fd = win32_open_osfhandle((intptr_t)fh, mode);
+ if (fd >= 0) {
+ PERL_DEB(dTHX;)
+ DEBUG_p(PerlIO_printf(Perl_debug_log,
+ "Created tmpfile=%s\n",filename));
+ return fd;
+ }
+ }
+ }
}
return -1;
}
@@ -3247,7 +3247,7 @@ win32_tmpfile(void)
{
int fd = win32_tmpfd();
if (fd >= 0)
- return win32_fdopen(fd, "w+b");
+ return win32_fdopen(fd, "w+b");
return NULL;
}
@@ -3297,13 +3297,13 @@ do_popen(const char *mode, const char *command, IV narg, SV **args) {
stdfd = 0; /* stdin */
parent = 1;
child = 0;
- nhandle = STD_INPUT_HANDLE;
+ nhandle = STD_INPUT_HANDLE;
}
else if (strchr(mode,'r')) {
stdfd = 1; /* stdout */
parent = 0;
child = 1;
- nhandle = STD_OUTPUT_HANDLE;
+ nhandle = STD_OUTPUT_HANDLE;
}
else
return NULL;
@@ -3336,44 +3336,44 @@ do_popen(const char *mode, const char *command, IV narg, SV **args) {
/* CreateProcess() requires inheritable handles */
if (!SetHandleInformation((HANDLE)_get_osfhandle(p[child]), HANDLE_FLAG_INHERIT,
- HANDLE_FLAG_INHERIT)) {
+ HANDLE_FLAG_INHERIT)) {
goto cleanup;
}
/* start the child */
{
- dTHX;
-
- if (command) {
- if ((childpid = do_spawn2_handles(aTHX_ command, EXECF_SPAWN_NOWAIT, handles)) == -1)
- goto cleanup;
-
- }
- else {
- int i;
- const char *exe_name;
+ dTHX;
- Newx(args_pvs, narg + 1 + w32_perlshell_items, const char *);
- SAVEFREEPV(args_pvs);
- for (i = 0; i < narg; ++i)
- args_pvs[i] = SvPV_nolen(args[i]);
- args_pvs[i] = NULL;
- exe_name = qualified_path(args_pvs[0], TRUE);
- if (!exe_name)
- /* let CreateProcess() try to find it instead */
- exe_name = args_pvs[0];
+ if (command) {
+ if ((childpid = do_spawn2_handles(aTHX_ command, EXECF_SPAWN_NOWAIT, handles)) == -1)
+ goto cleanup;
- if ((childpid = do_spawnvp_handles(P_NOWAIT, exe_name, args_pvs, handles)) == -1) {
- goto cleanup;
- }
- }
+ }
+ else {
+ int i;
+ const char *exe_name;
+
+ Newx(args_pvs, narg + 1 + w32_perlshell_items, const char *);
+ SAVEFREEPV(args_pvs);
+ for (i = 0; i < narg; ++i)
+ args_pvs[i] = SvPV_nolen(args[i]);
+ args_pvs[i] = NULL;
+ exe_name = qualified_path(args_pvs[0], TRUE);
+ if (!exe_name)
+ /* let CreateProcess() try to find it instead */
+ exe_name = args_pvs[0];
+
+ if ((childpid = do_spawnvp_handles(P_NOWAIT, exe_name, args_pvs, handles)) == -1) {
+ goto cleanup;
+ }
+ }
- win32_close(p[child]);
+ win32_close(p[child]);
- sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
+ sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid);
- /* set process id so that it can be returned by perl's open() */
- PL_forkprocess = childpid;
+ /* set process id so that it can be returned by perl's open() */
+ PL_forkprocess = childpid;
}
/* we have an fd, return a file stream */
@@ -3420,12 +3420,12 @@ win32_pclose(PerlIO *pf)
sv = *av_fetch(w32_fdpid, PerlIO_fileno(pf), TRUE);
if (SvIOK(sv))
- childpid = SvIVX(sv);
+ childpid = SvIVX(sv);
else
- childpid = 0;
+ childpid = 0;
if (!childpid) {
- errno = EBADF;
+ errno = EBADF;
return -1;
}
@@ -3453,10 +3453,10 @@ win32_link(const char *oldname, const char *newname)
if (MultiByteToWideChar(CP_ACP, 0, oldname, -1, wOldName, MAX_PATH+1) &&
MultiByteToWideChar(CP_ACP, 0, newname, -1, wNewName, MAX_PATH+1) &&
- ((aTHXa(PERL_GET_THX)), wcscpy(wOldName, PerlDir_mapW(wOldName)),
+ ((aTHXa(PERL_GET_THX)), wcscpy(wOldName, PerlDir_mapW(wOldName)),
CreateHardLinkW(PerlDir_mapW(wNewName), wOldName, NULL)))
{
- return 0;
+ return 0;
}
translate_to_errno();
return -1;
@@ -3623,37 +3623,37 @@ win32_chsize(int fd, Off_t size)
cur = win32_tell(fd);
if (cur < 0)
- return -1;
+ return -1;
end = win32_lseek(fd, 0, SEEK_END);
if (end < 0)
- return -1;
+ return -1;
extend = size - end;
if (extend == 0) {
- /* do nothing */
+ /* do nothing */
}
else if (extend > 0) {
- /* must grow the file, padding with nulls */
- char b[4096];
- int oldmode = win32_setmode(fd, O_BINARY);
- size_t count;
- memset(b, '\0', sizeof(b));
- do {
- count = extend >= sizeof(b) ? sizeof(b) : (size_t)extend;
- count = win32_write(fd, b, count);
- if ((int)count < 0) {
- retval = -1;
- break;
- }
- } while ((extend -= count) > 0);
- win32_setmode(fd, oldmode);
+ /* must grow the file, padding with nulls */
+ char b[4096];
+ int oldmode = win32_setmode(fd, O_BINARY);
+ size_t count;
+ memset(b, '\0', sizeof(b));
+ do {
+ count = extend >= sizeof(b) ? sizeof(b) : (size_t)extend;
+ count = win32_write(fd, b, count);
+ if ((int)count < 0) {
+ retval = -1;
+ break;
+ }
+ } while ((extend -= count) > 0);
+ win32_setmode(fd, oldmode);
}
else {
- /* shrink the file */
- win32_lseek(fd, size, SEEK_SET);
- if (!SetEndOfFile((HANDLE)_get_osfhandle(fd))) {
- errno = EACCES;
- retval = -1;
- }
+ /* shrink the file */
+ win32_lseek(fd, size, SEEK_SET);
+ if (!SetEndOfFile((HANDLE)_get_osfhandle(fd))) {
+ errno = EACCES;
+ retval = -1;
+ }
}
win32_lseek(fd, cur, SEEK_SET);
return retval;
@@ -3683,7 +3683,7 @@ win32_open(const char *path, int flag, ...)
va_end(ap);
if (stricmp(path, "/dev/null")==0)
- path = "NUL";
+ path = "NUL";
aTHXa(PERL_GET_THX);
return open(PerlDir_mapA(path), flag, pmode);
@@ -3771,8 +3771,8 @@ DllExport int
win32_chdir(const char *dir)
{
if (!dir || !*dir) {
- errno = ENOENT;
- return -1;
+ errno = ENOENT;
+ return -1;
}
return chdir(dir);
}
@@ -3807,7 +3807,7 @@ create_command_line(char *cname, STRLEN clen, const char * const *args)
bool quote_next = FALSE;
if (!cname)
- cname = (char*)args[0];
+ cname = (char*)args[0];
/* The NT cmd.exe shell has the following peculiarity that needs to be
* worked around. It strips a leading and trailing dquote when any
@@ -3825,44 +3825,44 @@ create_command_line(char *cname, STRLEN clen, const char * const *args)
* always, making for the convolutions below :-(
*/
if (cname) {
- if (!clen)
- clen = strlen(cname);
-
- if (clen > 4
- && (stricmp(&cname[clen-4], ".bat") == 0
- || (stricmp(&cname[clen-4], ".cmd") == 0)))
- {
- bat_file = TRUE;
+ if (!clen)
+ clen = strlen(cname);
+
+ if (clen > 4
+ && (stricmp(&cname[clen-4], ".bat") == 0
+ || (stricmp(&cname[clen-4], ".cmd") == 0)))
+ {
+ bat_file = TRUE;
len += 3;
- }
- else {
- char *exe = strrchr(cname, '/');
- char *exe2 = strrchr(cname, '\\');
- if (exe2 > exe)
- exe = exe2;
- if (exe)
- ++exe;
- else
- exe = cname;
- if (stricmp(exe, "cmd.exe") == 0 || stricmp(exe, "cmd") == 0) {
- cmd_shell = TRUE;
- len += 3;
- }
- else if (stricmp(exe, "command.com") == 0
- || stricmp(exe, "command") == 0)
- {
- dumb_shell = TRUE;
- }
- }
+ }
+ else {
+ char *exe = strrchr(cname, '/');
+ char *exe2 = strrchr(cname, '\\');
+ if (exe2 > exe)
+ exe = exe2;
+ if (exe)
+ ++exe;
+ else
+ exe = cname;
+ if (stricmp(exe, "cmd.exe") == 0 || stricmp(exe, "cmd") == 0) {
+ cmd_shell = TRUE;
+ len += 3;
+ }
+ else if (stricmp(exe, "command.com") == 0
+ || stricmp(exe, "command") == 0)
+ {
+ dumb_shell = TRUE;
+ }
+ }
}
DEBUG_p(PerlIO_printf(Perl_debug_log, "Args "));
for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
- STRLEN curlen = strlen(arg);
- if (!(arg[0] == '"' && arg[curlen-1] == '"'))
- len += 2; /* assume quoting needed (worst case) */
- len += curlen + 1;
- DEBUG_p(PerlIO_printf(Perl_debug_log, "[%s]",arg));
+ STRLEN curlen = strlen(arg);
+ if (!(arg[0] == '"' && arg[curlen-1] == '"'))
+ len += 2; /* assume quoting needed (worst case) */
+ len += curlen + 1;
+ DEBUG_p(PerlIO_printf(Perl_debug_log, "[%s]",arg));
}
DEBUG_p(PerlIO_printf(Perl_debug_log, "\n"));
@@ -3871,76 +3871,76 @@ create_command_line(char *cname, STRLEN clen, const char * const *args)
ptr = cmd;
if (bat_file) {
- *ptr++ = '"';
- extra_quotes = TRUE;
+ *ptr++ = '"';
+ extra_quotes = TRUE;
}
for (index = 0; (arg = (char*)args[index]) != NULL; ++index) {
- bool do_quote = 0;
- STRLEN curlen = strlen(arg);
-
- /* we want to protect empty arguments and ones with spaces with
- * dquotes, but only if they aren't already there */
- if (!dumb_shell) {
- if (!curlen) {
- do_quote = 1;
- }
- else if (quote_next) {
- /* see if it really is multiple arguments pretending to
- * be one and force a set of quotes around it */
- if (*find_next_space(arg))
- do_quote = 1;
- }
- else if (!(arg[0] == '"' && curlen > 1 && arg[curlen-1] == '"')) {
- STRLEN i = 0;
- while (i < curlen) {
- if (isSPACE(arg[i])) {
- do_quote = 1;
- }
- else if (arg[i] == '"') {
- do_quote = 0;
- break;
- }
- i++;
- }
- }
- }
-
- if (do_quote)
- *ptr++ = '"';
-
- strcpy(ptr, arg);
- ptr += curlen;
-
- if (do_quote)
- *ptr++ = '"';
-
- if (args[index+1])
- *ptr++ = ' ';
-
- if (!extra_quotes
- && cmd_shell
- && curlen >= 2
- && *arg == '/' /* see if arg is "/c", "/x/c", "/x/d/c" etc. */
- && stricmp(arg+curlen-2, "/c") == 0)
- {
- /* is there a next argument? */
- if (args[index+1]) {
- /* are there two or more next arguments? */
- if (args[index+2]) {
- *ptr++ = '"';
- extra_quotes = TRUE;
- }
- else {
- /* single argument, force quoting if it has spaces */
- quote_next = TRUE;
- }
- }
- }
+ bool do_quote = 0;
+ STRLEN curlen = strlen(arg);
+
+ /* we want to protect empty arguments and ones with spaces with
+ * dquotes, but only if they aren't already there */
+ if (!dumb_shell) {
+ if (!curlen) {
+ do_quote = 1;
+ }
+ else if (quote_next) {
+ /* see if it really is multiple arguments pretending to
+ * be one and force a set of quotes around it */
+ if (*find_next_space(arg))
+ do_quote = 1;
+ }
+ else if (!(arg[0] == '"' && curlen > 1 && arg[curlen-1] == '"')) {
+ STRLEN i = 0;
+ while (i < curlen) {
+ if (isSPACE(arg[i])) {
+ do_quote = 1;
+ }
+ else if (arg[i] == '"') {
+ do_quote = 0;
+ break;
+ }
+ i++;
+ }
+ }
+ }
+
+ if (do_quote)
+ *ptr++ = '"';
+
+ strcpy(ptr, arg);
+ ptr += curlen;
+
+ if (do_quote)
+ *ptr++ = '"';
+
+ if (args[index+1])
+ *ptr++ = ' ';
+
+ if (!extra_quotes
+ && cmd_shell
+ && curlen >= 2
+ && *arg == '/' /* see if arg is "/c", "/x/c", "/x/d/c" etc. */
+ && stricmp(arg+curlen-2, "/c") == 0)
+ {
+ /* is there a next argument? */
+ if (args[index+1]) {
+ /* are there two or more next arguments? */
+ if (args[index+2]) {
+ *ptr++ = '"';
+ extra_quotes = TRUE;
+ }
+ else {
+ /* single argument, force quoting if it has spaces */
+ quote_next = TRUE;
+ }
+ }
+ }
}
if (extra_quotes)
- *ptr++ = '"';
+ *ptr++ = '"';
*ptr = '\0';
@@ -3963,19 +3963,19 @@ qualified_path(const char *cmd, bool other_exts)
int has_slash = 0;
if (!cmd)
- return NULL;
+ return NULL;
fullcmd = (char*)cmd;
while (*fullcmd) {
- if (*fullcmd == '/' || *fullcmd == '\\')
- has_slash++;
- fullcmd++;
- cmdlen++;
+ if (*fullcmd == '/' || *fullcmd == '\\')
+ has_slash++;
+ fullcmd++;
+ cmdlen++;
}
/* look in PATH */
{
- dTHX;
- pathstr = PerlEnv_getenv("PATH");
+ dTHX;
+ pathstr = PerlEnv_getenv("PATH");
}
/* worst case: PATH is a single directory; we need additional space
* to append "/", ".exe" and trailing "\0" */
@@ -3983,65 +3983,65 @@ qualified_path(const char *cmd, bool other_exts)
curfullcmd = fullcmd;
while (1) {
- DWORD res;
-
- /* start by appending the name to the current prefix */
- strcpy(curfullcmd, cmd);
- curfullcmd += cmdlen;
-
- /* if it doesn't end with '.', or has no extension, try adding
- * a trailing .exe first */
- if (cmd[cmdlen-1] != '.'
- && (cmdlen < 4 || cmd[cmdlen-4] != '.'))
- {
- int i;
- /* first extension is .exe */
- int ext_limit = other_exts ? C_ARRAY_LENGTH(exe_extensions) : 1;
- for (i = 0; i < ext_limit; ++i) {
- strcpy(curfullcmd, exe_extensions[i]);
- res = GetFileAttributes(fullcmd);
- if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
- return fullcmd;
- }
-
- *curfullcmd = '\0';
- }
-
- /* that failed, try the bare name */
- res = GetFileAttributes(fullcmd);
- if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
- return fullcmd;
-
- /* quit if no other path exists, or if cmd already has path */
- if (!pathstr || !*pathstr || has_slash)
- break;
-
- /* skip leading semis */
- while (*pathstr == ';')
- pathstr++;
-
- /* build a new prefix from scratch */
- curfullcmd = fullcmd;
- while (*pathstr && *pathstr != ';') {
- if (*pathstr == '"') { /* foo;"baz;etc";bar */
- pathstr++; /* skip initial '"' */
- while (*pathstr && *pathstr != '"') {
+ DWORD res;
+
+ /* start by appending the name to the current prefix */
+ strcpy(curfullcmd, cmd);
+ curfullcmd += cmdlen;
+
+ /* if it doesn't end with '.', or has no extension, try adding
+ * a trailing .exe first */
+ if (cmd[cmdlen-1] != '.'
+ && (cmdlen < 4 || cmd[cmdlen-4] != '.'))
+ {
+ int i;
+ /* first extension is .exe */
+ int ext_limit = other_exts ? C_ARRAY_LENGTH(exe_extensions) : 1;
+ for (i = 0; i < ext_limit; ++i) {
+ strcpy(curfullcmd, exe_extensions[i]);
+ res = GetFileAttributes(fullcmd);
+ if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
+ return fullcmd;
+ }
+
+ *curfullcmd = '\0';
+ }
+
+ /* that failed, try the bare name */
+ res = GetFileAttributes(fullcmd);
+ if (res != 0xFFFFFFFF && !(res & FILE_ATTRIBUTE_DIRECTORY))
+ return fullcmd;
+
+ /* quit if no other path exists, or if cmd already has path */
+ if (!pathstr || !*pathstr || has_slash)
+ break;
+
+ /* skip leading semis */
+ while (*pathstr == ';')
+ pathstr++;
+
+ /* build a new prefix from scratch */
+ curfullcmd = fullcmd;
+ while (*pathstr && *pathstr != ';') {
+ if (*pathstr == '"') { /* foo;"baz;etc";bar */
+ pathstr++; /* skip initial '"' */
+ while (*pathstr && *pathstr != '"') {
*curfullcmd++ = *pathstr++;
- }
- if (*pathstr)
- pathstr++; /* skip trailing '"' */
- }
- else {
+ }
+ if (*pathstr)
+ pathstr++; /* skip trailing '"' */
+ }
+ else {
*curfullcmd++ = *pathstr++;
- }
- }
- if (*pathstr)
- pathstr++; /* skip trailing semi */
- if (curfullcmd > fullcmd /* append a dir separator */
- && curfullcmd[-1] != '/' && curfullcmd[-1] != '\\')
- {
- *curfullcmd++ = '\\';
- }
+ }
+ }
+ if (*pathstr)
+ pathstr++; /* skip trailing semi */
+ if (curfullcmd > fullcmd /* append a dir separator */
+ && curfullcmd[-1] != '/' && curfullcmd[-1] != '\\')
+ {
+ *curfullcmd++ = '\\';
+ }
}
Safefree(fullcmd);
@@ -4072,15 +4072,15 @@ win32_clearenv(void)
char *cur = envv;
STRLEN len;
while (*cur) {
- char *end = strchr(cur,'=');
- if (end && end != cur) {
- *end = '\0';
- SetEnvironmentVariable(cur, NULL);
- *end = '=';
- cur = end + strlen(end+1)+2;
- }
- else if ((len = strlen(cur)))
- cur += len+1;
+ char *end = strchr(cur,'=');
+ if (end && end != cur) {
+ *end = '\0';
+ SetEnvironmentVariable(cur, NULL);
+ *end = '=';
+ cur = end + strlen(end+1)+2;
+ }
+ else if ((len = strlen(cur)))
+ cur += len+1;
}
FreeEnvironmentStrings(envv);
}
@@ -4142,21 +4142,21 @@ do_spawnvp_handles(int mode, const char *cmdname, const char *const *argv,
STRLEN clen = 0;
if (cname) {
- clen = strlen(cname);
- /* if command name contains dquotes, must remove them */
- if (strchr(cname, '"')) {
- cmd = cname;
- Newx(cname,clen+1,char);
- clen = 0;
- while (*cmd) {
- if (*cmd != '"') {
- cname[clen] = *cmd;
- ++clen;
- }
- ++cmd;
- }
- cname[clen] = '\0';
- }
+ clen = strlen(cname);
+ /* if command name contains dquotes, must remove them */
+ if (strchr(cname, '"')) {
+ cmd = cname;
+ Newx(cname,clen+1,char);
+ clen = 0;
+ while (*cmd) {
+ if (*cmd != '"') {
+ cname[clen] = *cmd;
+ ++clen;
+ }
+ ++cmd;
+ }
+ cname[clen] = '\0';
+ }
}
cmd = create_command_line(cname, clen, argv);
@@ -4167,23 +4167,23 @@ do_spawnvp_handles(int mode, const char *cmdname, const char *const *argv,
switch(mode) {
case P_NOWAIT: /* asynch + remember result */
- if (w32_num_children >= MAXIMUM_WAIT_OBJECTS) {
- errno = EAGAIN;
- ret = -1;
- goto RETVAL;
- }
- /* Create a new process group so we can use GenerateConsoleCtrlEvent()
- * in win32_kill()
- */
+ if (w32_num_children >= MAXIMUM_WAIT_OBJECTS) {
+ errno = EAGAIN;
+ ret = -1;
+ goto RETVAL;
+ }
+ /* Create a new process group so we can use GenerateConsoleCtrlEvent()
+ * in win32_kill()
+ */
create |= CREATE_NEW_PROCESS_GROUP;
- /* FALL THROUGH */
+ /* FALL THROUGH */
case P_WAIT: /* synchronous execution */
- break;
+ break;
default: /* invalid mode */
- errno = EINVAL;
- ret = -1;
- goto RETVAL;
+ errno = EINVAL;
+ ret = -1;
+ goto RETVAL;
}
memset(&StartupInfo,0,sizeof(StartupInfo));
@@ -4204,15 +4204,15 @@ do_spawnvp_handles(int mode, const char *cmdname, const char *const *argv,
StartupInfo.hStdOutput = handles && handles[1] != -1 ?
(HANDLE)_get_osfhandle(handles[1]) : tbl.childStdOut;
StartupInfo.hStdError = handles && handles[2] != -1 ?
- (HANDLE)_get_osfhandle(handles[2]) : tbl.childStdErr;
+ (HANDLE)_get_osfhandle(handles[2]) : tbl.childStdErr;
if (StartupInfo.hStdInput == INVALID_HANDLE_VALUE &&
- StartupInfo.hStdOutput == INVALID_HANDLE_VALUE &&
- StartupInfo.hStdError == INVALID_HANDLE_VALUE)
+ StartupInfo.hStdOutput == INVALID_HANDLE_VALUE &&
+ StartupInfo.hStdError == INVALID_HANDLE_VALUE)
{
- create |= CREATE_NEW_CONSOLE;
+ create |= CREATE_NEW_CONSOLE;
}
else {
- StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
+ StartupInfo.dwFlags |= STARTF_USESTDHANDLES;
}
if (w32_use_showwindow) {
StartupInfo.dwFlags |= STARTF_USESHOWWINDOW;
@@ -4220,59 +4220,59 @@ do_spawnvp_handles(int mode, const char *cmdname, const char *const *argv,
}
DEBUG_p(PerlIO_printf(Perl_debug_log, "Spawning [%s] with [%s]\n",
- cname,cmd));
+ cname,cmd));
RETRY:
if (!CreateProcess(cname, /* search PATH to find executable */
- cmd, /* executable, and its arguments */
- NULL, /* process attributes */
- NULL, /* thread attributes */
- TRUE, /* inherit handles */
- create, /* creation flags */
- (LPVOID)env, /* inherit environment */
- dir, /* inherit cwd */
- &StartupInfo,
- &ProcessInformation))
+ cmd, /* executable, and its arguments */
+ NULL, /* process attributes */
+ NULL, /* thread attributes */
+ TRUE, /* inherit handles */
+ create, /* creation flags */
+ (LPVOID)env, /* inherit environment */
+ dir, /* inherit cwd */
+ &StartupInfo,
+ &ProcessInformation))
{
- /* initial NULL argument to CreateProcess() does a PATH
- * search, but it always first looks in the directory
- * where the current process was started, which behavior
- * is undesirable for backward compatibility. So we
- * jump through our own hoops by picking out the path
- * we really want it to use. */
- if (!fullcmd) {
- fullcmd = qualified_path(cname, FALSE);
- if (fullcmd) {
- if (cname != cmdname)
- Safefree(cname);
- cname = fullcmd;
- DEBUG_p(PerlIO_printf(Perl_debug_log,
- "Retrying [%s] with same args\n",
- cname));
- goto RETRY;
- }
- }
- errno = ENOENT;
- ret = -1;
- goto RETVAL;
+ /* initial NULL argument to CreateProcess() does a PATH
+ * search, but it always first looks in the directory
+ * where the current process was started, which behavior
+ * is undesirable for backward compatibility. So we
+ * jump through our own hoops by picking out the path
+ * we really want it to use. */
+ if (!fullcmd) {
+ fullcmd = qualified_path(cname, FALSE);
+ if (fullcmd) {
+ if (cname != cmdname)
+ Safefree(cname);
+ cname = fullcmd;
+ DEBUG_p(PerlIO_printf(Perl_debug_log,
+ "Retrying [%s] with same args\n",
+ cname));
+ goto RETRY;
+ }
+ }
+ errno = ENOENT;
+ ret = -1;
+ goto RETVAL;
}
if (mode == P_NOWAIT) {
- /* asynchronous spawn -- store handle, return PID */
- ret = (int)ProcessInformation.dwProcessId;
+ /* asynchronous spawn -- store handle, return PID */
+ ret = (int)ProcessInformation.dwProcessId;
- w32_child_handles[w32_num_children] = ProcessInformation.hProcess;
- w32_child_pids[w32_num_children] = (DWORD)ret;
- ++w32_num_children;
+ w32_child_handles[w32_num_children] = ProcessInformation.hProcess;
+ w32_child_pids[w32_num_children] = (DWORD)ret;
+ ++w32_num_children;
}
else {
- DWORD status;
- win32_msgwait(aTHX_ 1, &ProcessInformation.hProcess, INFINITE, NULL);
- /* FIXME: if msgwait returned due to message perhaps forward the
- "signal" to the process
+ DWORD status;
+ win32_msgwait(aTHX_ 1, &ProcessInformation.hProcess, INFINITE, NULL);
+ /* FIXME: if msgwait returned due to message perhaps forward the
+ "signal" to the process
*/
- GetExitCodeProcess(ProcessInformation.hProcess, &status);
- ret = (int)status;
- CloseHandle(ProcessInformation.hProcess);
+ GetExitCodeProcess(ProcessInformation.hProcess, &status);
+ ret = (int)status;
+ CloseHandle(ProcessInformation.hProcess);
}
CloseHandle(ProcessInformation.hThread);
@@ -4282,7 +4282,7 @@ RETVAL:
PerlEnv_free_childdir(dir);
Safefree(cmd);
if (cname != cmdname)
- Safefree(cname);
+ Safefree(cname);
return ret;
}
@@ -4294,7 +4294,7 @@ win32_execv(const char *cmdname, const char *const *argv)
/* if this is a pseudo-forked child, we just want to spawn
* the new program, and return */
if (w32_pseudo_id)
- return _spawnv(P_WAIT, cmdname, argv);
+ return _spawnv(P_WAIT, cmdname, argv);
#endif
return _execv(cmdname, argv);
}
@@ -4307,13 +4307,13 @@ win32_execvp(const char *cmdname, const char *const *argv)
/* if this is a pseudo-forked child, we just want to spawn
* the new program, and return */
if (w32_pseudo_id) {
- int status = win32_spawnvp(P_WAIT, cmdname, (const char *const *)argv);
- if (status != -1) {
- my_exit(status);
- return 0;
- }
- else
- return status;
+ int status = win32_spawnvp(P_WAIT, cmdname, (const char *const *)argv);
+ if (status != -1) {
+ my_exit(status);
+ return 0;
+ }
+ else
+ return status;
}
#endif
return _execvp(cmdname, argv);
@@ -4536,17 +4536,17 @@ win32_fdupopen(FILE *pf)
/* open the file in the same mode */
if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RD) {
- mode[0] = 'r';
- mode[1] = 0;
+ mode[0] = 'r';
+ mode[1] = 0;
}
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_WR) {
- mode[0] = 'a';
- mode[1] = 0;
+ mode[0] = 'a';
+ mode[1] = 0;
}
else if (PERLIO_FILE_flag(pf) & PERLIO_FILE_flag_RW) {
- mode[0] = 'r';
- mode[1] = '+';
- mode[2] = 0;
+ mode[0] = 'r';
+ mode[1] = '+';
+ mode[2] = 0;
}
/* it appears that the binmode is attached to the
@@ -4557,7 +4557,7 @@ win32_fdupopen(FILE *pf)
/* move the file pointer to the same position */
if (!fgetpos(pf, &pos)) {
- fsetpos(pfdup, &pos);
+ fsetpos(pfdup, &pos);
}
return pfdup;
}
@@ -4573,17 +4573,17 @@ win32_dynaload(const char* filename)
* so turn 'em back. */
first = strchr(filename, '/');
if (first) {
- STRLEN len = strlen(filename);
- if (len <= MAX_PATH) {
- strcpy(buf, filename);
- filename = &buf[first - filename];
- while (*filename) {
- if (*filename == '/')
- *(char*)filename = '\\';
- ++filename;
- }
- filename = buf;
- }
+ STRLEN len = strlen(filename);
+ if (len <= MAX_PATH) {
+ strcpy(buf, filename);
+ filename = &buf[first - filename];
+ while (*filename) {
+ if (*filename == '/')
+ *(char*)filename = '\\';
+ ++filename;
+ }
+ filename = buf;
+ }
}
aTHXa(PERL_GET_THX);
return LoadLibraryExA(PerlDir_mapA(filename), NULL, LOAD_WITH_ALTERED_SEARCH_PATH);
@@ -4597,7 +4597,7 @@ XS(w32_SetChildShowWindow)
unsigned short showwindow = w32_showwindow;
if (items > 1)
- croak_xs_usage(cv, "[showwindow]");
+ croak_xs_usage(cv, "[showwindow]");
if (items == 0 || !SvOK(ST(0)))
w32_use_showwindow = FALSE;
@@ -4628,16 +4628,16 @@ XS(w32_GetCwd)
* else return 'undef'
*/
if (ptr) {
- SV *sv = sv_newmortal();
- sv_setpv(sv, ptr);
- PerlEnv_free_childdir(ptr);
+ SV *sv = sv_newmortal();
+ sv_setpv(sv, ptr);
+ PerlEnv_free_childdir(ptr);
#ifndef INCOMPLETE_TAINTS
- SvTAINTED_on(sv);
+ SvTAINTED_on(sv);
#endif
- ST(0) = sv;
- XSRETURN(1);
+ ST(0) = sv;
+ XSRETURN(1);
}
XSRETURN_UNDEF;
}
@@ -4675,8 +4675,8 @@ win32_signal_context(void)
dTHX;
#ifdef MULTIPLICITY
if (!my_perl) {
- my_perl = PL_curinterp;
- PERL_SET_THX(my_perl);
+ my_perl = PL_curinterp;
+ PERL_SET_THX(my_perl);
}
return my_perl;
#else
@@ -4692,7 +4692,7 @@ win32_ctrlhandler(DWORD dwCtrlType)
dTHXa(PERL_GET_SIG_CONTEXT);
if (!my_perl)
- return FALSE;
+ return FALSE;
#endif
switch(dwCtrlType) {
@@ -4702,37 +4702,37 @@ win32_ctrlhandler(DWORD dwCtrlType)
console window's System menu, or by choosing the End Task command from the
Task List
*/
- if (do_raise(aTHX_ 1)) /* SIGHUP */
- sig_terminate(aTHX_ 1);
- return TRUE;
+ if (do_raise(aTHX_ 1)) /* SIGHUP */
+ sig_terminate(aTHX_ 1);
+ return TRUE;
case CTRL_C_EVENT:
- /* A CTRL+c signal was received */
- if (do_raise(aTHX_ SIGINT))
- sig_terminate(aTHX_ SIGINT);
- return TRUE;
+ /* A CTRL+c signal was received */
+ if (do_raise(aTHX_ SIGINT))
+ sig_terminate(aTHX_ SIGINT);
+ return TRUE;
case CTRL_BREAK_EVENT:
- /* A CTRL+BREAK signal was received */
- if (do_raise(aTHX_ SIGBREAK))
- sig_terminate(aTHX_ SIGBREAK);
- return TRUE;
+ /* A CTRL+BREAK signal was received */
+ if (do_raise(aTHX_ SIGBREAK))
+ sig_terminate(aTHX_ SIGBREAK);
+ return TRUE;
case CTRL_LOGOFF_EVENT:
/* A signal that the system sends to all console processes when a user is logging
off. This signal does not indicate which user is logging off, so no
assumptions can be made.
*/
- break;
+ break;
case CTRL_SHUTDOWN_EVENT:
/* A signal that the system sends to all console processes when the system is
shutting down.
*/
- if (do_raise(aTHX_ SIGTERM))
- sig_terminate(aTHX_ SIGTERM);
- return TRUE;
+ if (do_raise(aTHX_ SIGTERM))
+ sig_terminate(aTHX_ SIGTERM);
+ return TRUE;
default:
- break;
+ break;
}
return FALSE;
}
@@ -4869,13 +4869,13 @@ Perl_win32_init(int *argcp, char ***argvp)
#ifdef WIN32_DYN_IOINFO_SIZE
{
- Size_t ioinfo_size = _msize((void*)__pioinfo[0]);;
- if((SSize_t)ioinfo_size <= 0) { /* -1 is err */
- fprintf(stderr, "panic: invalid size for ioinfo\n"); /* no interp */
- exit(1);
- }
- ioinfo_size /= IOINFO_ARRAY_ELTS;
- w32_ioinfo_size = ioinfo_size;
+ Size_t ioinfo_size = _msize((void*)__pioinfo[0]);;
+ if((SSize_t)ioinfo_size <= 0) { /* -1 is err */
+ fprintf(stderr, "panic: invalid size for ioinfo\n"); /* no interp */
+ exit(1);
+ }
+ ioinfo_size /= IOINFO_ARRAY_ELTS;
+ w32_ioinfo_size = ioinfo_size;
}
#endif
@@ -4883,15 +4883,15 @@ Perl_win32_init(int *argcp, char ***argvp)
#ifndef WIN32_NO_REGISTRY
{
- LONG retval;
- retval = RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Perl", 0, KEY_READ, &HKCU_Perl_hnd);
- if (retval != ERROR_SUCCESS) {
- HKCU_Perl_hnd = NULL;
- }
- retval = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Perl", 0, KEY_READ, &HKLM_Perl_hnd);
- if (retval != ERROR_SUCCESS) {
- HKLM_Perl_hnd = NULL;
- }
+ LONG retval;
+ retval = RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Perl", 0, KEY_READ, &HKCU_Perl_hnd);
+ if (retval != ERROR_SUCCESS) {
+ HKCU_Perl_hnd = NULL;
+ }
+ retval = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Perl", 0, KEY_READ, &HKLM_Perl_hnd);
+ if (retval != ERROR_SUCCESS) {
+ HKLM_Perl_hnd = NULL;
+ }
}
#endif
@@ -4899,8 +4899,8 @@ Perl_win32_init(int *argcp, char ***argvp)
FILETIME ft;
if (!SystemTimeToFileTime(&time_t_epoch_base_systemtime,
&ft)) {
- fprintf(stderr, "panic: cannot convert base system time to filetime\n"); /* no interp */
- exit(1);
+ fprintf(stderr, "panic: cannot convert base system time to filetime\n"); /* no interp */
+ exit(1);
}
time_t_epoch_base_filetime.LowPart = ft.dwLowDateTime;
time_t_epoch_base_filetime.HighPart = ft.dwHighDateTime;
@@ -4938,28 +4938,28 @@ win32_signal(int sig, Sighandler_t subcode)
{
dTHXa(NULL);
if (sig < SIG_SIZE) {
- int save_errno = errno;
- Sighandler_t result;
+ int save_errno = errno;
+ Sighandler_t result;
#ifdef SET_INVALID_PARAMETER_HANDLER
- /* Silence our invalid parameter handler since we expect to make some
- * calls with invalid signal numbers giving a SIG_ERR result. */
- BOOL oldvalue = set_silent_invalid_parameter_handler(TRUE);
+ /* Silence our invalid parameter handler since we expect to make some
+ * calls with invalid signal numbers giving a SIG_ERR result. */
+ BOOL oldvalue = set_silent_invalid_parameter_handler(TRUE);
#endif
- result = signal(sig, subcode);
+ result = signal(sig, subcode);
#ifdef SET_INVALID_PARAMETER_HANDLER
- set_silent_invalid_parameter_handler(oldvalue);
+ set_silent_invalid_parameter_handler(oldvalue);
#endif
- aTHXa(PERL_GET_THX);
- if (result == SIG_ERR) {
- result = w32_sighandler[sig];
- errno = save_errno;
- }
- w32_sighandler[sig] = subcode;
- return result;
+ aTHXa(PERL_GET_THX);
+ if (result == SIG_ERR) {
+ result = w32_sighandler[sig];
+ errno = save_errno;
+ }
+ w32_sighandler[sig] = subcode;
+ return result;
}
else {
- errno = EINVAL;
- return SIG_ERR;
+ errno = EINVAL;
+ return SIG_ERR;
}
}
@@ -5105,16 +5105,16 @@ Perl_sys_intern_init(pTHX)
w32_message_hwnd = CAST_HWND__(INVALID_HANDLE_VALUE);
w32_poll_count = 0;
for (i=0; i < SIG_SIZE; i++) {
- w32_sighandler[i] = SIG_DFL;
+ w32_sighandler[i] = SIG_DFL;
}
# ifdef MULTIPLICITY
if (my_perl == PL_curinterp) {
# else
{
# endif
- /* Force C runtime signal stuff to set its console handler */
- signal(SIGINT,win32_csighandler);
- signal(SIGBREAK,win32_csighandler);
+ /* Force C runtime signal stuff to set its console handler */
+ signal(SIGINT,win32_csighandler);
+ signal(SIGBREAK,win32_csighandler);
/* We spawn asynchronous processes with the CREATE_NEW_PROCESS_GROUP
* flag. This has the side-effect of disabling Ctrl-C events in all
@@ -5124,8 +5124,8 @@ Perl_sys_intern_init(pTHX)
*/
SetConsoleCtrlHandler(NULL,FALSE);
- /* Push our handler on top */
- SetConsoleCtrlHandler(win32_ctrlhandler,TRUE);
+ /* Push our handler on top */
+ SetConsoleCtrlHandler(win32_ctrlhandler,TRUE);
}
}
@@ -5138,8 +5138,8 @@ Perl_sys_intern_clear(pTHX)
/* NOTE: w32_fdpid is freed by sv_clean_all() */
Safefree(w32_children);
if (w32_timerid) {
- KillTimer(w32_message_hwnd, w32_timerid);
- w32_timerid = 0;
+ KillTimer(w32_message_hwnd, w32_timerid);
+ w32_timerid = 0;
}
if (w32_message_hwnd != NULL && w32_message_hwnd != INVALID_HANDLE_VALUE)
DestroyWindow(w32_message_hwnd);
@@ -5148,7 +5148,7 @@ Perl_sys_intern_clear(pTHX)
# else
{
# endif
- SetConsoleCtrlHandler(win32_ctrlhandler,FALSE);
+ SetConsoleCtrlHandler(win32_ctrlhandler,FALSE);
}
# ifdef USE_ITHREADS
Safefree(w32_pseudo_children);
diff --git a/win32/win32.h b/win32/win32.h
index 40ab7e043a..2325d0edc9 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -111,7 +111,7 @@
#if (defined(__GNUC__) && defined(__MINGW32__) && \
!defined(__MINGW64_VERSION_MAJOR) && !defined(__clang__) && \
- ((__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ <= 5))))
+ ((__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ <= 5))))
/* use default fallbacks from perl.h for this particular GCC */
#else
# if !defined(PERLDLL) && !defined(PERL_EXT_RE_BUILD)
@@ -181,10 +181,10 @@ WINBASEAPI LPCH WINAPI GetEnvironmentStringsA(VOID);
#endif
struct tms {
- long tms_utime;
- long tms_stime;
- long tms_cutime;
- long tms_cstime;
+ long tms_utime;
+ long tms_stime;
+ long tms_cutime;
+ long tms_cstime;
};
#ifndef SYS_NMLN
diff --git a/win32/win32io.c b/win32/win32io.c
index 814fc8bf8f..2b4f27611d 100644
--- a/win32/win32io.c
+++ b/win32/win32io.c
@@ -63,8 +63,8 @@ PerlIOWin32_pushed(pTHX_ PerlIO *f, const char *mode, SV *arg, PerlIO_funcs *tab
PerlIOBase(f)->flags |= PERLIO_F_OPEN;
Perl_ck_warner_d(aTHX_
- packWARN(WARN_EXPERIMENTAL__WIN32_PERLIO),
- "PerlIO layer ':win32' is experimental");
+ packWARN(WARN_EXPERIMENTAL__WIN32_PERLIO),
+ "PerlIO layer ':win32' is experimental");
return code;
}
diff --git a/win32/win32iop.h b/win32/win32iop.h
index fd6b1c151b..9733d7b532 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -88,7 +88,7 @@ DllExport int win32_isatty(int fd);
DllExport int win32_read(int fd, void *buf, unsigned int cnt);
DllExport int win32_write(int fd, const void *buf, unsigned int cnt);
DllExport int win32_spawnvp(int mode, const char *cmdname,
- const char *const *argv);
+ const char *const *argv);
DllExport int win32_mkdir(const char *dir, int mode);
DllExport int win32_rmdir(const char *dir);
DllExport int win32_chdir(const char *dir);
diff --git a/win32/win32sck.c b/win32/win32sck.c
index 2798ee507b..ef5c682101 100644
--- a/win32/win32sck.c
+++ b/win32/win32sck.c
@@ -35,19 +35,19 @@
#define StartSockets() \
STMT_START { \
- if (!wsock_started) \
- start_sockets(); \
+ if (!wsock_started) \
+ start_sockets(); \
} STMT_END
#define SOCKET_TEST(x, y) \
STMT_START { \
- StartSockets(); \
- if((x) == (y)) \
- { \
- int wsaerr = WSAGetLastError(); \
- errno = convert_wsa_error_to_errno(wsaerr); \
- SetLastError(wsaerr); \
- } \
+ StartSockets(); \
+ if((x) == (y)) \
+ { \
+ int wsaerr = WSAGetLastError(); \
+ errno = convert_wsa_error_to_errno(wsaerr); \
+ SetLastError(wsaerr); \
+ } \
} STMT_END
#define SOCKET_TEST_ERROR(x) SOCKET_TEST(x, SOCKET_ERROR)
@@ -66,7 +66,7 @@ EXTERN_C void
EndSockets(void)
{
if (wsock_started)
- WSACleanup();
+ WSACleanup();
}
/* Translate WSAExxx values to corresponding Exxx values where possible. Not all
@@ -89,107 +89,107 @@ convert_wsa_error_to_errno(int wsaerr)
{
switch (wsaerr) {
case WSAEINTR:
- return EINTR;
+ return EINTR;
case WSAEBADF:
- return EBADF;
+ return EBADF;
case WSAEACCES:
- return EACCES;
+ return EACCES;
case WSAEFAULT:
- return EFAULT;
+ return EFAULT;
case WSAEINVAL:
- return EINVAL;
+ return EINVAL;
case WSAEMFILE:
- return EMFILE;
+ return EMFILE;
case WSAEWOULDBLOCK:
- return EWOULDBLOCK;
+ return EWOULDBLOCK;
case WSAEINPROGRESS:
- return EINPROGRESS;
+ return EINPROGRESS;
case WSAEALREADY:
- return EALREADY;
+ return EALREADY;
case WSAENOTSOCK:
- return ENOTSOCK;
+ return ENOTSOCK;
case WSAEDESTADDRREQ:
- return EDESTADDRREQ;
+ return EDESTADDRREQ;
case WSAEMSGSIZE:
- return EMSGSIZE;
+ return EMSGSIZE;
case WSAEPROTOTYPE:
- return EPROTOTYPE;
+ return EPROTOTYPE;
case WSAENOPROTOOPT:
- return ENOPROTOOPT;
+ return ENOPROTOOPT;
case WSAEPROTONOSUPPORT:
- return EPROTONOSUPPORT;
+ return EPROTONOSUPPORT;
case WSAESOCKTNOSUPPORT:
- return ESOCKTNOSUPPORT;
+ return ESOCKTNOSUPPORT;
case WSAEOPNOTSUPP:
- return EOPNOTSUPP;
+ return EOPNOTSUPP;
case WSAEPFNOSUPPORT:
- return EPFNOSUPPORT;
+ return EPFNOSUPPORT;
case WSAEAFNOSUPPORT:
- return EAFNOSUPPORT;
+ return EAFNOSUPPORT;
case WSAEADDRINUSE:
- return EADDRINUSE;
+ return EADDRINUSE;
case WSAEADDRNOTAVAIL:
- return EADDRNOTAVAIL;
+ return EADDRNOTAVAIL;
case WSAENETDOWN:
- return ENETDOWN;
+ return ENETDOWN;
case WSAENETUNREACH:
- return ENETUNREACH;
+ return ENETUNREACH;
case WSAENETRESET:
- return ENETRESET;
+ return ENETRESET;
case WSAECONNABORTED:
- return ECONNABORTED;
+ return ECONNABORTED;
case WSAECONNRESET:
- return ECONNRESET;
+ return ECONNRESET;
case WSAENOBUFS:
- return ENOBUFS;
+ return ENOBUFS;
case WSAEISCONN:
- return EISCONN;
+ return EISCONN;
case WSAENOTCONN:
- return ENOTCONN;
+ return ENOTCONN;
case WSAESHUTDOWN:
- return ESHUTDOWN;
+ return ESHUTDOWN;
case WSAETOOMANYREFS:
- return ETOOMANYREFS;
+ return ETOOMANYREFS;
case WSAETIMEDOUT:
- return ETIMEDOUT;
+ return ETIMEDOUT;
case WSAECONNREFUSED:
- return ECONNREFUSED;
+ return ECONNREFUSED;
case WSAELOOP:
- return ELOOP;
+ return ELOOP;
case WSAENAMETOOLONG:
- return ENAMETOOLONG;
+ return ENAMETOOLONG;
case WSAEHOSTDOWN:
- return WSAEHOSTDOWN; /* EHOSTDOWN is not defined */
+ return WSAEHOSTDOWN; /* EHOSTDOWN is not defined */
case WSAEHOSTUNREACH:
- return EHOSTUNREACH;
+ return EHOSTUNREACH;
case WSAENOTEMPTY:
- return ENOTEMPTY;
+ return ENOTEMPTY;
case WSAEPROCLIM:
- return EPROCLIM;
+ return EPROCLIM;
case WSAEUSERS:
- return EUSERS;
+ return EUSERS;
case WSAEDQUOT:
- return EDQUOT;
+ return EDQUOT;
case WSAESTALE:
- return ESTALE;
+ return ESTALE;
case WSAEREMOTE:
- return EREMOTE;
+ return EREMOTE;
case WSAEDISCON:
- return WSAEDISCON; /* EDISCON is not defined */
+ return WSAEDISCON; /* EDISCON is not defined */
case WSAENOMORE:
- return WSAENOMORE; /* ENOMORE is not defined */
+ return WSAENOMORE; /* ENOMORE is not defined */
#ifdef WSAECANCELLED
case WSAECANCELLED: /* New in WinSock2 */
- return ECANCELED;
+ return ECANCELED;
#endif
case WSAEINVALIDPROCTABLE:
- return WSAEINVALIDPROCTABLE; /* EINVALIDPROCTABLE is not defined */
+ return WSAEINVALIDPROCTABLE; /* EINVALIDPROCTABLE is not defined */
case WSAEINVALIDPROVIDER:
- return WSAEINVALIDPROVIDER; /* EINVALIDPROVIDER is not defined */
+ return WSAEINVALIDPROVIDER; /* EINVALIDPROVIDER is not defined */
case WSAEPROVIDERFAILEDINIT:
- return WSAEPROVIDERFAILEDINIT; /* EPROVIDERFAILEDINIT is not defined */
+ return WSAEPROVIDERFAILEDINIT; /* EPROVIDERFAILEDINIT is not defined */
case WSAEREFUSED:
- return WSAEREFUSED; /* EREFUSED is not defined */
+ return WSAEREFUSED; /* EREFUSED is not defined */
}
return wsaerr;
@@ -213,113 +213,113 @@ convert_errno_to_wsa_error(int err)
{
switch (err) {
case EADDRINUSE:
- return WSAEADDRINUSE;
+ return WSAEADDRINUSE;
case EADDRNOTAVAIL:
- return WSAEADDRNOTAVAIL;
+ return WSAEADDRNOTAVAIL;
case EAFNOSUPPORT:
- return WSAEAFNOSUPPORT;
+ return WSAEAFNOSUPPORT;
case EALREADY:
- return WSAEALREADY;
+ return WSAEALREADY;
#ifdef EBADMSG
case EBADMSG: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case ECANCELED:
#ifdef WSAECANCELLED
- return WSAECANCELLED; /* New in WinSock2 */
+ return WSAECANCELLED; /* New in WinSock2 */
#else
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case ECONNABORTED:
- return WSAECONNABORTED;
+ return WSAECONNABORTED;
case ECONNREFUSED:
- return WSAECONNREFUSED;
+ return WSAECONNREFUSED;
case ECONNRESET:
- return WSAECONNRESET;
+ return WSAECONNRESET;
case EDESTADDRREQ:
- return WSAEDESTADDRREQ;
+ return WSAEDESTADDRREQ;
case EHOSTUNREACH:
- return WSAEHOSTUNREACH;
+ return WSAEHOSTUNREACH;
#ifdef EIDRM
case EIDRM: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case EINPROGRESS:
- return WSAEINPROGRESS;
+ return WSAEINPROGRESS;
case EISCONN:
- return WSAEISCONN;
+ return WSAEISCONN;
case ELOOP:
- return WSAELOOP;
+ return WSAELOOP;
case EMSGSIZE:
- return WSAEMSGSIZE;
+ return WSAEMSGSIZE;
case ENETDOWN:
- return WSAENETDOWN;
+ return WSAENETDOWN;
case ENETRESET:
- return WSAENETRESET;
+ return WSAENETRESET;
case ENETUNREACH:
- return WSAENETUNREACH;
+ return WSAENETUNREACH;
case ENOBUFS:
- return WSAENOBUFS;
+ return WSAENOBUFS;
#ifdef ENODATA
case ENODATA: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
#ifdef ENOLINK
case ENOLINK: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
#ifdef ENOMSG
case ENOMSG: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case ENOPROTOOPT:
- return WSAENOPROTOOPT;
+ return WSAENOPROTOOPT;
#ifdef ENOSR
case ENOSR: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
#ifdef ENOSTR
case ENOSTR: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case ENOTCONN:
- return WSAENOTCONN;
+ return WSAENOTCONN;
#ifdef ENOTRECOVERABLE
case ENOTRECOVERABLE: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case ENOTSOCK:
- return WSAENOTSOCK;
+ return WSAENOTSOCK;
case ENOTSUP:
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
case EOPNOTSUPP:
- return WSAEOPNOTSUPP;
+ return WSAEOPNOTSUPP;
#ifdef EOTHER
case EOTHER: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case EOVERFLOW:
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
case EOWNERDEAD:
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
case EPROTO:
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
case EPROTONOSUPPORT:
- return WSAEPROTONOSUPPORT;
+ return WSAEPROTONOSUPPORT;
case EPROTOTYPE:
- return WSAEPROTOTYPE;
+ return WSAEPROTOTYPE;
#ifdef ETIME
case ETIME: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case ETIMEDOUT:
- return WSAETIMEDOUT;
+ return WSAETIMEDOUT;
#ifdef ETXTBSY
case ETXTBSY: /* Not defined in gcc-4.8.0 */
- return ERROR_INVALID_FUNCTION;
+ return ERROR_INVALID_FUNCTION;
#endif
case EWOULDBLOCK:
- return WSAEWOULDBLOCK;
+ return WSAEWOULDBLOCK;
}
return err;
@@ -339,9 +339,9 @@ start_sockets(void)
*/
version = 0x2;
if(ret = WSAStartup(version, &retdata))
- Perl_croak_nocontext("Unable to locate winsock library!\n");
+ Perl_croak_nocontext("Unable to locate winsock library!\n");
if(retdata.wVersion != version)
- Perl_croak_nocontext("Could not find version 2.0 of winsock dll\n");
+ Perl_croak_nocontext("Could not find version 2.0 of winsock dll\n");
/* atexit((void (*)(void)) EndSockets); */
wsock_started = 1;
@@ -482,7 +482,7 @@ win32_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, i
* of sockets, so go the extra mile.
*/
if (r != SOCKET_ERROR && frombufsize == *fromlen)
- (void)win32_getpeername(s, from, fromlen);
+ (void)win32_getpeername(s, from, fromlen);
return r;
}
@@ -501,33 +501,33 @@ win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const
FD_ZERO(&nwr);
FD_ZERO(&nex);
for (i = 0; i < nfds; i++) {
- if (rd && PERL_FD_ISSET(i,rd)) {
- fd = TO_SOCKET(i);
- FD_SET((unsigned)fd, &nrd);
+ if (rd && PERL_FD_ISSET(i,rd)) {
+ fd = TO_SOCKET(i);
+ FD_SET((unsigned)fd, &nrd);
just_sleep = FALSE;
- }
- if (wr && PERL_FD_ISSET(i,wr)) {
- fd = TO_SOCKET(i);
- FD_SET((unsigned)fd, &nwr);
+ }
+ if (wr && PERL_FD_ISSET(i,wr)) {
+ fd = TO_SOCKET(i);
+ FD_SET((unsigned)fd, &nwr);
just_sleep = FALSE;
- }
- if (ex && PERL_FD_ISSET(i,ex)) {
- fd = TO_SOCKET(i);
- FD_SET((unsigned)fd, &nex);
+ }
+ if (ex && PERL_FD_ISSET(i,ex)) {
+ fd = TO_SOCKET(i);
+ FD_SET((unsigned)fd, &nex);
just_sleep = FALSE;
- }
+ }
}
/* winsock seems incapable of dealing with all three fd_sets being empty,
* so do the (millisecond) sleep as a special case
*/
if (just_sleep) {
- if (timeout)
- Sleep(timeout->tv_sec * 1000 +
- timeout->tv_usec / 1000); /* do the best we can */
- else
- Sleep(UINT_MAX);
- return 0;
+ if (timeout)
+ Sleep(timeout->tv_sec * 1000 +
+ timeout->tv_usec / 1000); /* do the best we can */
+ else
+ Sleep(UINT_MAX);
+ return 0;
}
errno = save_errno;
@@ -535,21 +535,21 @@ win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const
save_errno = errno;
for (i = 0; i < nfds; i++) {
- if (rd && PERL_FD_ISSET(i,rd)) {
- fd = TO_SOCKET(i);
- if (!FD_ISSET(fd, &nrd))
- PERL_FD_CLR(i,rd);
- }
- if (wr && PERL_FD_ISSET(i,wr)) {
- fd = TO_SOCKET(i);
- if (!FD_ISSET(fd, &nwr))
- PERL_FD_CLR(i,wr);
- }
- if (ex && PERL_FD_ISSET(i,ex)) {
- fd = TO_SOCKET(i);
- if (!FD_ISSET(fd, &nex))
- PERL_FD_CLR(i,ex);
- }
+ if (rd && PERL_FD_ISSET(i,rd)) {
+ fd = TO_SOCKET(i);
+ if (!FD_ISSET(fd, &nrd))
+ PERL_FD_CLR(i,rd);
+ }
+ if (wr && PERL_FD_ISSET(i,wr)) {
+ fd = TO_SOCKET(i);
+ if (!FD_ISSET(fd, &nwr))
+ PERL_FD_CLR(i,wr);
+ }
+ if (ex && PERL_FD_ISSET(i,ex)) {
+ fd = TO_SOCKET(i);
+ if (!FD_ISSET(fd, &nex))
+ PERL_FD_CLR(i,ex);
+ }
}
errno = save_errno;
return r;
@@ -566,7 +566,7 @@ win32_send(SOCKET s, const char *buf, int len, int flags)
int
win32_sendto(SOCKET s, const char *buf, int len, int flags,
- const struct sockaddr *to, int tolen)
+ const struct sockaddr *to, int tolen)
{
int r;
@@ -623,7 +623,7 @@ open_ifs_socket(int af, int type, int protocol)
if (WSCEnumProtocols(NULL, NULL, &proto_buffers_len, &error_code) == SOCKET_ERROR
&& error_code == WSAENOBUFS)
{
- WSAPROTOCOL_INFOW *proto_buffers;
+ WSAPROTOCOL_INFOW *proto_buffers;
int protocols_available = 0;
Newx(proto_buffers, proto_buffers_len / sizeof(WSAPROTOCOL_INFOW),
@@ -672,12 +672,12 @@ win32_socket(int af, int type, int protocol)
if((s = open_ifs_socket(af, type, protocol)) == INVALID_SOCKET)
{
- int wsaerr = WSAGetLastError();
- errno = convert_wsa_error_to_errno(wsaerr);
- SetLastError(wsaerr);
- }
+ int wsaerr = WSAGetLastError();
+ errno = convert_wsa_error_to_errno(wsaerr);
+ SetLastError(wsaerr);
+ }
else
- s = OPEN_SOCKET(s);
+ s = OPEN_SOCKET(s);
return s;
}
@@ -693,32 +693,32 @@ int my_close(int fd)
{
int osf;
if (!wsock_started) /* No WinSock? */
- return(close(fd)); /* Then not a socket. */
+ return(close(fd)); /* Then not a socket. */
osf = TO_SOCKET(fd);/* Get it now before it's gone! */
if (osf != -1) {
- int err;
- err = closesocket(osf);
- if (err == 0) {
+ int err;
+ err = closesocket(osf);
+ if (err == 0) {
#ifdef _set_osfhnd
- assert(_osfhnd(fd) == osf); /* catch a bad ioinfo struct def */
- /* don't close freed handle */
- _set_osfhnd(fd, INVALID_HANDLE_VALUE);
- return close(fd);
+ assert(_osfhnd(fd) == osf); /* catch a bad ioinfo struct def */
+ /* don't close freed handle */
+ _set_osfhnd(fd, INVALID_HANDLE_VALUE);
+ return close(fd);
#else
- (void)close(fd); /* handle already closed, ignore error */
- return 0;
+ (void)close(fd); /* handle already closed, ignore error */
+ return 0;
#endif
- }
- else if (err == SOCKET_ERROR) {
- int wsaerr = WSAGetLastError();
- err = convert_wsa_error_to_errno(wsaerr);
- if (err != ENOTSOCK) {
- (void)close(fd);
- errno = err;
- SetLastError(wsaerr);
- return EOF;
- }
- }
+ }
+ else if (err == SOCKET_ERROR) {
+ int wsaerr = WSAGetLastError();
+ err = convert_wsa_error_to_errno(wsaerr);
+ if (err != ENOTSOCK) {
+ (void)close(fd);
+ errno = err;
+ SetLastError(wsaerr);
+ return EOF;
+ }
+ }
}
return close(fd);
}
@@ -729,33 +729,33 @@ my_fclose (FILE *pf)
{
int osf;
if (!wsock_started) /* No WinSock? */
- return(fclose(pf)); /* Then not a socket. */
+ return(fclose(pf)); /* Then not a socket. */
osf = TO_SOCKET(win32_fileno(pf));/* Get it now before it's gone! */
if (osf != -1) {
- int err;
- win32_fflush(pf);
- err = closesocket(osf);
- if (err == 0) {
+ int err;
+ win32_fflush(pf);
+ err = closesocket(osf);
+ if (err == 0) {
#ifdef _set_osfhnd
- assert(_osfhnd(win32_fileno(pf)) == osf); /* catch a bad ioinfo struct def */
- /* don't close freed handle */
- _set_osfhnd(win32_fileno(pf), INVALID_HANDLE_VALUE);
- return fclose(pf);
+ assert(_osfhnd(win32_fileno(pf)) == osf); /* catch a bad ioinfo struct def */
+ /* don't close freed handle */
+ _set_osfhnd(win32_fileno(pf), INVALID_HANDLE_VALUE);
+ return fclose(pf);
#else
- (void)fclose(pf); /* handle already closed, ignore error */
- return 0;
+ (void)fclose(pf); /* handle already closed, ignore error */
+ return 0;
#endif
- }
- else if (err == SOCKET_ERROR) {
- int wsaerr = WSAGetLastError();
- err = convert_wsa_error_to_errno(wsaerr);
- if (err != ENOTSOCK) {
- (void)fclose(pf);
- errno = err;
- SetLastError(wsaerr);
- return EOF;
- }
- }
+ }
+ else if (err == SOCKET_ERROR) {
+ int wsaerr = WSAGetLastError();
+ err = convert_wsa_error_to_errno(wsaerr);
+ if (err != ENOTSOCK) {
+ (void)fclose(pf);
+ errno = err;
+ SetLastError(wsaerr);
+ return EOF;
+ }
+ }
}
return fclose(pf);
}
@@ -814,7 +814,7 @@ win32_getservbyname(const char *name, const char *proto)
SOCKET_TEST(r = getservbyname(name, proto), NULL);
if (r) {
aTHXa(PERL_GET_THX);
- r = win32_savecopyservent(&w32_servent, r, proto);
+ r = win32_savecopyservent(&w32_servent, r, proto);
}
return r;
}
@@ -828,7 +828,7 @@ win32_getservbyport(int port, const char *proto)
SOCKET_TEST(r = getservbyport(port, proto), NULL);
if (r) {
aTHXa(PERL_GET_THX);
- r = win32_savecopyservent(&w32_servent, r, proto);
+ r = win32_savecopyservent(&w32_servent, r, proto);
}
return r;
}
@@ -840,8 +840,8 @@ win32_ioctl(int i, unsigned int u, char *data)
int retval;
if (!wsock_started) {
- Perl_croak_nocontext("ioctl implemented only on sockets");
- /* NOTREACHED */
+ Perl_croak_nocontext("ioctl implemented only on sockets");
+ /* NOTREACHED */
}
/* mauke says using memcpy avoids alignment issues */
@@ -850,14 +850,14 @@ win32_ioctl(int i, unsigned int u, char *data)
memcpy(data, &u_long_arg, sizeof u_long_arg);
if (retval == SOCKET_ERROR) {
- int wsaerr = WSAGetLastError();
- int err = convert_wsa_error_to_errno(wsaerr);
- if (err == ENOTSOCK) {
- Perl_croak_nocontext("ioctl implemented only on sockets");
- /* NOTREACHED */
- }
- errno = err;
- SetLastError(wsaerr);
+ int wsaerr = WSAGetLastError();
+ int err = convert_wsa_error_to_errno(wsaerr);
+ if (err == ENOTSOCK) {
+ Perl_croak_nocontext("ioctl implemented only on sockets");
+ /* NOTREACHED */
+ }
+ errno = err;
+ SetLastError(wsaerr);
}
return retval;
}
@@ -974,12 +974,12 @@ win32_savecopyservent(struct servent*d, struct servent*s, const char *proto)
d->s_aliases = s->s_aliases;
d->s_port = s->s_port;
if (s->s_proto && strlen(s->s_proto))
- d->s_proto = s->s_proto;
+ d->s_proto = s->s_proto;
else
if (proto && strlen(proto))
- d->s_proto = (char *)proto;
+ d->s_proto = (char *)proto;
else
- d->s_proto = "tcp";
+ d->s_proto = "tcp";
return d;
}
diff --git a/win32/win32thread.h b/win32/win32thread.h
index 9ac964ccf4..9306157c1c 100644
--- a/win32/win32thread.h
+++ b/win32/win32thread.h
@@ -24,26 +24,26 @@ typedef CRITICAL_SECTION perl_mutex;
typedef HANDLE perl_mutex;
# define MUTEX_INIT(m) \
STMT_START { \
- if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL) \
- Perl_croak_nocontext("panic: MUTEX_INIT"); \
+ if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL) \
+ Perl_croak_nocontext("panic: MUTEX_INIT"); \
} STMT_END
# define MUTEX_LOCK(m) \
STMT_START { \
- if (WaitForSingleObject(*(m),INFINITE) == WAIT_FAILED) \
- Perl_croak_nocontext("panic: MUTEX_LOCK"); \
+ if (WaitForSingleObject(*(m),INFINITE) == WAIT_FAILED) \
+ Perl_croak_nocontext("panic: MUTEX_LOCK"); \
} STMT_END
# define MUTEX_UNLOCK(m) \
STMT_START { \
- if (ReleaseMutex(*(m)) == 0) \
- Perl_croak_nocontext("panic: MUTEX_UNLOCK"); \
+ if (ReleaseMutex(*(m)) == 0) \
+ Perl_croak_nocontext("panic: MUTEX_UNLOCK"); \
} STMT_END
# define MUTEX_DESTROY(m) \
STMT_START { \
- if (CloseHandle(*(m)) == 0) \
- Perl_croak_nocontext("panic: MUTEX_DESTROY"); \
+ if (CloseHandle(*(m)) == 0) \
+ Perl_croak_nocontext("panic: MUTEX_DESTROY"); \
} STMT_END
#endif
@@ -54,53 +54,53 @@ typedef HANDLE perl_mutex;
*/
#define COND_INIT(c) \
STMT_START { \
- (c)->waiters = 0; \
- (c)->sem = Win_CreateSemaphore(NULL,0,LONG_MAX,NULL); \
- if ((c)->sem == NULL) \
- Perl_croak_nocontext("panic: COND_INIT (%ld)",GetLastError()); \
+ (c)->waiters = 0; \
+ (c)->sem = Win_CreateSemaphore(NULL,0,LONG_MAX,NULL); \
+ if ((c)->sem == NULL) \
+ Perl_croak_nocontext("panic: COND_INIT (%ld)",GetLastError()); \
} STMT_END
#define COND_SIGNAL(c) \
STMT_START { \
- if ((c)->waiters > 0 && \
- ReleaseSemaphore((c)->sem,1,NULL) == 0) \
- Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",GetLastError()); \
+ if ((c)->waiters > 0 && \
+ ReleaseSemaphore((c)->sem,1,NULL) == 0) \
+ Perl_croak_nocontext("panic: COND_SIGNAL (%ld)",GetLastError()); \
} STMT_END
#define COND_BROADCAST(c) \
STMT_START { \
- if ((c)->waiters > 0 && \
- ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0) \
- Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\
+ if ((c)->waiters > 0 && \
+ ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0) \
+ Perl_croak_nocontext("panic: COND_BROADCAST (%ld)",GetLastError());\
} STMT_END
#define COND_WAIT(c, m) \
STMT_START { \
- (c)->waiters++; \
- MUTEX_UNLOCK(m); \
- /* Note that there's no race here, since a \
- * COND_BROADCAST() on another thread will have seen the\
- * right number of waiters (i.e. including this one) */ \
- if (WaitForSingleObject((c)->sem,INFINITE)==WAIT_FAILED)\
- Perl_croak_nocontext("panic: COND_WAIT (%ld)",GetLastError()); \
- /* XXX there may be an inconsequential race here */ \
- MUTEX_LOCK(m); \
- (c)->waiters--; \
+ (c)->waiters++; \
+ MUTEX_UNLOCK(m); \
+ /* Note that there's no race here, since a \
+ * COND_BROADCAST() on another thread will have seen the\
+ * right number of waiters (i.e. including this one) */ \
+ if (WaitForSingleObject((c)->sem,INFINITE)==WAIT_FAILED)\
+ Perl_croak_nocontext("panic: COND_WAIT (%ld)",GetLastError()); \
+ /* XXX there may be an inconsequential race here */ \
+ MUTEX_LOCK(m); \
+ (c)->waiters--; \
} STMT_END
#define COND_DESTROY(c) \
STMT_START { \
- (c)->waiters = 0; \
- if (CloseHandle((c)->sem) == 0) \
- Perl_croak_nocontext("panic: COND_DESTROY (%ld)",GetLastError()); \
+ (c)->waiters = 0; \
+ if (CloseHandle((c)->sem) == 0) \
+ Perl_croak_nocontext("panic: COND_DESTROY (%ld)",GetLastError()); \
} STMT_END
#define DETACH(t) \
STMT_START { \
- if (CloseHandle((t)->self) == 0) { \
- MUTEX_UNLOCK(&(t)->mutex); \
- Perl_croak_nocontext("panic: DETACH"); \
- } \
+ if (CloseHandle((t)->self) == 0) { \
+ MUTEX_UNLOCK(&(t)->mutex); \
+ Perl_croak_nocontext("panic: DETACH"); \
+ } \
} STMT_END
@@ -148,15 +148,15 @@ END_EXTERN_C
#define INIT_THREADS NOOP
#define ALLOC_THREAD_KEY \
STMT_START { \
- if ((PL_thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) { \
- PerlIO_printf(PerlIO_stderr(),"panic: TlsAlloc"); \
- exit(1); \
- } \
+ if ((PL_thr_key = TlsAlloc()) == TLS_OUT_OF_INDEXES) { \
+ PerlIO_printf(PerlIO_stderr(),"panic: TlsAlloc"); \
+ exit(1); \
+ } \
} STMT_END
#define FREE_THREAD_KEY \
STMT_START { \
- TlsFree(PL_thr_key); \
+ TlsFree(PL_thr_key); \
} STMT_END
#define PTHREAD_ATFORK(prepare,parent,child) NOOP
@@ -164,19 +164,19 @@ END_EXTERN_C
#if defined(USE_RTL_THREAD_API) && !defined(_MSC_VER)
#define JOIN(t, avp) \
STMT_START { \
- if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED) \
- || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0) \
- || (CloseHandle((t)->self) == 0)) \
- Perl_croak_nocontext("panic: JOIN"); \
- *avp = (AV *)((t)->i.retv); \
+ if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED) \
+ || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0) \
+ || (CloseHandle((t)->self) == 0)) \
+ Perl_croak_nocontext("panic: JOIN"); \
+ *avp = (AV *)((t)->i.retv); \
} STMT_END
#else /* !USE_RTL_THREAD_API || _MSC_VER */
#define JOIN(t, avp) \
STMT_START { \
- if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED) \
- || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0) \
- || (CloseHandle((t)->self) == 0)) \
- Perl_croak_nocontext("panic: JOIN"); \
+ if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED) \
+ || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0) \
+ || (CloseHandle((t)->self) == 0)) \
+ Perl_croak_nocontext("panic: JOIN"); \
} STMT_END
#endif /* !USE_RTL_THREAD_API || _MSC_VER */