summaryrefslogtreecommitdiff
path: root/win32
diff options
context:
space:
mode:
Diffstat (limited to 'win32')
-rw-r--r--win32/Makefile37
-rw-r--r--win32/config.bc26
-rw-r--r--win32/config.vc19
-rw-r--r--win32/config_H.bc4
-rw-r--r--win32/config_H.vc2
-rw-r--r--win32/config_sh.PL10
-rw-r--r--win32/include/sys/socket.h55
-rw-r--r--win32/makedef.pl14
-rw-r--r--win32/makefile.mk48
-rw-r--r--win32/perllib.c11
-rw-r--r--win32/runperl.c15
-rw-r--r--win32/win32.c525
-rw-r--r--win32/win32.h176
-rw-r--r--win32/win32io.c333
-rw-r--r--win32/win32io.h91
-rw-r--r--win32/win32iop.h65
-rw-r--r--win32/win32sck.c416
-rw-r--r--win32/win32thread.c6
-rw-r--r--win32/win32thread.h71
19 files changed, 674 insertions, 1250 deletions
diff --git a/win32/Makefile b/win32/Makefile
index f6b9a99b45..d2e464145a 100644
--- a/win32/Makefile
+++ b/win32/Makefile
@@ -11,7 +11,7 @@
# newly built perl.
INST_DRV=c:
INST_TOP=$(INST_DRV)\perl
-BUILDOPT=-DUSE_THREADS -TP
+BUILDOPT=-DUSE_THREADS
CORECCOPT=
#
@@ -60,7 +60,7 @@ LIBC = msvcrt.lib
WINIOMAYBE =
!ELSE
LIBC = libcmt.lib
-WINIOMAYBE = win32io.obj
+WINIOMAYBE =
!ENDIF
!IF "$(CFG)" == "Debug"
@@ -86,7 +86,7 @@ LIBFILES = oldnames.lib kernel32.lib user32.lib gdi32.lib \
version.lib odbc32.lib odbccp32.lib
CFLAGS = -nologo -W3 $(INCLUDES) $(DEFINES) $(LOCDEFS) $(PCHFLAGS) $(OPTIMIZE)
-LINK_FLAGS = -nologo $(LIBFILES) $(LINK_DBG) -machine:$(PROCESSOR_ARCHITECTURE)
+LINK_FLAGS = -nologo $(LINK_DBG) -machine:$(PROCESSOR_ARCHITECTURE)
OBJOUT_FLAG = -Fo
#################### do not edit below this line #######################
@@ -103,7 +103,7 @@ OBJOUT_FLAG = -Fo
.obj.dll:
$(LINK32) -dll -subsystem:windows -implib:$(*B).lib -def:$(*B).def \
- -out:$@ $(LINK_FLAGS) $< $(LIBPERL)
+ -out:$@ $(LINK_FLAGS) $(LIBFILES) $< $(LIBPERL)
#
INST_BIN=$(INST_TOP)\bin
@@ -197,18 +197,15 @@ CORE_OBJ= ..\av.obj \
WIN32_C = perllib.c \
win32.c \
- win32io.c \
win32sck.c \
win32thread.c
WIN32_OBJ = win32.obj \
- win32io.obj \
win32sck.obj \
win32thread.obj
PERL95_OBJ = perl95.obj \
win32mt.obj \
- win32iomt.obj \
win32sckmt.obj
DLL_OBJ = perllib.obj $(DYNALOADER).obj
@@ -236,6 +233,7 @@ CORE_H = ..\av.h \
..\regexp.h \
..\scope.h \
..\sv.h \
+ ..\thread.h \
..\unixish.h \
..\util.h \
..\XSUB.h \
@@ -246,7 +244,8 @@ CORE_H = ..\av.h \
.\include\sys\socket.h \
.\win32.h
-EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs Thread
+DYNAMIC_EXT=Socket IO Fcntl Opcode SDBM_File attrs Thread
+STATIC_EXT=DynaLoader
DYNALOADER=$(EXTDIR)\DynaLoader\DynaLoader
SOCKET=$(EXTDIR)\Socket\Socket
@@ -291,7 +290,8 @@ $(DYNALOADER).obj : $(DYNALOADER).c $(CORE_H) $(EXTDIR)\DynaLoader\dlutils.c
#------------------------------------------------------------
$(GLOBEXE): perlglob.obj
- $(LINK32) $(LINK_FLAGS) -out:$@ -subsystem:$(SUBSYS) perlglob.obj setargv.obj
+ $(LINK32) $(LINK_FLAGS) $(LIBFILES) -out:$@ -subsystem:$(SUBSYS) \
+ perlglob.obj setargv.obj
$(GLOBBAT) : ..\lib\File\DosGlob.pm $(MINIPERL)
$(MINIPERL) $(PL2BAT) - < ..\lib\File\DosGlob.pm > $(GLOBBAT)
@@ -313,6 +313,8 @@ config.w32 : $(CFGSH_TMPL)
"INST_TOP=$(INST_TOP)" "cc=$(CC)" "ccflags=$(OPTIMIZE) $(DEFINES)" \
"cf_email=$(EMAIL)" "libs=$(LIBFILES)" "incpath=$(CCINCDIR)" \
"libpth=$(CCLIBDIR)" "libc=$(LIBC)" \
+ "static_ext=$(STATIC_EXT)" "dynamic_ext=$(DYNAMIC_EXT)" \
+ "ldflags=$(LINK_FLAGS)" "optimize=$(OPTIMIZE)" \
config.w32 > ..\config.sh
$(CONFIGPM) : $(MINIPERL) ..\config.sh config_h.PL ..\minimod.pl
@@ -326,7 +328,7 @@ $(CONFIGPM) : $(MINIPERL) ..\config.sh config_h.PL ..\minimod.pl
$(MINIPERL) : ..\miniperlmain.obj $(CORE_OBJ) $(WIN32_OBJ)
$(LINK32) -subsystem:console -out:$@ @<<
- $(LINK_FLAGS) ..\miniperlmain.obj $(CORE_OBJ) $(WIN32_OBJ)
+ $(LINK_FLAGS) $(LIBFILES) ..\miniperlmain.obj $(CORE_OBJ) $(WIN32_OBJ)
<<
$(WIN32_OBJ) : $(CORE_H)
@@ -338,7 +340,7 @@ perldll.def : $(MINIPERL) $(CONFIGPM)
$(PERLDLL): perldll.def $(CORE_OBJ) $(WIN32_OBJ) $(DLL_OBJ)
$(LINK32) -dll -def:perldll.def -out:$@ @<<
- $(LINK_FLAGS) $(CORE_OBJ) $(WIN32_OBJ) $(DLL_OBJ)
+ $(LINK_FLAGS) $(LIBFILES) $(CORE_OBJ) $(WIN32_OBJ) $(DLL_OBJ)
<<
$(XCOPY) $(PERLIMPLIB) ..\lib\CORE
@@ -355,14 +357,12 @@ perlmain.obj : perlmain.c
$(CC) $(CFLAGS) -UPERLDLL -c perlmain.c
$(PERLEXE): $(PERLDLL) $(CONFIGPM) perlmain.obj
- $(LINK32) -subsystem:console -out:perl.exe $(LINK_FLAGS) \
+ $(LINK32) -subsystem:console -out:perl.exe $(LINK_FLAGS) $(LIBFILES) \
perlmain.obj $(WINIOMAYBE) $(PERLIMPLIB)
copy perl.exe $@
del perl.exe
copy splittree.pl ..
$(MINIPERL) -I..\lib ..\splittree.pl "../LIB" "../LIB/auto"
-# attrib -r ..\t\*.*
-# copy test ..\t
perl95.c : runperl.c
copy runperl.c perl95.c
@@ -370,9 +370,6 @@ perl95.c : runperl.c
perl95.obj : perl95.c
$(CC) $(CFLAGS) -MT -UPERLDLL -c perl95.c
-win32iomt.obj : win32io.c
- $(CC) $(CFLAGS) -MT -c $(OBJOUT_FLAG)win32iomt.obj win32io.c
-
win32sckmt.obj : win32sck.c
$(CC) $(CFLAGS) -MT -c $(OBJOUT_FLAG)win32sckmt.obj win32sck.c
@@ -380,13 +377,13 @@ win32mt.obj : win32.c
$(CC) $(CFLAGS) -MT -c $(OBJOUT_FLAG)win32mt.obj win32.c
$(PERL95EXE): $(PERLDLL) $(CONFIGPM) $(PERL95_OBJ)
- $(LINK32) -subsystem:console -out:perl95.exe $(LINK_FLAGS) \
+ $(LINK32) -subsystem:console -out:perl95.exe $(LINK_FLAGS) $(LIBFILES) \
$(PERL95_OBJ) $(PERLIMPLIB)
copy perl95.exe $@
del perl95.exe
$(DYNALOADER).c: $(MINIPERL) $(EXTDIR)\DynaLoader\dl_win32.xs $(CONFIGPM)
- if not exist ..\lib\auto md ..\lib\auto
+ if not exist ..\lib\auto mkdir ..\lib\auto
$(XCOPY) $(EXTDIR)\$(*B)\$(*B).pm $(LIBDIR)\$(NULL)
cd $(EXTDIR)\$(*B)
$(XSUBPP) dl_win32.xs > $(*B).c
@@ -460,7 +457,7 @@ utils: $(PERLEXE)
bin\pl2bat.pl
distclean: clean
- -del /f $(MINIPERL) $(PERLEXE) $(PERLDLL) $(GLOBEXE) \
+ -del /f $(MINIPERL) $(PERLEXE) $(PERL95EXE) $(PERLDLL) $(GLOBEXE) \
$(PERLIMPLIB) ..\miniperl.lib $(MINIMOD)
-del /f *.def *.map
-del /f $(SOCKET_DLL) $(IO_DLL) $(SDBM_FILE_DLL) $(FCNTL_DLL) \
diff --git a/win32/config.bc b/win32/config.bc
index 3933c2789c..e3559a041a 100644
--- a/win32/config.bc
+++ b/win32/config.bc
@@ -11,8 +11,8 @@ cc='bcc32'
ccflags='-DWIN32'
cppflags='-DWIN32'
dlsrc='dl_win32.xs'
-dynamic_ext='Fcntl IO Opcode SDBM_File Socket'
-extensions='Fcntl IO Opcode SDBM_File Socket'
+dynamic_ext='Socket IO Fcntl Opcode SDBM_File attrs Thread'
+extensions='~static_ext~ ~dynamic_ext~'
installarchlib='~INST_TOP~\lib'
installprivlib='~INST_TOP~\lib'
libpth=''
@@ -26,7 +26,7 @@ shsharp='true'
sig_name='ZERO HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM USR1 USR2 CHLD PWR WINCH URG IO STOP TSTP CONT TTIN TTOU VTALRM PROF XCPU XFSZ WAITING LWP FREEZE THAW RTMIN NUM37 NUM38 NUM39 NUM40 NUM41 NUM42 RTMAX IOT CLD POLL'
so='dll'
startsh='#!/bin/sh'
-static_ext=' '
+static_ext='DynaLoader'
Author=''
CONFIG='true'
Date='$Date'
@@ -60,10 +60,10 @@ c=''
castflags='0'
cat='type'
cccdlflags=' '
-ccdlflags=' '
-cf_by='garyng'
-cf_email='71564.1743@compuserve.com'
-cf_time='Thu Apr 11 06:20:49 PDT 1996'
+ccdlflags='-tWD'
+cf_by='nobody'
+cf_email='nobody@no.where.net'
+cf_time=''
chgrp=''
chmod=''
chown=''
@@ -83,7 +83,7 @@ cryptlib=''
csh='undef'
d_Gconvert='gcvt((x),(n),(b))'
d_access='define'
-d_alarm='define'
+d_alarm='undef'
d_archlib='define'
d_attribut='undef'
d_bcmp='undef'
@@ -357,12 +357,12 @@ installscript='~INST_TOP~\bin'
installsitearch='~INST_TOP~\lib\site'
installsitelib='~INST_TOP~\lib\site'
intsize='4'
-known_extensions='DB_File Fcntl GDBM_File NDBM_File ODBM_File Opcode POSIX SDBM_File Socket'
+known_extensions='DB_File Fcntl GDBM_File NDBM_File ODBM_File Opcode POSIX SDBM_File Socket IO attrs Thread'
ksh=''
large=''
ld='tlink32'
lddlflags='-Tpd'
-ldflags='~LINK_FLAGS~'
+ldflags=''
less='less'
lib_ext='.lib'
libc='cw32mti.lib'
@@ -411,7 +411,7 @@ o_nonblock='O_NONBLOCK'
obj_ext='.obj'
oldarchlib=''
oldarchlibexp=''
-optimize='-O'
+optimize='-O2'
orderlib='false'
package='perl5'
pager='more /e'
@@ -438,7 +438,7 @@ runnm='true'
scriptdir='~INST_TOP~\bin'
scriptdirexp='~INST_TOP~\bin'
sed='sed'
-selecttype='int *'
+selecttype='Perl_fd_set *'
sendmail='blat'
sh='cmd /x /c'
shar=''
@@ -462,7 +462,7 @@ spackage='Perl5'
spitshell=''
split=''
ssizetype='int'
-startperl='#perl'
+startperl='#!perl'
stdchar='unsigned char'
stdio_base='((fp)->buffer)'
stdio_bufsiz='((fp)->level + (fp)->curp - (fp)->buffer)'
diff --git a/win32/config.vc b/win32/config.vc
index 188317478c..c117689b0b 100644
--- a/win32/config.vc
+++ b/win32/config.vc
@@ -11,8 +11,8 @@ cc='cl'
ccflags='-MD -DWIN32'
cppflags='-DWIN32'
dlsrc='dl_win32.xs'
-dynamic_ext='Fcntl IO Opcode SDBM_File Socket'
-extensions='Fcntl IO Opcode SDBM_File Socket'
+dynamic_ext='Socket IO Fcntl Opcode SDBM_File attrs Thread'
+extensions='~static_ext~ ~dynamic_ext~'
installarchlib='~INST_TOP~\lib'
installprivlib='~INST_TOP~\lib'
libpth=''
@@ -21,13 +21,12 @@ osname='MSWin32'
osvers='4.0'
prefix='~INST_DRV~'
privlibexp='~INST_TOP~\lib'
-ranlib=''
sharpbang='#!'
shsharp='true'
sig_name='ZERO HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM USR1 USR2 CHLD PWR WINCH URG IO STOP TSTP CONT TTIN TTOU VTALRM PROF XCPU XFSZ WAITING LWP FREEZE THAW RTMIN NUM37 NUM38 NUM39 NUM40 NUM41 NUM42 RTMAX IOT CLD POLL'
so='dll'
startsh='#!/bin/sh'
-static_ext=' '
+static_ext='DynaLoader'
Author=''
CONFIG='true'
Date='$Date'
@@ -62,9 +61,9 @@ castflags='0'
cat='type'
cccdlflags=' '
ccdlflags=' '
-cf_by='garyng'
-cf_email='71564.1743@compuserve.com'
-cf_time='Thu Apr 11 06:20:49 PDT 1996'
+cf_by='nobody'
+cf_email='nobody@no.where.net'
+cf_time=''
chgrp=''
chmod=''
chown=''
@@ -358,7 +357,7 @@ installscript='~INST_TOP~\bin'
installsitearch='~INST_TOP~\lib\site'
installsitelib='~INST_TOP~\lib\site'
intsize='4'
-known_extensions='DB_File Fcntl GDBM_File NDBM_File ODBM_File Opcode POSIX SDBM_File Socket'
+known_extensions='DB_File Fcntl GDBM_File NDBM_File ODBM_File Opcode POSIX SDBM_File Socket IO attrs Thread'
ksh=''
large=''
ld='link'
@@ -439,7 +438,7 @@ runnm='true'
scriptdir='~INST_TOP~\bin'
scriptdirexp='~INST_TOP~\bin'
sed='sed'
-selecttype='int *'
+selecttype='Perl_fd_set *'
sendmail='blat'
sh='cmd /x /c'
shar=''
@@ -463,7 +462,7 @@ spackage='Perl5'
spitshell=''
split=''
ssizetype='int'
-startperl='#perl'
+startperl='#!perl'
stdchar='char'
stdio_base='((fp)->_base)'
stdio_bufsiz='((fp)->_cnt + (fp)->_ptr - (fp)->_base)'
diff --git a/win32/config_H.bc b/win32/config_H.bc
index 460b58577c..3ba2481a0f 100644
--- a/win32/config_H.bc
+++ b/win32/config_H.bc
@@ -113,7 +113,7 @@
* This symbol, if defined, indicates that the alarm routine is
* available.
*/
-#define HAS_ALARM /**/
+/*#define HAS_ALARM /**/
/* HASATTRIBUTE:
* This symbol indicates the C compiler can check for function attributes,
@@ -1376,7 +1376,7 @@
* is defined, and 'int *' otherwise. This is only useful if you
* have select(), of course.
*/
-#define Select_fd_set_t int * /**/
+#define Select_fd_set_t Perl_fd_set * /**/
/* Size_t:
* This symbol holds the type used to declare length parameters
diff --git a/win32/config_H.vc b/win32/config_H.vc
index 4634072a4e..d2c6d47afb 100644
--- a/win32/config_H.vc
+++ b/win32/config_H.vc
@@ -1376,7 +1376,7 @@
* is defined, and 'int *' otherwise. This is only useful if you
* have select(), of course.
*/
-#define Select_fd_set_t int * /**/
+#define Select_fd_set_t Perl_fd_set * /**/
/* Size_t:
* This symbol holds the type used to declare length parameters
diff --git a/win32/config_sh.PL b/win32/config_sh.PL
index 0769ef3112..0c3713cb2e 100644
--- a/win32/config_sh.PL
+++ b/win32/config_sh.PL
@@ -17,7 +17,15 @@ $opt{'cf_email'} = $opt{'cf_by'} . '@' . (gethostbyname('localhost'))[0]
while (<>)
{
s/~([\w_]+)~/$opt{$1}/g;
- $_ = "$1='$opt{$1}'\n" if (/^([\w_]+)=/ && exists($opt{$1}));
+ if (/^([\w_]+)=(.*)$/) {
+ # this depends on cf_time being empty in the template (or we'll get a loop)
+ if ($1 eq 'cf_time') {
+ $_ = "$1='" . localtime(time) . "'\n" if $2 =~ /^\s*'\s*'/;
+ }
+ elsif (exists $opt{$1}) {
+ $_ = "$1='$opt{$1}'\n";
+ }
+ }
print;
}
diff --git a/win32/include/sys/socket.h b/win32/include/sys/socket.h
index 9e5259b254..c6d0123143 100644
--- a/win32/include/sys/socket.h
+++ b/win32/include/sys/socket.h
@@ -44,6 +44,41 @@ typedef struct _OVERLAPPED {
#define ENOTSOCK WSAENOTSOCK
#undef HOST_NOT_FOUND
+#ifdef USE_SOCKETS_AS_HANDLES
+
+#ifndef PERL_FD_SETSIZE
+#define PERL_FD_SETSIZE 64
+#endif
+
+#define PERL_BITS_PER_BYTE 8
+#define PERL_NFDBITS (sizeof(Perl_fd_mask)*PERL_BITS_PER_BYTE)
+
+typedef int Perl_fd_mask;
+
+typedef struct Perl_fd_set {
+ Perl_fd_mask bits[(PERL_FD_SETSIZE+PERL_NFDBITS-1)/PERL_NFDBITS];
+} Perl_fd_set;
+
+#define PERL_FD_CLR(n,p) \
+ ((p)->bits[(n)/PERL_NFDBITS] &= ~((unsigned)1 << ((n)%PERL_NFDBITS)))
+
+#define PERL_FD_SET(n,p) \
+ ((p)->bits[(n)/PERL_NFDBITS] |= ((unsigned)1 << ((n)%PERL_NFDBITS)))
+
+#define PERL_FD_ZERO(p) memset((char *)(p),0,sizeof(*(p)))
+
+#define PERL_FD_ISSET(n,p) \
+ ((p)->bits[(n)/PERL_NFDBITS] & ((unsigned)1 << ((n)%PERL_NFDBITS)))
+
+#else /* USE_SOCKETS_AS_HANDLES */
+
+#define Perl_fd_set fd_set
+#define PERL_FD_SET(n,p) FD_SET(n,p)
+#define PERL_FD_CLR(n,p) FD_CLR(n,p)
+#define PERL_FD_ISSET(n,p) FD_ISSET(n,p)
+#define PERL_FD_ZERO(p) FD_ZERO(p)
+
+#endif /* USE_SOCKETS_AS_HANDLES */
SOCKET win32_accept (SOCKET s, struct sockaddr *addr, int *addrlen);
int win32_bind (SOCKET s, const struct sockaddr *addr, int namelen);
@@ -63,7 +98,8 @@ u_short win32_ntohs (u_short netshort);
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, int *readfds, int *writefds, int *exceptfds, const struct timeval *timeout);
+int win32_select (int nfds, Perl_fd_set *rfds, Perl_fd_set *wfds, Perl_fd_set *xfds,
+ 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);
@@ -95,6 +131,7 @@ void win32_endnetent(void);
void win32_endprotoent(void);
void win32_endservent(void);
+#ifndef WIN32SCK_IS_STDSCK
//
// direct to our version
//
@@ -115,6 +152,7 @@ void win32_endservent(void);
#define recv win32_recv
#define recvfrom win32_recvfrom
#define shutdown win32_shutdown
+#define closesocket win32_closesocket
#define ioctlsocket win32_ioctlsocket
#define setsockopt win32_setsockopt
#define getsockopt win32_getsockopt
@@ -142,6 +180,21 @@ void win32_endservent(void);
#define setprotoent win32_setprotoent
#define setservent win32_setservent
+#ifdef USE_SOCKETS_AS_HANDLES
+#undef fd_set
+#undef FD_SET
+#undef FD_CLR
+#undef FD_ISSET
+#undef FD_ZERO
+#define fd_set Perl_fd_set
+#define FD_SET(n,p) PERL_FD_SET(n,p)
+#define FD_CLR(n,p) PERL_FD_CLR(n,p)
+#define FD_ISSET(n,p) PERL_FD_ISSET(n,p)
+#define FD_ZERO(p) PERL_FD_ZERO(p)
+#endif /* USE_SOCKETS_AS_HANDLES */
+
+#endif /* WIN32SCK_IS_STDSCK */
+
#ifdef __cplusplus
}
#endif
diff --git a/win32/makedef.pl b/win32/makedef.pl
index 8bc7a8a46a..abc89d848a 100644
--- a/win32/makedef.pl
+++ b/win32/makedef.pl
@@ -154,7 +154,11 @@ Perl_eval_mutex
Perl_eval_cond
Perl_eval_owner
Perl_threads_mutex
+Perl_new_struct_thread
+Perl_nthreads
Perl_nthreads_cond
+Perl_per_thread_magicals
+Perl_thrsv
Perl_unlock_condpair
Perl_vtbl_mutex
Perl_magic_mutexfree
@@ -347,6 +351,7 @@ win32_sendto
win32_recv
win32_recvfrom
win32_shutdown
+win32_closesocket
win32_ioctlsocket
win32_setsockopt
win32_getsockopt
@@ -390,8 +395,11 @@ win32_malloc
win32_calloc
win32_realloc
win32_free
-win32stdio
+win32_sleep
+win32_times
+win32_alarm
+win32_open_osfhandle
+win32_get_osfhandle
Perl_win32_init
+Perl_init_os_extras
RunPerl
-SetIOSubSystem
-GetIOSubSystem
diff --git a/win32/makefile.mk b/win32/makefile.mk
index 655efb7395..2b7dc8ccbe 100644
--- a/win32/makefile.mk
+++ b/win32/makefile.mk
@@ -10,8 +10,8 @@
# Set these to wherever you want "nmake install" to put your
# newly built perl.
INST_DRV=c:
-INST_TOP=$(INST_DRV)\perl\perl5004.5X
-BUILDOPT=-DUSE_THREADS
+INST_TOP=$(INST_DRV)\perl
+BUILDOPT=-DUSE_THREADS
# -DUSE_PERLIO -D__STDC__=1 -DUSE_SFIO -DI_SFIO -I\sfio97\include
@@ -96,7 +96,7 @@ RUNTIME = -MD
.ENDIF
INCLUDES = -I.\include -I. -I..
#PCHFLAGS = -Fp$(INTDIR)\vcmoduls.pch -YX
-DEFINES = -DWIN32 $(BUILDOPT) -D_CONSOLE -D_WIN32_WINNT=0x400
+DEFINES = -DWIN32 -D_CONSOLE $(BUILDOPT)
LOCDEFS = -DPERLDLL
SUBSYS = console
@@ -105,7 +105,7 @@ LIBC = msvcrt.lib
WINIOMAYBE =
.ELSE
LIBC = libcmt.lib
-WINIOMAYBE = win32io.obj
+WINIOMAYBE =
.ENDIF
.IF "$(CFG)" == "Debug"
@@ -131,7 +131,7 @@ LIBFILES = oldnames.lib kernel32.lib user32.lib gdi32.lib \
version.lib odbc32.lib odbccp32.lib
CFLAGS = -nologo -W3 $(INCLUDES) $(DEFINES) $(LOCDEFS) $(PCHFLAGS) $(OPTIMIZE)
-LINK_FLAGS = -nologo $(LIBFILES) $(LINK_DBG) -machine:I386
+LINK_FLAGS = -nologo $(LINK_DBG) -machine:$(PROCESSOR_ARCHITECTURE)
OBJOUT_FLAG = -Fo
.ENDIF
@@ -157,7 +157,7 @@ OBJOUT_FLAG = -Fo
.obj.dll:
$(LINK32) -dll -subsystem:windows -implib:$(*B).lib -def:$(*B).def \
- -out:$@ $(LINK_FLAGS) $< $(LIBPERL)
+ -out:$@ $(LINK_FLAGS) $(LIBFILES) $< $(LIBPERL)
.ENDIF
@@ -265,18 +265,15 @@ CORE_OBJ= ..\av.obj \
WIN32_C = perllib.c \
win32.c \
- win32io.c \
win32sck.c \
win32thread.c
WIN32_OBJ = win32.obj \
- win32io.obj \
win32sck.obj \
win32thread.obj
PERL95_OBJ = perl95.obj \
win32mt.obj \
- win32iomt.obj \
win32sckmt.obj
DLL_OBJ = perllib.obj $(DYNALOADER).obj
@@ -315,8 +312,8 @@ CORE_H = ..\av.h \
.\include\sys\socket.h \
.\win32.h
-
-EXTENSIONS=DynaLoader Socket IO Fcntl Opcode SDBM_File attrs Thread
+DYNAMIC_EXT=Socket IO Fcntl Opcode SDBM_File attrs Thread
+STATIC_EXT=DynaLoader
DYNALOADER=$(EXTDIR)\DynaLoader\DynaLoader
SOCKET=$(EXTDIR)\Socket\Socket
@@ -366,7 +363,8 @@ $(GLOBEXE): perlglob.obj
$(LINK32) -Tpe -ap $(LINK_FLAGS) c0x32.obj perlglob.obj \
$(CCLIBDIR)\32BIT\wildargs.obj,$@,,import32.lib cw32mt.lib,
.ELSE
- $(LINK32) $(LINK_FLAGS) -out:$@ -subsystem:$(SUBSYS) perlglob.obj setargv.obj
+ $(LINK32) $(LINK_FLAGS) $(LIBFILES) -out:$@ -subsystem:$(SUBSYS) \
+ perlglob.obj setargv.obj
.ENDIF
$(GLOBBAT) : ..\lib\File\DosGlob.pm $(MINIPERL)
@@ -388,7 +386,8 @@ config.w32 : $(CFGSH_TMPL)
"INST_TOP=$(INST_TOP)" "cc=$(CC)" "ccflags=$(OPTIMIZE) $(DEFINES)" \
"cf_email=$(EMAIL)" "libs=$(LIBFILES:f)" "incpath=$(CCINCDIR)" \
"libpth=$(strip $(CCLIBDIR) $(LIBFILES:d))" "libc=$(LIBC)" \
- "LINK_FLAGS=$(LINK_FLAGS)" \
+ "static_ext=$(STATIC_EXT)" "dynamic_ext=$(DYNAMIC_EXT)" \
+ "ldflags=$(LINK_FLAGS)" "optimize=$(OPTIMIZE)" \
config.w32 > ..\config.sh
$(CONFIGPM) : $(MINIPERL) ..\config.sh config_h.PL ..\minimod.pl
@@ -407,7 +406,7 @@ $(MINIPERL) : ..\miniperlmain.obj $(CORE_OBJ) $(WIN32_OBJ)
$(CORE_OBJ:s,\,\\) $(WIN32_OBJ:s,\,\\),$@,,$(LIBFILES),)
.ELSE
$(LINK32) -subsystem:console -out:$@ \
- @$(mktmp $(LINK_FLAGS) ..\miniperlmain.obj \
+ @$(mktmp $(LINK_FLAGS) $(LIBFILES) ..\miniperlmain.obj \
$(CORE_OBJ:s,\,\\) $(WIN32_OBJ:s,\,\\))
.ENDIF
@@ -429,7 +428,7 @@ $(PERLDLL): perldll.def $(CORE_OBJ) $(WIN32_OBJ) $(DLL_OBJ)
$(IMPLIB) $*.lib $@
.ELSE
$(LINK32) -dll -def:perldll.def -out:$@ \
- @$(mktmp $(LINK_FLAGS) $(CORE_OBJ:s,\,\\) \
+ @$(mktmp $(LINK_FLAGS) $(LIBFILES) $(CORE_OBJ:s,\,\\) \
$(WIN32_OBJ:s,\,\\) $(DLL_OBJ:s,\,\\))
.ENDIF
$(XCOPY) $(PERLIMPLIB) ..\lib\CORE
@@ -454,15 +453,13 @@ $(PERLEXE): $(PERLDLL) $(CONFIGPM) perlmain.obj
$@,\n \
$(PERLIMPLIB) $(LIBFILES)\n)
.ELSE
- $(LINK32) -subsystem:console -out:perl.exe $(LINK_FLAGS) \
+ $(LINK32) -subsystem:console -out:perl.exe $(LINK_FLAGS) $(LIBFILES) \
perlmain.obj $(WINIOMAYBE) $(PERLIMPLIB)
copy perl.exe $@
del perl.exe
.ENDIF
copy splittree.pl ..
$(MINIPERL) -I..\lib ..\splittree.pl "../LIB" "../LIB/auto"
-# attrib -r ..\t\*.*
-# copy test ..\t
.IF "$(CCTYPE)" != "BORLAND"
@@ -472,9 +469,6 @@ perl95.c : runperl.c
perl95.obj : perl95.c
$(CC) $(CFLAGS) -MT -UPERLDLL -c perl95.c
-win32iomt.obj : win32io.c
- $(CC) $(CFLAGS) -MT -c $(OBJOUT_FLAG)win32iomt.obj win32io.c
-
win32sckmt.obj : win32sck.c
$(CC) $(CFLAGS) -MT -c $(OBJOUT_FLAG)win32sckmt.obj win32sck.c
@@ -482,7 +476,7 @@ win32mt.obj : win32.c
$(CC) $(CFLAGS) -MT -c $(OBJOUT_FLAG)win32mt.obj win32.c
$(PERL95EXE): $(PERLDLL) $(CONFIGPM) $(PERL95_OBJ)
- $(LINK32) -subsystem:console -out:perl95.exe $(LINK_FLAGS) \
+ $(LINK32) -subsystem:console -out:perl95.exe $(LINK_FLAGS) $(LIBFILES) \
$(PERL95_OBJ) $(PERLIMPLIB)
copy perl95.exe $@
del perl95.exe
@@ -551,7 +545,7 @@ utils: $(PERLEXE)
bin\pl2bat.pl
distclean: clean
- -del /f $(MINIPERL) $(PERLEXE) $(PERLDLL) $(GLOBEXE) \
+ -del /f $(MINIPERL) $(PERLEXE) $(PERL95EXE) $(PERLDLL) $(GLOBEXE) \
$(PERLIMPLIB) ..\miniperl.lib $(MINIMOD)
-del /f *.def *.map
-del /f $(SOCKET_DLL) $(IO_DLL) $(SDBM_FILE_DLL) $(FCNTL_DLL) \
@@ -601,7 +595,7 @@ minitest : $(MINIPERL) $(GLOBEXE) $(CONFIGPM)
cd ..\t && \
$(MINIPERL) -I..\lib test base/*.t comp/*.t cmd/*.t io/*.t op/*.t pragma/*.t
-test : all
+test-prep : all
$(XCOPY) $(PERLEXE) ..\t\$(NULL)
$(XCOPY) $(PERLDLL) ..\t\$(NULL)
.IF "$(CCTYPE)" == "BORLAND"
@@ -609,8 +603,14 @@ test : all
.ELSE
$(XCOPY) $(GLOBEXE) ..\t\$(NULL)
.ENDIF
+
+test : test-prep
cd ..\t && $(PERLEXE) -I..\lib harness
+test-notty : test-prep
+ set PERL_SKIP_TTY_TEST=1 && \
+ cd ..\t && $(PERLEXE) -I.\lib harness
+
clean :
-@erase miniperlmain.obj
-@erase $(MINIPERL)
diff --git a/win32/perllib.c b/win32/perllib.c
index 317c88ac05..848360698b 100644
--- a/win32/perllib.c
+++ b/win32/perllib.c
@@ -7,12 +7,6 @@
#include "perl.h"
#include "XSUB.h"
-#ifdef __cplusplus
-# define EXTERN_C extern "C"
-#else
-# define EXTERN_C extern
-#endif
-
static void xs_init _((void));
__declspec(dllexport) int
@@ -20,9 +14,6 @@ RunPerl(int argc, char **argv, char **env, void *iosubsystem)
{
int exitstatus;
PerlInterpreter *my_perl;
- void *pOldIOSubsystem;
-
- pOldIOSubsystem = SetIOSubSystem(iosubsystem);
PERL_SYS_INIT(&argc,&argv);
@@ -43,8 +34,6 @@ RunPerl(int argc, char **argv, char **env, void *iosubsystem)
PERL_SYS_TERM();
- SetIOSubSystem(pOldIOSubsystem);
-
return (exitstatus);
}
diff --git a/win32/runperl.c b/win32/runperl.c
index 07e2bd6f83..6f84c601ea 100644
--- a/win32/runperl.c
+++ b/win32/runperl.c
@@ -1,18 +1,9 @@
-#include <stdio.h>
-#include <win32io.h>
+/* Say NO to CPP! Hallelujah! */
-#ifndef _DLL
-extern WIN32_IOSUBSYSTEM win32stdio;
-#endif
-
-extern int RunPerl(int argc, char **argv, char **env, void *iosubsystem);
+__declspec(dllimport) int RunPerl(int argc, char **argv, char **env, void *ios);
int
main(int argc, char **argv, char **env)
{
-#ifdef _DLL
- return (RunPerl(argc, argv, env, NULL));
-#else
- return (RunPerl(argc, argv, env, &win32stdio));
-#endif
+ return RunPerl(argc, argv, env, (void*)0);
}
diff --git a/win32/win32.c b/win32/win32.c
index e10bf2b463..4551679f58 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -30,18 +30,12 @@
#include <stdarg.h>
#include <float.h>
-#define CROAK croak
-#define WARN warn
-
#define EXECF_EXEC 1
#define EXECF_SPAWN 2
#define EXECF_SPAWN_NOWAIT 3
static DWORD IdOS(void);
-extern WIN32_IOSUBSYSTEM win32stdio;
-static PWIN32_IOSUBSYSTEM pIOSubSystem = &win32stdio;
-
BOOL ProbeEnv = FALSE;
DWORD Win32System = (DWORD)-1;
char szShellPath[MAX_PATH+1];
@@ -60,29 +54,6 @@ IsWinNT(void) {
return (IdOS() == VER_PLATFORM_WIN32_NT);
}
-DllExport PWIN32_IOSUBSYSTEM
-SetIOSubSystem(void *p)
-{
- PWIN32_IOSUBSYSTEM old = pIOSubSystem;
- if (p) {
- PWIN32_IOSUBSYSTEM pio = (PWIN32_IOSUBSYSTEM)p;
- if (pio->signature_begin == 12345678L
- && pio->signature_end == 87654321L) {
- pIOSubSystem = pio;
- }
- }
- else {
- pIOSubSystem = &win32stdio;
- }
- return old;
-}
-
-DllExport PWIN32_IOSUBSYSTEM
-GetIOSubSystem(void)
-{
- return pIOSubSystem;
-}
-
char *
win32PerlLibPath(void)
{
@@ -168,156 +139,12 @@ my_popen(char *cmd, char *mode)
#else
#define fixcmd(x)
#endif
-
-#if 1
-/* was #ifndef PERLDLL, but the #else stuff doesn't work on NT
- * GSAR 97/03/13
- */
fixcmd(cmd);
#ifdef __BORLANDC__ /* workaround a Borland stdio bug */
win32_fflush(stdout);
win32_fflush(stderr);
#endif
return win32_popen(cmd, mode);
-#else
-/*
- * There seems to be some problems for the _popen call in a DLL
- * this trick at the moment seems to work but it is never test
- * on NT yet
- *
- */
-# ifdef __cplusplus
-#define EXT_C_FUNC extern "C"
-# else
-#define EXT_C_FUNC extern
-# endif
-
- EXT_C_FUNC int __cdecl _set_osfhnd(int fh, long value);
- EXT_C_FUNC void __cdecl _lock_fhandle(int);
- EXT_C_FUNC void __cdecl _unlock_fhandle(int);
-
- BOOL fSuccess;
- PerlIO *pf; /* to store the _popen return value */
- int tm = 0; /* flag indicating tDllExport or binary mode */
- int fhNeeded, fhInherited, fhDup;
- int ineeded, iinherited;
- DWORD dwDup;
- int phdls[2]; /* I/O handles for pipe */
- HANDLE hPIn, hPOut, hPErr,
- hSaveStdin, hSaveStdout, hSaveStderr,
- hPNeeded, hPInherited, hPDuped;
-
- /* first check for errors in the arguments */
- if ( (cmd == NULL) || (mode == NULL)
- || ((*mode != 'w') && (*mode != _T('r'))) )
- goto error1;
-
- if ( *(mode + 1) == _T('t') )
- tm = O_TEXT;
- else if ( *(mode + 1) == _T('b') )
- tm = O_BINARY;
- else
- tm = (*mode == 'w' ? O_BINARY : O_TEXT);
-
-
- fixcmd(cmd);
- if (&win32stdio != pIOSubSystem)
- return win32_popen(cmd, mode);
-
-#ifdef EFG
- if ( _pipe( phdls, 1024, tm ) == -1 )
-#else
- if ( win32_pipe( phdls, 1024, tm ) == -1 )
-#endif
- goto error1;
-
- /* save the current situation */
- hSaveStdin = GetStdHandle(STD_INPUT_HANDLE);
- hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE);
- hSaveStderr = GetStdHandle(STD_ERROR_HANDLE);
-
- if (*mode == _T('w')) {
- ineeded = 1;
- dwDup = STD_INPUT_HANDLE;
- iinherited = 0;
- }
- else {
- ineeded = 0;
- dwDup = STD_OUTPUT_HANDLE;
- iinherited = 1;
- }
-
- fhNeeded = phdls[ineeded];
- fhInherited = phdls[iinherited];
-
- fSuccess = DuplicateHandle(GetCurrentProcess(),
- (HANDLE) stolen_get_osfhandle(fhNeeded),
- GetCurrentProcess(),
- &hPNeeded,
- 0,
- FALSE, /* not inherited */
- DUPLICATE_SAME_ACCESS);
-
- if (!fSuccess)
- goto error2;
-
- fhDup = stolen_open_osfhandle((long) hPNeeded, tm);
- win32_dup2(fhDup, fhNeeded);
- win32_close(fhDup);
-
-#ifdef AAA
- /* Close the Out pipe, child won't need it */
- hPDuped = (HANDLE) stolen_get_osfhandle(fhNeeded);
-
- _lock_fhandle(fhNeeded);
- _set_osfhnd(fhNeeded, (long)hPNeeded); /* put in ours duplicated one */
- _unlock_fhandle(fhNeeded);
-
- CloseHandle(hPDuped); /* close the handle first */
-#endif
-
- if (!SetStdHandle(dwDup, (HANDLE) stolen_get_osfhandle(fhInherited)))
- goto error2;
-
- /*
- * make sure the child see the same stderr as the calling program
- */
- if (!SetStdHandle(STD_ERROR_HANDLE,
- (HANDLE)stolen_get_osfhandle(win32_fileno(win32_stderr()))))
- goto error2;
-
- pf = win32_popen(cmd, mode); /* ask _popen to do the job */
-
- /* restore to where we were */
- SetStdHandle(STD_INPUT_HANDLE, hSaveStdin);
- SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout);
- SetStdHandle(STD_ERROR_HANDLE, hSaveStderr);
-
- /* we don't need it any more, that's for the child */
- win32_close(fhInherited);
-
- if (NULL == pf) {
- /* something wrong */
- win32_close(fhNeeded);
- goto error1;
- }
- else {
- /*
- * here we steal the file handle in pf and stuff ours in
- */
- win32_dup2(fhNeeded, win32_fileno(pf));
- win32_close(fhNeeded);
- }
- return (pf);
-
-error2:
- win32_close(fhNeeded);
- win32_close(fhInherited);
-
-error1:
- return (NULL);
-
-#endif
}
long
@@ -566,7 +393,7 @@ opendir(char *filename)
idx = strlen(FindData.cFileName)+1;
New(1304, p->start, idx, char);
if(p->start == NULL) {
- CROAK("opendir: malloc failed!\n");
+ croak("opendir: malloc failed!\n");
}
strcpy(p->start, FindData.cFileName);
/* if(downcase)
@@ -586,7 +413,7 @@ opendir(char *filename)
*/
Renew(p->start, idx+len+1, char);
if(p->start == NULL) {
- CROAK("opendir: malloc failed!\n");
+ croak("opendir: malloc failed!\n");
}
strcpy(&p->start[idx], FindData.cFileName);
/* if (downcase)
@@ -725,11 +552,11 @@ kill(int pid, int sig)
HANDLE hProcess= OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid);
if (hProcess == NULL) {
- CROAK("kill process failed!\n");
+ croak("kill process failed!\n");
}
else {
if (!TerminateProcess(hProcess, sig))
- CROAK("kill process failed!\n");
+ croak("kill process failed!\n");
CloseHandle(hProcess);
}
return 0;
@@ -743,31 +570,18 @@ kill(int pid, int sig)
int
ioctl(int i, unsigned int u, char *data)
{
- CROAK("ioctl not implemented!\n");
+ croak("ioctl not implemented!\n");
return -1;
}
#endif
-unsigned int
-sleep(unsigned int t)
+DllExport unsigned int
+win32_sleep(unsigned int t)
{
Sleep(t*1000);
return 0;
}
-
-#undef rename
-
-int
-myrename(char *OldFileName, char *newname)
-{
- if(_access(newname, 0) != -1) { /* file exists */
- _unlink(newname);
- }
- return rename(OldFileName, newname);
-}
-
-
DllExport int
win32_stat(const char *path, struct stat *buffer)
{
@@ -787,7 +601,7 @@ win32_stat(const char *path, struct stat *buffer)
};
}
}
- res = pIOSubSystem->pfnstat(p,buffer);
+ res = stat(p,buffer);
#ifdef __BORLANDC__
if (res == 0) {
if (S_ISDIR(buffer->st_mode))
@@ -843,9 +657,8 @@ FileTimeToClock(PFILETIME ft)
return (long) qw;
}
-#undef times
-int
-mytimes(struct tms *timebuf)
+DllExport int
+win32_times(struct tms *timebuf)
{
FILETIME user;
FILETIME kernel;
@@ -878,9 +691,8 @@ static VOID CALLBACK TimerProc(HWND win, UINT msg, UINT id, DWORD time)
sighandler(14);
}
-#undef alarm
-unsigned int
-myalarm(unsigned int sec)
+DllExport unsigned int
+win32_alarm(unsigned int sec)
{
/*
* the 'obvious' implentation is SetTimer() with a callback
@@ -908,6 +720,154 @@ myalarm(unsigned int sec)
return 0;
}
+#ifdef USE_FIXED_OSFHANDLE
+
+EXTERN_C int __cdecl _alloc_osfhnd(void);
+EXTERN_C int __cdecl _set_osfhnd(int fh, long value);
+EXTERN_C void __cdecl _lock_fhandle(int);
+EXTERN_C void __cdecl _unlock_fhandle(int);
+EXTERN_C void __cdecl _unlock(int);
+
+#if (_MSC_VER >= 1000)
+typedef struct {
+ long osfhnd; /* underlying OS file HANDLE */
+ char osfile; /* attributes of file (e.g., open in text mode?) */
+ char pipech; /* one char buffer for handles opened on pipes */
+#if defined (_MT) && !defined (DLL_FOR_WIN32S)
+ int lockinitflag;
+ CRITICAL_SECTION lock;
+#endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
+} ioinfo;
+
+EXTERN_C ioinfo * __pioinfo[];
+
+#define IOINFO_L2E 5
+#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
+#define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
+#define _osfile(i) (_pioinfo(i)->osfile)
+
+#else /* (_MSC_VER >= 1000) */
+extern char _osfile[];
+#endif /* (_MSC_VER >= 1000) */
+
+#define FOPEN 0x01 /* file handle open */
+#define FAPPEND 0x20 /* file handle opened O_APPEND */
+#define FDEV 0x40 /* file handle refers to device */
+#define FTEXT 0x80 /* file handle is in text mode */
+
+#define _STREAM_LOCKS 26 /* Table of stream locks */
+#define _LAST_STREAM_LOCK (_STREAM_LOCKS+_NSTREAM_-1) /* Last stream lock */
+#define _FH_LOCKS (_LAST_STREAM_LOCK+1) /* Table of fh locks */
+
+/***
+*int my_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
+*
+*Purpose:
+* This function allocates a free C Runtime file handle and associates
+* it with the Win32 HANDLE specified by the first parameter. This is a
+* temperary fix for WIN95's brain damage GetFileType() error on socket
+* we just bypass that call for socket
+*
+*Entry:
+* long osfhandle - Win32 HANDLE to associate with C Runtime file handle.
+* int flags - flags to associate with C Runtime file handle.
+*
+*Exit:
+* returns index of entry in fh, if successful
+* return -1, if no free entry is found
+*
+*Exceptions:
+*
+*******************************************************************************/
+
+static int
+my_open_osfhandle(long osfhandle, int flags)
+{
+ int fh;
+ char fileflags; /* _osfile flags */
+
+ /* copy relevant flags from second parameter */
+ fileflags = FDEV;
+
+ if(flags & O_APPEND)
+ fileflags |= FAPPEND;
+
+ if(flags & O_TEXT)
+ fileflags |= FTEXT;
+
+ /* attempt to allocate a C Runtime file handle */
+ if((fh = _alloc_osfhnd()) == -1) {
+ errno = EMFILE; /* too many open files */
+ _doserrno = 0L; /* not an OS error */
+ return -1; /* return error to caller */
+ }
+
+ /* the file is open. now, set the info in _osfhnd array */
+ _set_osfhnd(fh, osfhandle);
+
+ fileflags |= FOPEN; /* mark as open */
+
+#if (_MSC_VER >= 1000)
+ _osfile(fh) = fileflags; /* set osfile entry */
+ _unlock_fhandle(fh);
+#else
+ _osfile[fh] = fileflags; /* set osfile entry */
+ _unlock(fh+_FH_LOCKS); /* unlock handle */
+#endif
+
+ return fh; /* return handle */
+}
+
+#define _open_osfhandle my_open_osfhandle
+#endif /* USE_FIXED_OSFHANDLE */
+
+/* simulate flock by locking a range on the file */
+
+#define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
+#define LK_LEN 0xffff0000
+
+DllExport int
+win32_flock(int fd, int oper)
+{
+ OVERLAPPED o;
+ int i = -1;
+ HANDLE fh;
+
+ if (!IsWinNT()) {
+ croak("flock() unimplemented on this platform");
+ return -1;
+ }
+ fh = (HANDLE)_get_osfhandle(fd);
+ memset(&o, 0, sizeof(o));
+
+ switch(oper) {
+ case LOCK_SH: /* shared lock */
+ LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
+ break;
+ case LOCK_EX: /* exclusive lock */
+ LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
+ break;
+ case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
+ LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
+ break;
+ case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
+ LK_ERR(LockFileEx(fh,
+ LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
+ 0, LK_LEN, 0, &o),i);
+ break;
+ case LOCK_UN: /* unlock lock */
+ LK_ERR(UnlockFileEx(fh, 0, LK_LEN, 0, &o),i);
+ break;
+ default: /* unknown */
+ errno = EINVAL;
+ break;
+ }
+ return i;
+}
+
+#undef LK_ERR
+#undef LK_LEN
+
/*
* redirected io subsystem for all XS modules
*
@@ -916,45 +876,45 @@ myalarm(unsigned int sec)
DllExport int *
win32_errno(void)
{
- return (pIOSubSystem->pfnerrno());
+ return (&errno);
}
DllExport char ***
win32_environ(void)
{
- return (pIOSubSystem->pfnenviron());
+ return (&(_environ));
}
/* the rest are the remapped stdio routines */
DllExport FILE *
win32_stderr(void)
{
- return (pIOSubSystem->pfnstderr());
+ return (stderr);
}
DllExport FILE *
win32_stdin(void)
{
- return (pIOSubSystem->pfnstdin());
+ return (stdin);
}
DllExport FILE *
win32_stdout()
{
- return (pIOSubSystem->pfnstdout());
+ return (stdout);
}
DllExport int
win32_ferror(FILE *fp)
{
- return (pIOSubSystem->pfnferror(fp));
+ return (ferror(fp));
}
DllExport int
win32_feof(FILE *fp)
{
- return (pIOSubSystem->pfnfeof(fp));
+ return (feof(fp));
}
/*
@@ -983,7 +943,7 @@ win32_strerror(int e)
return strerror_buffer;
}
- return pIOSubSystem->pfnstrerror(e);
+ return strerror(e);
}
DllExport int
@@ -992,7 +952,7 @@ win32_fprintf(FILE *fp, const char *format, ...)
va_list marker;
va_start(marker, format); /* Initialize variable arguments. */
- return (pIOSubSystem->pfnvfprintf(fp, format, marker));
+ return (vfprintf(fp, format, marker));
}
DllExport int
@@ -1001,188 +961,193 @@ win32_printf(const char *format, ...)
va_list marker;
va_start(marker, format); /* Initialize variable arguments. */
- return (pIOSubSystem->pfnvprintf(format, marker));
+ return (vprintf(format, marker));
}
DllExport int
win32_vfprintf(FILE *fp, const char *format, va_list args)
{
- return (pIOSubSystem->pfnvfprintf(fp, format, args));
+ return (vfprintf(fp, format, args));
}
DllExport int
win32_vprintf(const char *format, va_list args)
{
- return (pIOSubSystem->pfnvprintf(format, args));
+ return (vprintf(format, args));
}
DllExport size_t
win32_fread(void *buf, size_t size, size_t count, FILE *fp)
{
- return pIOSubSystem->pfnfread(buf, size, count, fp);
+ return fread(buf, size, count, fp);
}
DllExport size_t
win32_fwrite(const void *buf, size_t size, size_t count, FILE *fp)
{
- return pIOSubSystem->pfnfwrite(buf, size, count, fp);
+ return fwrite(buf, size, count, fp);
}
DllExport FILE *
win32_fopen(const char *filename, const char *mode)
{
if (stricmp(filename, "/dev/null")==0)
- return pIOSubSystem->pfnfopen("NUL", mode);
- return pIOSubSystem->pfnfopen(filename, mode);
+ return fopen("NUL", mode);
+ return fopen(filename, mode);
}
+#ifndef USE_SOCKETS_AS_HANDLES
+#undef fdopen
+#define fdopen my_fdopen
+#endif
+
DllExport FILE *
win32_fdopen( int handle, const char *mode)
{
- return pIOSubSystem->pfnfdopen(handle, (char *) mode);
+ return fdopen(handle, (char *) mode);
}
DllExport FILE *
win32_freopen( const char *path, const char *mode, FILE *stream)
{
if (stricmp(path, "/dev/null")==0)
- return pIOSubSystem->pfnfreopen("NUL", mode, stream);
- return pIOSubSystem->pfnfreopen(path, mode, stream);
+ return freopen("NUL", mode, stream);
+ return freopen(path, mode, stream);
}
DllExport int
win32_fclose(FILE *pf)
{
- return pIOSubSystem->pfnfclose(pf);
+ return my_fclose(pf); /* defined in win32sck.c */
}
DllExport int
win32_fputs(const char *s,FILE *pf)
{
- return pIOSubSystem->pfnfputs(s, pf);
+ return fputs(s, pf);
}
DllExport int
win32_fputc(int c,FILE *pf)
{
- return pIOSubSystem->pfnfputc(c,pf);
+ return fputc(c,pf);
}
DllExport int
win32_ungetc(int c,FILE *pf)
{
- return pIOSubSystem->pfnungetc(c,pf);
+ return ungetc(c,pf);
}
DllExport int
win32_getc(FILE *pf)
{
- return pIOSubSystem->pfngetc(pf);
+ return getc(pf);
}
DllExport int
win32_fileno(FILE *pf)
{
- return pIOSubSystem->pfnfileno(pf);
+ return fileno(pf);
}
DllExport void
win32_clearerr(FILE *pf)
{
- pIOSubSystem->pfnclearerr(pf);
+ clearerr(pf);
return;
}
DllExport int
win32_fflush(FILE *pf)
{
- return pIOSubSystem->pfnfflush(pf);
+ return fflush(pf);
}
DllExport long
win32_ftell(FILE *pf)
{
- return pIOSubSystem->pfnftell(pf);
+ return ftell(pf);
}
DllExport int
win32_fseek(FILE *pf,long offset,int origin)
{
- return pIOSubSystem->pfnfseek(pf, offset, origin);
+ return fseek(pf, offset, origin);
}
DllExport int
win32_fgetpos(FILE *pf,fpos_t *p)
{
- return pIOSubSystem->pfnfgetpos(pf, p);
+ return fgetpos(pf, p);
}
DllExport int
win32_fsetpos(FILE *pf,const fpos_t *p)
{
- return pIOSubSystem->pfnfsetpos(pf, p);
+ return fsetpos(pf, p);
}
DllExport void
win32_rewind(FILE *pf)
{
- pIOSubSystem->pfnrewind(pf);
+ rewind(pf);
return;
}
DllExport FILE*
win32_tmpfile(void)
{
- return pIOSubSystem->pfntmpfile();
+ return tmpfile();
}
DllExport void
win32_abort(void)
{
- pIOSubSystem->pfnabort();
+ abort();
return;
}
DllExport int
win32_fstat(int fd,struct stat *bufptr)
{
- return pIOSubSystem->pfnfstat(fd,bufptr);
+ return fstat(fd,bufptr);
}
DllExport int
win32_pipe(int *pfd, unsigned int size, int mode)
{
- return pIOSubSystem->pfnpipe(pfd, size, mode);
+ return _pipe(pfd, size, mode);
}
DllExport FILE*
win32_popen(const char *command, const char *mode)
{
- return pIOSubSystem->pfnpopen(command, mode);
+ return _popen(command, mode);
}
DllExport int
win32_pclose(FILE *pf)
{
- return pIOSubSystem->pfnpclose(pf);
+ return _pclose(pf);
}
DllExport int
win32_setmode(int fd, int mode)
{
- return pIOSubSystem->pfnsetmode(fd, mode);
+ return setmode(fd, mode);
}
DllExport long
win32_lseek(int fd, long offset, int origin)
{
- return pIOSubSystem->pfnlseek(fd, offset, origin);
+ return lseek(fd, offset, origin);
}
DllExport long
win32_tell(int fd)
{
- return pIOSubSystem->pfntell(fd);
+ return tell(fd);
}
DllExport int
@@ -1196,198 +1161,188 @@ win32_open(const char *path, int flag, ...)
va_end(ap);
if (stricmp(path, "/dev/null")==0)
- return pIOSubSystem->pfnopen("NUL", flag, pmode);
- return pIOSubSystem->pfnopen(path,flag,pmode);
+ return open("NUL", flag, pmode);
+ return open(path,flag,pmode);
}
DllExport int
win32_close(int fd)
{
- return pIOSubSystem->pfnclose(fd);
+ return close(fd);
}
DllExport int
win32_eof(int fd)
{
- return pIOSubSystem->pfneof(fd);
+ return eof(fd);
}
DllExport int
win32_dup(int fd)
{
- return pIOSubSystem->pfndup(fd);
+ return dup(fd);
}
DllExport int
win32_dup2(int fd1,int fd2)
{
- return pIOSubSystem->pfndup2(fd1,fd2);
+ return dup2(fd1,fd2);
}
DllExport int
win32_read(int fd, void *buf, unsigned int cnt)
{
- return pIOSubSystem->pfnread(fd, buf, cnt);
+ return read(fd, buf, cnt);
}
DllExport int
win32_write(int fd, const void *buf, unsigned int cnt)
{
- return pIOSubSystem->pfnwrite(fd, buf, cnt);
+ return write(fd, buf, cnt);
}
DllExport int
win32_mkdir(const char *dir, int mode)
{
- return pIOSubSystem->pfnmkdir(dir); /* just ignore mode */
+ return mkdir(dir); /* just ignore mode */
}
DllExport int
win32_rmdir(const char *dir)
{
- return pIOSubSystem->pfnrmdir(dir);
+ return rmdir(dir);
}
DllExport int
win32_chdir(const char *dir)
{
- return pIOSubSystem->pfnchdir(dir);
+ return chdir(dir);
}
DllExport int
win32_spawnvp(int mode, const char *cmdname, const char *const *argv)
{
- return pIOSubSystem->pfnspawnvp(mode, cmdname, (char * const *) argv);
+ return spawnvp(mode, cmdname, (char * const *) argv);
}
DllExport int
win32_execvp(const char *cmdname, const char *const *argv)
{
- return pIOSubSystem->pfnexecvp(cmdname, (char *const *)argv);
+ return execvp(cmdname, (char *const *)argv);
}
DllExport void
win32_perror(const char *str)
{
- pIOSubSystem->pfnperror(str);
+ perror(str);
}
DllExport void
win32_setbuf(FILE *pf, char *buf)
{
- pIOSubSystem->pfnsetbuf(pf, buf);
+ setbuf(pf, buf);
}
DllExport int
win32_setvbuf(FILE *pf, char *buf, int type, size_t size)
{
- return pIOSubSystem->pfnsetvbuf(pf, buf, type, size);
+ return setvbuf(pf, buf, type, size);
}
DllExport int
win32_flushall(void)
{
- return pIOSubSystem->pfnflushall();
+ return flushall();
}
DllExport int
win32_fcloseall(void)
{
- return pIOSubSystem->pfnfcloseall();
+ return fcloseall();
}
DllExport char*
win32_fgets(char *s, int n, FILE *pf)
{
- return pIOSubSystem->pfnfgets(s, n, pf);
+ return fgets(s, n, pf);
}
DllExport char*
win32_gets(char *s)
{
- return pIOSubSystem->pfngets(s);
+ return gets(s);
}
DllExport int
win32_fgetc(FILE *pf)
{
- return pIOSubSystem->pfnfgetc(pf);
+ return fgetc(pf);
}
DllExport int
win32_putc(int c, FILE *pf)
{
- return pIOSubSystem->pfnputc(c,pf);
+ return putc(c,pf);
}
DllExport int
win32_puts(const char *s)
{
- return pIOSubSystem->pfnputs(s);
+ return puts(s);
}
DllExport int
win32_getchar(void)
{
- return pIOSubSystem->pfngetchar();
+ return getchar();
}
DllExport int
win32_putchar(int c)
{
- return pIOSubSystem->pfnputchar(c);
+ return putchar(c);
}
DllExport void*
win32_malloc(size_t size)
{
- return pIOSubSystem->pfnmalloc(size);
+ return malloc(size);
}
DllExport void*
win32_calloc(size_t numitems, size_t size)
{
- return pIOSubSystem->pfncalloc(numitems,size);
+ return calloc(numitems,size);
}
DllExport void*
win32_realloc(void *block, size_t size)
{
- return pIOSubSystem->pfnrealloc(block,size);
+ return realloc(block,size);
}
DllExport void
win32_free(void *block)
{
- pIOSubSystem->pfnfree(block);
+ free(block);
}
int
-stolen_open_osfhandle(long handle, int flags)
+win32_open_osfhandle(long handle, int flags)
{
- return pIOSubSystem->pfn_open_osfhandle(handle, flags);
+ return _open_osfhandle(handle, flags);
}
long
-stolen_get_osfhandle(int fd)
+win32_get_osfhandle(int fd)
{
- return pIOSubSystem->pfn_get_osfhandle(fd);
+ return _get_osfhandle(fd);
}
/*
* Extras.
*/
-DllExport int
-win32_flock(int fd, int oper)
-{
- if (!IsWinNT()) {
- croak("flock() unimplemented on this platform");
- return -1;
- }
- return pIOSubSystem->pfnflock(fd, oper);
-}
-
static
XS(w32_GetCwd)
{
@@ -1639,7 +1594,7 @@ XS(w32_GetShortPathName)
}
void
-init_os_extras()
+Perl_init_os_extras()
{
char *file = __FILE__;
dXSUB_SYS;
diff --git a/win32/win32.h b/win32/win32.h
index 525ef0f6cc..18bf8a2e96 100644
--- a/win32/win32.h
+++ b/win32/win32.h
@@ -22,10 +22,51 @@
#include <process.h>
#include <stdio.h>
#include <direct.h>
+#include <stdlib.h>
+#ifndef EXT
+#include "EXTERN.h"
+#endif
-/* For UNIX compatibility. */
+#ifndef START_EXTERN_C
+#ifdef __cplusplus
+# define START_EXTERN_C extern "C" {
+# define END_EXTERN_C }
+# define EXTERN_C extern "C"
+#else
+# define START_EXTERN_C
+# define END_EXTERN_C
+# define EXTERN_C
+#endif
+#endif
+
+#define STANDARD_C 1
+#define DOSISH 1 /* no escaping our roots */
+#define OP_BINARY O_BINARY /* mistake in in pp_sys.c? */
+#define DllExport __declspec(dllexport)
+#define DllImport __declspec(dllimport)
+
+/* Define USE_SOCKETS_AS_HANDLES to enable emulation of windows sockets as
+ * real filehandles. XXX Should always be defined (the other version is untested) */
+#define USE_SOCKETS_AS_HANDLES
+
+/* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
+ * to read the environment, bypassing the runtime's (usually broken)
+ * facilities for accessing the same. See note in util.c/my_setenv(). */
+/*#define USE_WIN32_RTL_ENV */
+
+/* Define USE_FIXED_OSFHANDLE to fix VC's _open_osfhandle() on W95.
+ * Can only enable it if not using the DLL CRT (it doesn't expose internals) */
+#if defined(_MSC_VER) && !defined(_DLL) && defined(_M_IX86)
+#define USE_FIXED_OSFHANDLE
+#endif
+
+#ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers dont have this */
+#define VER_PLATFORM_WIN32_WINDOWS 1
+#endif
+
+/* Compiler-specific stuff. */
-#ifdef __BORLANDC__
+#ifdef __BORLANDC__ /* Microsoft Visual C++ */
#define _access access
#define _chdir chdir
@@ -47,136 +88,61 @@
#else
+#ifdef _MSC_VER /* Microsoft Visual C++ */
+
typedef long uid_t;
typedef long gid_t;
+#pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761)
-#endif
+#endif /* _MSC_VER */
+
+/* compatibility stuff for other compilers goes here */
-#ifdef __cplusplus
-extern "C" {
#endif
+START_EXTERN_C
+
+/* For UNIX compatibility. */
+
extern uid_t getuid(void);
extern gid_t getgid(void);
extern uid_t geteuid(void);
extern gid_t getegid(void);
extern int setuid(uid_t uid);
extern int setgid(gid_t gid);
-
extern int kill(int pid, int sig);
-#ifdef __cplusplus
-}
-#endif
-
-
-extern char *staticlinkmodules[];
-
-/* if USE_WIN32_RTL_ENV is not defined, Perl uses direct Win32 calls
- * to read the environment, bypassing the runtime's (usually broken)
- * facilities for accessing the same. See note in util.c/my_setenv().
- */
-/*#define USE_WIN32_RTL_ENV */
-
-#ifndef USE_WIN32_RTL_ENV
-#include <stdlib.h>
-#ifndef EXT
-#include "EXTERN.h"
-#endif
-#undef getenv
-#define getenv win32_getenv
-EXT char *win32_getenv(const char *name);
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#undef Stat
+#define Stat win32_stat
+#undef init_os_extras
+#define init_os_extras Perl_init_os_extras
-EXT void Perl_win32_init(int *argcp, char ***argvp);
+EXT void Perl_win32_init(int *argcp, char ***argvp);
+EXT void Perl_init_os_extras(void);
-#define USE_SOCKETS_AS_HANDLES
#ifndef USE_SOCKETS_AS_HANDLES
-
-extern FILE *myfdopen(int, char *);
-
-#undef fdopen
-#define fdopen myfdopen
-#endif /* USE_SOCKETS_AS_HANDLES */
-
-#define STANDARD_C 1 /* Perl5 likes standard C. */
-#define DOSISH 1 /* Take advantage of DOSish code in Perl5. */
-
-#define OP_BINARY O_BINARY /* Mistake in in pp_sys.c. */
-
-#undef pipe
-#define pipe(fd) win32_pipe((fd), 512, O_BINARY) /* the pipe call is a bit different */
-
-#undef pause
-#define pause() sleep((32767L << 16) + 32767)
-
-
-#undef times
-#define times mytimes
-
-#undef alarm
-#define alarm myalarm
-
-struct tms {
- long tms_utime;
- long tms_stime;
- long tms_cutime;
- long tms_cstime;
-};
-
-unsigned int sleep(unsigned int);
-char *win32PerlLibPath(void);
-char *win32SiteLibPath(void);
-int mytimes(struct tms *timebuf);
-unsigned int myalarm(unsigned int sec);
-int do_aspawn(void* really, void ** mark, void ** arglast);
-int do_spawn(char *cmd);
-char do_exec(char *cmd);
-void init_os_extras(void);
-
-#ifdef __cplusplus
-}
+extern FILE * my_fdopen(int, char *);
#endif
+extern int my_fclose(FILE *);
+extern int do_aspawn(void* really, void ** mark, void ** arglast);
+extern int do_spawn(char *cmd);
+extern char do_exec(char *cmd);
+extern char * win32PerlLibPath(void);
+extern char * win32SiteLibPath(void);
+extern int IsWin95(void);
+extern int IsWinNT(void);
-typedef char * caddr_t; /* In malloc.c (core address). */
+extern char * staticlinkmodules[];
-/*
- * Extension Library, only good for VC
- */
+END_EXTERN_C
-#define DllExport __declspec(dllexport)
-#define DllImport __declspec(dllimport)
+typedef char * caddr_t; /* In malloc.c (core address). */
/*
* handle socket stuff, assuming socket is always available
*/
-
#include <sys/socket.h>
#include <netdb.h>
-#ifdef _MSC_VER
-#pragma warning(disable: 4018 4035 4101 4102 4244 4245 4761)
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int IsWin95(void);
-int IsWinNT(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#ifndef VER_PLATFORM_WIN32_WINDOWS /* VC-2.0 headers dont have this */
-#define VER_PLATFORM_WIN32_WINDOWS 1
-#endif
-
#endif /* _INC_WIN32_PERL5 */
diff --git a/win32/win32io.c b/win32/win32io.c
deleted file mode 100644
index 0e2e649059..0000000000
--- a/win32/win32io.c
+++ /dev/null
@@ -1,333 +0,0 @@
-
-
-#define WIN32_LEAN_AND_MEAN
-#include <stdio.h>
-extern int my_fclose(FILE *pf);
-#include "EXTERN.h"
-#define WIN32IO_IS_STDIO
-#include <windows.h>
-#include <stdlib.h>
-#include <io.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <fcntl.h>
-#include <assert.h>
-#include <errno.h>
-#include <process.h>
-#include <direct.h>
-
-
-#ifdef __cplusplus
-#define START_EXTERN_C extern "C" {
-#define END_EXTERN_C }
-#else
-#define START_EXTERN_C
-#define END_EXTERN_C
-#endif
-
-#include "win32iop.h"
-
-/*
- * The following is just a basic wrapping of the stdio
- *
- * redirected io subsystem for all XS modules
- */
-
-static int *
-dummy_errno(void)
-{
- return (&(errno));
-}
-
-static char ***
-dummy_environ(void)
-{
- return (&(_environ));
-}
-
-/* the rest are the remapped stdio routines */
-static FILE *
-dummy_stderr(void)
-{
- return stderr;
-}
-
-static FILE *
-dummy_stdin(void)
-{
- return stdin;
-}
-
-static FILE *
-dummy_stdout(void)
-{
- return stdout;
-}
-
-static int
-dummy_globalmode(int mode)
-{
- int o = _fmode;
- _fmode = mode;
-
- return o;
-}
-
-#if defined(_DLL) || defined(__BORLANDC__)
-/* It may or may not be fixed (ok on NT), but DLL runtime
- does not export the functions used in the workround
-*/
-#define WIN95_OSFHANDLE_FIXED
-#endif
-
-#if defined(_WIN32) && !defined(WIN95_OSFHANDLE_FIXED) && defined(_M_IX86)
-
-# ifdef __cplusplus
-#define EXT_C_FUNC extern "C"
-# else
-#define EXT_C_FUNC extern
-# endif
-
-EXT_C_FUNC int __cdecl _alloc_osfhnd(void);
-EXT_C_FUNC int __cdecl _set_osfhnd(int fh, long value);
-EXT_C_FUNC void __cdecl _lock_fhandle(int);
-EXT_C_FUNC void __cdecl _unlock_fhandle(int);
-EXT_C_FUNC void __cdecl _unlock(int);
-
-#if (_MSC_VER >= 1000)
-typedef struct {
- long osfhnd; /* underlying OS file HANDLE */
- char osfile; /* attributes of file (e.g., open in text mode?) */
- char pipech; /* one char buffer for handles opened on pipes */
-#if defined (_MT) && !defined (DLL_FOR_WIN32S)
- int lockinitflag;
- CRITICAL_SECTION lock;
-#endif /* defined (_MT) && !defined (DLL_FOR_WIN32S) */
-} ioinfo;
-
-EXT_C_FUNC ioinfo * __pioinfo[];
-
-#define IOINFO_L2E 5
-#define IOINFO_ARRAY_ELTS (1 << IOINFO_L2E)
-#define _pioinfo(i) (__pioinfo[i >> IOINFO_L2E] + (i & (IOINFO_ARRAY_ELTS - 1)))
-#define _osfile(i) (_pioinfo(i)->osfile)
-
-#else /* (_MSC_VER >= 1000) */
-extern char _osfile[];
-#endif /* (_MSC_VER >= 1000) */
-
-#define FOPEN 0x01 /* file handle open */
-#define FAPPEND 0x20 /* file handle opened O_APPEND */
-#define FDEV 0x40 /* file handle refers to device */
-#define FTEXT 0x80 /* file handle is in text mode */
-
-#define _STREAM_LOCKS 26 /* Table of stream locks */
-#define _LAST_STREAM_LOCK (_STREAM_LOCKS+_NSTREAM_-1) /* Last stream lock */
-#define _FH_LOCKS (_LAST_STREAM_LOCK+1) /* Table of fh locks */
-
-/***
-*int _patch_open_osfhandle(long osfhandle, int flags) - open C Runtime file handle
-*
-*Purpose:
-* This function allocates a free C Runtime file handle and associates
-* it with the Win32 HANDLE specified by the first parameter. This is a
-* temperary fix for WIN95's brain damage GetFileType() error on socket
-* we just bypass that call for socket
-*
-*Entry:
-* long osfhandle - Win32 HANDLE to associate with C Runtime file handle.
-* int flags - flags to associate with C Runtime file handle.
-*
-*Exit:
-* returns index of entry in fh, if successful
-* return -1, if no free entry is found
-*
-*Exceptions:
-*
-*******************************************************************************/
-
-int
-my_open_osfhandle(long osfhandle, int flags)
-{
- int fh;
- char fileflags; /* _osfile flags */
-
- /* copy relevant flags from second parameter */
- fileflags = FDEV;
-
- if(flags & O_APPEND)
- fileflags |= FAPPEND;
-
- if(flags & O_TEXT)
- fileflags |= FTEXT;
-
- /* attempt to allocate a C Runtime file handle */
- if((fh = _alloc_osfhnd()) == -1) {
- errno = EMFILE; /* too many open files */
- _doserrno = 0L; /* not an OS error */
- return -1; /* return error to caller */
- }
-
- /* the file is open. now, set the info in _osfhnd array */
- _set_osfhnd(fh, osfhandle);
-
- fileflags |= FOPEN; /* mark as open */
-
-#if (_MSC_VER >= 1000)
- _osfile(fh) = fileflags; /* set osfile entry */
- _unlock_fhandle(fh);
-#else
- _osfile[fh] = fileflags; /* set osfile entry */
- _unlock(fh+_FH_LOCKS); /* unlock handle */
-#endif
-
- return fh; /* return handle */
-}
-#else
-
-int __cdecl
-my_open_osfhandle(long osfhandle, int flags)
-{
- return _open_osfhandle(osfhandle, flags);
-}
-#endif /* _M_IX86 */
-
-long
-my_get_osfhandle( int filehandle )
-{
- return _get_osfhandle(filehandle);
-}
-
-#ifdef __BORLANDC__
-#define _chdir chdir
-#endif
-
-/* simulate flock by locking a range on the file */
-
-
-#define LK_ERR(f,i) ((f) ? (i = 0) : (errno = GetLastError()))
-#define LK_LEN 0xffff0000
-
-int
-my_flock(int fd, int oper)
-{
- OVERLAPPED o;
- int i = -1;
- HANDLE fh;
-
- fh = (HANDLE)my_get_osfhandle(fd);
- memset(&o, 0, sizeof(o));
-
- switch(oper) {
- case LOCK_SH: /* shared lock */
- LK_ERR(LockFileEx(fh, 0, 0, LK_LEN, 0, &o),i);
- break;
- case LOCK_EX: /* exclusive lock */
- LK_ERR(LockFileEx(fh, LOCKFILE_EXCLUSIVE_LOCK, 0, LK_LEN, 0, &o),i);
- break;
- case LOCK_SH|LOCK_NB: /* non-blocking shared lock */
- LK_ERR(LockFileEx(fh, LOCKFILE_FAIL_IMMEDIATELY, 0, LK_LEN, 0, &o),i);
- break;
- case LOCK_EX|LOCK_NB: /* non-blocking exclusive lock */
- LK_ERR(LockFileEx(fh,
- LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY,
- 0, LK_LEN, 0, &o),i);
- break;
- case LOCK_UN: /* unlock lock */
- LK_ERR(UnlockFileEx(fh, 0, LK_LEN, 0, &o),i);
- break;
- default: /* unknown */
- errno = EINVAL;
- break;
- }
- return i;
-}
-
-#undef LK_ERR
-#undef LK_LEN
-
-
-#ifdef PERLDLL
-__declspec(dllexport)
-#endif
-WIN32_IOSUBSYSTEM win32stdio = {
- 12345678L, /* begin of structure; */
- dummy_errno, /* (*pfunc_errno)(void); */
- dummy_environ, /* (*pfunc_environ)(void); */
- dummy_stdin, /* (*pfunc_stdin)(void); */
- dummy_stdout, /* (*pfunc_stdout)(void); */
- dummy_stderr, /* (*pfunc_stderr)(void); */
- ferror, /* (*pfunc_ferror)(FILE *fp); */
- feof, /* (*pfunc_feof)(FILE *fp); */
- strerror, /* (*strerror)(int e); */
- vfprintf, /* (*pfunc_vfprintf)(FILE *pf, const char *format, va_list arg); */
- vprintf, /* (*pfunc_vprintf)(const char *format, va_list arg); */
- fread, /* (*pfunc_fread)(void *buf, size_t size, size_t count, FILE *pf); */
- fwrite, /* (*pfunc_fwrite)(void *buf, size_t size, size_t count, FILE *pf); */
- fopen, /* (*pfunc_fopen)(const char *path, const char *mode); */
- fdopen, /* (*pfunc_fdopen)(int fh, const char *mode); */
- freopen, /* (*pfunc_freopen)(const char *path, const char *mode, FILE *pf); */
- my_fclose, /* (*pfunc_fclose)(FILE *pf); */
- fputs, /* (*pfunc_fputs)(const char *s,FILE *pf); */
- fputc, /* (*pfunc_fputc)(int c,FILE *pf); */
- ungetc, /* (*pfunc_ungetc)(int c,FILE *pf); */
- getc, /* (*pfunc_getc)(FILE *pf); */
- fileno, /* (*pfunc_fileno)(FILE *pf); */
- clearerr, /* (*pfunc_clearerr)(FILE *pf); */
- fflush, /* (*pfunc_fflush)(FILE *pf); */
- ftell, /* (*pfunc_ftell)(FILE *pf); */
- fseek, /* (*pfunc_fseek)(FILE *pf,long offset,int origin); */
- fgetpos, /* (*pfunc_fgetpos)(FILE *pf,fpos_t *p); */
- fsetpos, /* (*pfunc_fsetpos)(FILE *pf,fpos_t *p); */
- rewind, /* (*pfunc_rewind)(FILE *pf); */
- tmpfile, /* (*pfunc_tmpfile)(void); */
- abort, /* (*pfunc_abort)(void); */
- fstat, /* (*pfunc_fstat)(int fd,struct stat *bufptr); */
- stat, /* (*pfunc_stat)(const char *name,struct stat *bufptr); */
- _pipe, /* (*pfunc_pipe)( int *phandles, unsigned int psize, int textmode ); */
- _popen, /* (*pfunc_popen)( const char *command, const char *mode ); */
- _pclose, /* (*pfunc_pclose)( FILE *pf); */
- setmode, /* (*pfunc_setmode)( int fd, int mode); */
- lseek, /* (*pfunc_lseek)( int fd, long offset, int origin); */
- tell, /* (*pfunc_tell)( int fd); */
- dup, /* (*pfunc_dup)( int fd); */
- dup2, /* (*pfunc_dup2)(int h1, int h2); */
- open, /* (*pfunc_open)(const char *path, int oflag,...); */
- close, /* (*pfunc_close)(int fd); */
- eof, /* (*pfunc_eof)(int fd); */
- read, /* (*pfunc_read)(int fd, void *buf, unsigned int cnt); */
- write, /* (*pfunc_write)(int fd, const void *buf, unsigned int cnt); */
- dummy_globalmode, /* (*pfunc_globalmode)(int mode) */
- my_open_osfhandle,
- my_get_osfhandle,
- spawnvp,
- mkdir,
- rmdir,
- chdir,
- my_flock, /* (*pfunc_flock)(int fd, int oper) */
- execvp,
- perror,
- setbuf,
- setvbuf,
- flushall,
- fcloseall,
- fgets,
- gets,
- fgetc,
- putc,
- puts,
- getchar,
- putchar,
- fscanf,
- scanf,
- malloc,
- calloc,
- realloc,
- free,
- 87654321L, /* end of structure */
-};
-
-
-
-
-
diff --git a/win32/win32io.h b/win32/win32io.h
deleted file mode 100644
index 0e849cf783..0000000000
--- a/win32/win32io.h
+++ /dev/null
@@ -1,91 +0,0 @@
-#ifndef WIN32IO_H
-#define WIN32IO_H
-
-#ifdef __BORLANDC__
-#include <stdarg.h>
-#define MSconst
-#else
-#define MSconst const
-#endif
-
-typedef struct {
-int signature_begin;
-int * (*pfnerrno)(void);
-char ***(*pfnenviron)(void);
-FILE* (*pfnstdin)(void);
-FILE* (*pfnstdout)(void);
-FILE* (*pfnstderr)(void);
-int (*pfnferror)(FILE *fp);
-int (*pfnfeof)(FILE *fp);
-char* (*pfnstrerror)(int e);
-int (*pfnvfprintf)(FILE *pf, const char *format, va_list arg);
-int (*pfnvprintf)(const char *format, va_list arg);
-size_t (*pfnfread)(void *buf, size_t size, size_t count, FILE *pf);
-size_t (*pfnfwrite)(const void *buf, size_t size, size_t count, FILE *pf);
-FILE* (*pfnfopen)(const char *path, const char *mode);
-FILE* (*pfnfdopen)(int fh, MSconst char *mode);
-FILE* (*pfnfreopen)(const char *path, const char *mode, FILE *pf);
-int (*pfnfclose)(FILE *pf);
-int (*pfnfputs)(const char *s,FILE *pf);
-int (*pfnfputc)(int c,FILE *pf);
-int (*pfnungetc)(int c,FILE *pf);
-int (*pfngetc)(FILE *pf);
-int (*pfnfileno)(FILE *pf);
-void (*pfnclearerr)(FILE *pf);
-int (*pfnfflush)(FILE *pf);
-long (*pfnftell)(FILE *pf);
-int (*pfnfseek)(FILE *pf,long offset,int origin);
-int (*pfnfgetpos)(FILE *pf,fpos_t *p);
-int (*pfnfsetpos)(FILE *pf,const fpos_t *p);
-void (*pfnrewind)(FILE *pf);
-FILE* (*pfntmpfile)(void);
-void (*pfnabort)(void);
-int (*pfnfstat)(int fd,struct stat *bufptr);
-int (*pfnstat)(const char *name,struct stat *bufptr);
-int (*pfnpipe)( int *phandles, unsigned int psize, int textmode );
-FILE* (*pfnpopen)( const char *command, const char *mode );
-int (*pfnpclose)( FILE *pf);
-int (*pfnsetmode)( int fd, int mode);
-long (*pfnlseek)( int fd, long offset, int origin);
-long (*pfntell)( int fd);
-int (*pfndup)( int fd);
-int (*pfndup2)(int h1, int h2);
-int (*pfnopen)(const char *path, int oflag,...);
-int (*pfnclose)(int fd);
-int (*pfneof)(int fd);
-int (*pfnread)(int fd, void *buf, unsigned int cnt);
-int (*pfnwrite)(int fd, const void *buf, unsigned int cnt);
-int (*pfnopenmode)(int mode);
-int (*pfn_open_osfhandle)(long handle, int flags);
-long (*pfn_get_osfhandle)(int fd);
-int (*pfnspawnvp)(int mode, const char *cmdname, MSconst char * const *argv);
-int (*pfnmkdir)(const char *path);
-int (*pfnrmdir)(const char *path);
-int (*pfnchdir)(const char *path);
-int (*pfnflock)(int fd, int oper);
-int (*pfnexecvp)(const char *cmdname, MSconst char *const *argv);
-void (*pfnperror)(const char *str);
-void (*pfnsetbuf)(FILE *pf, char *buf);
-int (*pfnsetvbuf)(FILE *pf, char *buf, int type, size_t size);
-int (*pfnflushall)(void);
-int (*pfnfcloseall)(void);
-char* (*pfnfgets)(char *s, int n, FILE *pf);
-char* (*pfngets)(char *s);
-int (*pfnfgetc)(FILE *pf);
-int (*pfnputc)(int c, FILE *pf);
-int (*pfnputs)(const char *s);
-int (*pfngetchar)(void);
-int (*pfnputchar)(int c);
-int (*pfnfscanf)(FILE *pf, const char *format, ...);
-int (*pfnscanf)(const char *format, ...);
-void* (*pfnmalloc)(size_t size);
-void* (*pfncalloc)(size_t numitems, size_t size);
-void* (*pfnrealloc)(void *block, size_t size);
-void (*pfnfree)(void *block);
-int signature_end;
-} WIN32_IOSUBSYSTEM;
-
-typedef WIN32_IOSUBSYSTEM *PWIN32_IOSUBSYSTEM;
-
-#endif /* WIN32IO_H */
-
diff --git a/win32/win32iop.h b/win32/win32iop.h
index 52acce1a9b..a60194d0f0 100644
--- a/win32/win32iop.h
+++ b/win32/win32iop.h
@@ -1,6 +1,18 @@
#ifndef WIN32IOP_H
#define WIN32IOP_H
+#ifndef START_EXTERN_C
+#ifdef __cplusplus
+# define START_EXTERN_C extern "C" {
+# define END_EXTERN_C }
+# define EXTERN_C extern "C"
+#else
+# define START_EXTERN_C
+# define END_EXTERN_C
+# define EXTERN_C
+#endif
+#endif
+
/*
* defines for flock emulation
*/
@@ -9,8 +21,6 @@
#define LOCK_NB 4
#define LOCK_UN 8
-#include <win32io.h> /* pull in the io sub system structure */
-
/*
* Make this as close to original stdio as possible.
*/
@@ -20,6 +30,13 @@
*/
START_EXTERN_C
+struct tms {
+ long tms_utime;
+ long tms_stime;
+ long tms_cutime;
+ long tms_cstime;
+};
+
EXT int * win32_errno(void);
EXT char *** win32_environ(void);
EXT FILE* win32_stdin(void);
@@ -92,17 +109,18 @@ EXT void* win32_calloc(size_t numitems, size_t size);
EXT void* win32_realloc(void *block, size_t size);
EXT void win32_free(void *block);
+EXT int win32_open_osfhandle(long handle, int flags);
+EXT long win32_get_osfhandle(int fd);
+#ifndef USE_WIN32_RTL_ENV
+EXT char* win32_getenv(const char *name);
+#endif
-/*
- * these two are win32 specific but still io related
- */
-int stolen_open_osfhandle(long handle, int flags);
-long stolen_get_osfhandle(int fd);
-
-
-EXT PWIN32_IOSUBSYSTEM SetIOSubSystem(void *piosubsystem);
-EXT PWIN32_IOSUBSYSTEM GetIOSubSystem(void);
+EXT unsigned int win32_sleep(unsigned int);
+EXT int win32_times(struct tms *timebuf);
+EXT unsigned int win32_alarm(unsigned int sec);
+EXT int win32_flock(int fd, int oper);
+EXT int win32_stat(const char *path, struct stat *buf);
END_EXTERN_C
@@ -117,6 +135,12 @@ END_EXTERN_C
#undef stdout
#undef ferror
#undef feof
+#undef fclose
+#undef pipe
+#undef pause
+#undef sleep
+#undef times
+#undef alarm
#ifdef __BORLANDC__
#undef ungetc
@@ -175,8 +199,8 @@ END_EXTERN_C
#define eof(fd) win32_eof(fd)
#define read(fd,b,s) win32_read(fd,b,s)
#define write(fd,b,s) win32_write(fd,b,s)
-#define _open_osfhandle stolen_open_osfhandle
-#define _get_osfhandle stolen_get_osfhandle
+#define _open_osfhandle win32_open_osfhandle
+#define _get_osfhandle win32_get_osfhandle
#define spawnvp win32_spawnvp
#define mkdir win32_mkdir
#define rmdir win32_rmdir
@@ -195,12 +219,21 @@ END_EXTERN_C
#define puts win32_puts
#define getchar win32_getchar
#define putchar win32_putchar
-#define fscanf (GetIOSubSystem()->pfnfscanf)
-#define scanf (GetIOSubSystem()->pfnscanf)
#define malloc win32_malloc
#define calloc win32_calloc
#define realloc win32_realloc
#define free win32_free
-#endif /* WIN32IO_IS_STDIO */
+#define pipe(fd) win32_pipe((fd), 512, O_BINARY)
+#define pause() win32_sleep((32767L << 16) + 32767)
+#define sleep win32_sleep
+#define times win32_times
+#define alarm win32_alarm
+
+#ifndef USE_WIN32_RTL_ENV
+#undef getenv
+#define getenv win32_getenv
+#endif
+
+#endif /* WIN32IO_IS_STDIO */
#endif /* WIN32IOP_H */
diff --git a/win32/win32sck.c b/win32/win32sck.c
index b4ad4f4cfb..559691a350 100644
--- a/win32/win32sck.c
+++ b/win32/win32sck.c
@@ -1,4 +1,4 @@
-/* NTSock.C
+/* win32sck.c
*
* (c) 1995 Microsoft Corporation. All rights reserved.
* Developed by hip communications inc., http://info.hip.com/info/
@@ -8,202 +8,72 @@
* License or the Artistic License, as specified in the README file.
*/
-#include <windows.h>
+#define WIN32IO_IS_STDIO
+#define WIN32SCK_IS_STDSCK
#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#include "EXTERN.h"
#include "perl.h"
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <assert.h>
+#include <io.h>
-#define CROAK croak
-
-#ifdef USE_SOCKETS_AS_HANDLES
/* thanks to Beverly Brown (beverly@datacube.com) */
-
-#define OPEN_SOCKET(x) _open_osfhandle(x,O_RDWR|O_BINARY)
-#define TO_SOCKET(x) _get_osfhandle(x)
-
+#ifdef USE_SOCKETS_AS_HANDLES
+# define OPEN_SOCKET(x) _open_osfhandle(x,O_RDWR|O_BINARY)
+# define TO_SOCKET(x) _get_osfhandle(x)
#else
-
# define OPEN_SOCKET(x) (x)
# define TO_SOCKET(x) (x)
-
#endif /* USE_SOCKETS_AS_HANDLES */
+#define StartSockets() \
+ STMT_START { \
+ if (!wsock_started) \
+ start_sockets(); \
+ } STMT_END
+
+#define EndSockets() \
+ STMT_START { \
+ if (wsock_started) \
+ WSACleanup(); \
+ } STMT_END
+
+#define SOCKET_TEST(x, y) \
+ STMT_START { \
+ StartSockets(); \
+ if((x) == (y)) \
+ errno = WSAGetLastError(); \
+ } STMT_END
+
+#define SOCKET_TEST_ERROR(x) SOCKET_TEST(x, SOCKET_ERROR)
+
static struct servent* win32_savecopyservent(struct servent*d,
struct servent*s,
const char *proto);
-#define SOCKETAPI PASCAL
-
-typedef SOCKET (SOCKETAPI *LPSOCKACCEPT)(SOCKET, struct sockaddr *, int *);
-typedef int (SOCKETAPI *LPSOCKBIND)(SOCKET, const struct sockaddr *, int);
-typedef int (SOCKETAPI *LPSOCKCLOSESOCKET)(SOCKET);
-typedef int (SOCKETAPI *LPSOCKCONNECT)(SOCKET, const struct sockaddr *, int);
-typedef int (SOCKETAPI *LPSOCKIOCTLSOCKET)(SOCKET, long, u_long *);
-typedef int (SOCKETAPI *LPSOCKGETPEERNAME)(SOCKET, struct sockaddr *, int *);
-typedef int (SOCKETAPI *LPSOCKGETSOCKNAME)(SOCKET, struct sockaddr *, int *);
-typedef int (SOCKETAPI *LPSOCKGETSOCKOPT)(SOCKET, int, int, char *, int *);
-typedef u_long (SOCKETAPI *LPSOCKHTONL)(u_long);
-typedef u_short (SOCKETAPI *LPSOCKHTONS)(u_short);
-typedef int (SOCKETAPI *LPSOCKLISTEN)(SOCKET, int);
-typedef u_long (SOCKETAPI *LPSOCKNTOHL)(u_long);
-typedef u_short (SOCKETAPI *LPSOCKNTOHS)(u_short);
-typedef int (SOCKETAPI *LPSOCKRECV)(SOCKET, char *, int, int);
-typedef int (SOCKETAPI *LPSOCKRECVFROM)(SOCKET, char *, int, int, struct sockaddr *, int *);
-typedef int (SOCKETAPI *LPSOCKSELECT)(int, fd_set *, fd_set *, fd_set *, const struct timeval *);
-typedef int (SOCKETAPI *LPSOCKSEND)(SOCKET, const char *, int, int);
-typedef int (SOCKETAPI *LPSOCKSENDTO)(SOCKET, const char *, int, int, const struct sockaddr *, int);
-typedef int (SOCKETAPI *LPSOCKSETSOCKOPT)(SOCKET, int, int, const char *, int);
-typedef int (SOCKETAPI *LPSOCKSHUTDOWN)(SOCKET, int);
-typedef SOCKET (SOCKETAPI *LPSOCKSOCKET)(int, int, int);
-typedef char FAR *(SOCKETAPI *LPSOCKINETNTOA)(struct in_addr in);
-typedef unsigned long (SOCKETAPI *LPSOCKINETADDR)(const char FAR * cp);
-
-
-/* Database function prototypes */
-typedef struct hostent *(SOCKETAPI *LPSOCKGETHOSTBYADDR)(const char *, int, int);
-typedef struct hostent *(SOCKETAPI *LPSOCKGETHOSTBYNAME)(const char *);
-typedef int (SOCKETAPI *LPSOCKGETHOSTNAME)(char *, int);
-typedef struct servent *(SOCKETAPI *LPSOCKGETSERVBYPORT)(int, const char *);
-typedef struct servent *(SOCKETAPI *LPSOCKGETSERVBYNAME)(const char *, const char *);
-typedef struct protoent *(SOCKETAPI *LPSOCKGETPROTOBYNUMBER)(int);
-typedef struct protoent *(SOCKETAPI *LPSOCKGETPROTOBYNAME)(const char *);
-
-/* Microsoft Windows Extension function prototypes */
-typedef int (SOCKETAPI *LPSOCKWSASTARTUP)(unsigned short, LPWSADATA);
-typedef int (SOCKETAPI *LPSOCKWSACLEANUP)(void);
-typedef int (SOCKETAPI *LPSOCKWSAGETLASTERROR)(void);
-typedef int (SOCKETAPI *LPWSAFDIsSet)(SOCKET, fd_set *);
-
-static HINSTANCE hWinSockDll = 0;
-/* extern CRITICAL_SECTION csSock; */
-
-static LPSOCKACCEPT paccept = 0;
-static LPSOCKBIND pbind = 0;
-static LPSOCKCLOSESOCKET pclosesocket = 0;
-static LPSOCKCONNECT pconnect = 0;
-static LPSOCKIOCTLSOCKET pioctlsocket = 0;
-static LPSOCKGETPEERNAME pgetpeername = 0;
-static LPSOCKGETSOCKNAME pgetsockname = 0;
-static LPSOCKGETSOCKOPT pgetsockopt = 0;
-static LPSOCKHTONL phtonl = 0;
-static LPSOCKHTONS phtons = 0;
-static LPSOCKLISTEN plisten = 0;
-static LPSOCKNTOHL pntohl = 0;
-static LPSOCKNTOHS pntohs = 0;
-static LPSOCKRECV precv = 0;
-static LPSOCKRECVFROM precvfrom = 0;
-static LPSOCKSELECT pselect = 0;
-static LPSOCKSEND psend = 0;
-static LPSOCKSENDTO psendto = 0;
-static LPSOCKSETSOCKOPT psetsockopt = 0;
-static LPSOCKSHUTDOWN pshutdown = 0;
-static LPSOCKSOCKET psocket = 0;
-static LPSOCKGETHOSTBYADDR pgethostbyaddr = 0;
-static LPSOCKGETHOSTBYNAME pgethostbyname = 0;
-static LPSOCKGETHOSTNAME pgethostname = 0;
-static LPSOCKGETSERVBYPORT pgetservbyport = 0;
-static LPSOCKGETSERVBYNAME pgetservbyname = 0;
-static LPSOCKGETPROTOBYNUMBER pgetprotobynumber = 0;
-static LPSOCKGETPROTOBYNAME pgetprotobyname = 0;
-static LPSOCKWSASTARTUP pWSAStartup = 0;
-static LPSOCKWSACLEANUP pWSACleanup = 0;
-static LPSOCKWSAGETLASTERROR pWSAGetLastError = 0;
-static LPWSAFDIsSet pWSAFDIsSet = 0;
-static LPSOCKINETNTOA pinet_ntoa = 0;
-static LPSOCKINETADDR pinet_addr = 0;
__declspec(thread) struct servent myservent;
-
-
-void *
-GetAddress(HINSTANCE hInstance, char *lpFunctionName)
-{
- FARPROC proc = GetProcAddress(hInstance, lpFunctionName);
- if(proc == 0)
- CROAK("Unable to get address of %s in WSock32.dll", lpFunctionName);
- return proc;
-}
-
-void
-LoadWinSock(void)
-{
-/* EnterCriticalSection(&csSock); */
- if(hWinSockDll == NULL) {
- HINSTANCE hLib = LoadLibrary("WSock32.DLL");
- if(hLib == NULL)
- CROAK("Could not load WSock32.dll\n");
-
- paccept = (LPSOCKACCEPT)GetAddress(hLib, "accept");
- pbind = (LPSOCKBIND)GetAddress(hLib, "bind");
- pclosesocket = (LPSOCKCLOSESOCKET)GetAddress(hLib, "closesocket");
- pconnect = (LPSOCKCONNECT)GetAddress(hLib, "connect");
- pioctlsocket = (LPSOCKIOCTLSOCKET)GetAddress(hLib, "ioctlsocket");
- pgetpeername = (LPSOCKGETPEERNAME)GetAddress(hLib, "getpeername");
- pgetsockname = (LPSOCKGETSOCKNAME)GetAddress(hLib, "getsockname");
- pgetsockopt = (LPSOCKGETSOCKOPT)GetAddress(hLib, "getsockopt");
- phtonl = (LPSOCKHTONL)GetAddress(hLib, "htonl");
- phtons = (LPSOCKHTONS)GetAddress(hLib, "htons");
- plisten = (LPSOCKLISTEN)GetAddress(hLib, "listen");
- pntohl = (LPSOCKNTOHL)GetAddress(hLib, "ntohl");
- pntohs = (LPSOCKNTOHS)GetAddress(hLib, "ntohs");
- precv = (LPSOCKRECV)GetAddress(hLib, "recv");
- precvfrom = (LPSOCKRECVFROM)GetAddress(hLib, "recvfrom");
- pselect = (LPSOCKSELECT)GetAddress(hLib, "select");
- psend = (LPSOCKSEND)GetAddress(hLib, "send");
- psendto = (LPSOCKSENDTO)GetAddress(hLib, "sendto");
- psetsockopt = (LPSOCKSETSOCKOPT)GetAddress(hLib, "setsockopt");
- pshutdown = (LPSOCKSHUTDOWN)GetAddress(hLib, "shutdown");
- psocket = (LPSOCKSOCKET)GetAddress(hLib, "socket");
- pgethostbyaddr = (LPSOCKGETHOSTBYADDR)GetAddress(hLib, "gethostbyaddr");
- pgethostbyname = (LPSOCKGETHOSTBYNAME)GetAddress(hLib, "gethostbyname");
- pgethostname = (LPSOCKGETHOSTNAME)GetAddress(hLib, "gethostname");
- pgetservbyport = (LPSOCKGETSERVBYPORT)GetAddress(hLib, "getservbyport");
- pgetservbyname = (LPSOCKGETSERVBYNAME)GetAddress(hLib, "getservbyname");
- pgetprotobynumber = (LPSOCKGETPROTOBYNUMBER)GetAddress(hLib, "getprotobynumber");
- pgetprotobyname = (LPSOCKGETPROTOBYNAME)GetAddress(hLib, "getprotobyname");
- pWSAStartup = (LPSOCKWSASTARTUP)GetAddress(hLib, "WSAStartup");
- pWSACleanup = (LPSOCKWSACLEANUP)GetAddress(hLib, "WSACleanup");
- pWSAGetLastError = (LPSOCKWSAGETLASTERROR)GetAddress(hLib, "WSAGetLastError");
- pWSAFDIsSet = (LPWSAFDIsSet)GetAddress(hLib, "__WSAFDIsSet");
- pinet_addr = (LPSOCKINETADDR)GetAddress(hLib,"inet_addr");
- pinet_ntoa = (LPSOCKINETNTOA)GetAddress(hLib,"inet_ntoa");
-
- hWinSockDll = hLib;
- }
-/* LeaveCriticalSection(&csSock); */
-}
+static int wsock_started = 0;
void
-EndSockets(void)
-{
- if(hWinSockDll != NULL) {
- pWSACleanup();
- FreeLibrary(hWinSockDll);
- }
- hWinSockDll = NULL;
-}
-
-void
-StartSockets(void)
+start_sockets(void)
{
unsigned short version;
WSADATA retdata;
int ret;
int iSockOpt = SO_SYNCHRONOUS_NONALERT;
- LoadWinSock();
/*
* initalize the winsock interface and insure that it is
* cleaned up at exit.
*/
version = 0x101;
- if(ret = pWSAStartup(version, &retdata))
- CROAK("Unable to locate winsock library!\n");
+ if(ret = WSAStartup(version, &retdata))
+ croak("Unable to locate winsock library!\n");
if(retdata.wVersion != version)
- CROAK("Could not find version 1.1 of winsock dll\n");
+ croak("Could not find version 1.1 of winsock dll\n");
/* atexit((void (*)(void)) EndSockets); */
@@ -211,26 +81,28 @@ StartSockets(void)
/*
* Enable the use of sockets as filehandles
*/
- psetsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
+ setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
(char *)&iSockOpt, sizeof(iSockOpt));
#endif /* USE_SOCKETS_AS_HANDLES */
+ wsock_started = 1;
}
#ifndef USE_SOCKETS_AS_HANDLES
+#undef fdopen
FILE *
-myfdopen(int fd, char *mode)
+my_fdopen(int fd, char *mode)
{
FILE *fp;
char sockbuf[256];
int optlen = sizeof(sockbuf);
int retval;
- if (hWinSockDll == 0)
+ if (!wsock_started)
return(fdopen(fd, mode));
- retval = pgetsockopt((SOCKET)fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
- if(retval == SOCKET_ERROR && pWSAGetLastError() == WSAENOTSOCK) {
+ retval = getsockopt((SOCKET)fd, SOL_SOCKET, SO_TYPE, sockbuf, &optlen);
+ if(retval == SOCKET_ERROR && WSAGetLastError() == WSAENOTSOCK) {
return(fdopen(fd, mode));
}
@@ -257,51 +129,39 @@ myfdopen(int fd, char *mode)
u_long
win32_htonl(u_long hostlong)
{
- if(hWinSockDll == 0)
- StartSockets();
-
- return phtonl(hostlong);
+ StartSockets();
+ return htonl(hostlong);
}
u_short
win32_htons(u_short hostshort)
{
- if(hWinSockDll == 0)
- StartSockets();
-
- return phtons(hostshort);
+ StartSockets();
+ return htons(hostshort);
}
u_long
win32_ntohl(u_long netlong)
{
- if(hWinSockDll == 0)
- StartSockets();
-
- return pntohl(netlong);
+ StartSockets();
+ return ntohl(netlong);
}
u_short
win32_ntohs(u_short netshort)
{
- if(hWinSockDll == 0)
- StartSockets();
-
- return pntohs(netshort);
+ StartSockets();
+ return ntohs(netshort);
}
-#define SOCKET_TEST(x, y) if(hWinSockDll == 0) StartSockets();\
- if((x) == (y)) errno = pWSAGetLastError()
-
-#define SOCKET_TEST_ERROR(x) SOCKET_TEST(x, SOCKET_ERROR)
SOCKET
win32_accept(SOCKET s, struct sockaddr *addr, int *addrlen)
{
SOCKET r;
- SOCKET_TEST((r = paccept(TO_SOCKET(s), addr, addrlen)), INVALID_SOCKET);
+ SOCKET_TEST((r = accept(TO_SOCKET(s), addr, addrlen)), INVALID_SOCKET);
return OPEN_SOCKET(r);
}
@@ -310,7 +170,7 @@ win32_bind(SOCKET s, const struct sockaddr *addr, int addrlen)
{
int r;
- SOCKET_TEST_ERROR(r = pbind(TO_SOCKET(s), addr, addrlen));
+ SOCKET_TEST_ERROR(r = bind(TO_SOCKET(s), addr, addrlen));
return r;
}
@@ -319,7 +179,7 @@ win32_connect(SOCKET s, const struct sockaddr *addr, int addrlen)
{
int r;
- SOCKET_TEST_ERROR(r = pconnect(TO_SOCKET(s), addr, addrlen));
+ SOCKET_TEST_ERROR(r = connect(TO_SOCKET(s), addr, addrlen));
return r;
}
@@ -329,7 +189,7 @@ win32_getpeername(SOCKET s, struct sockaddr *addr, int *addrlen)
{
int r;
- SOCKET_TEST_ERROR(r = pgetpeername(TO_SOCKET(s), addr, addrlen));
+ SOCKET_TEST_ERROR(r = getpeername(TO_SOCKET(s), addr, addrlen));
return r;
}
@@ -338,7 +198,7 @@ win32_getsockname(SOCKET s, struct sockaddr *addr, int *addrlen)
{
int r;
- SOCKET_TEST_ERROR(r = pgetsockname(TO_SOCKET(s), addr, addrlen));
+ SOCKET_TEST_ERROR(r = getsockname(TO_SOCKET(s), addr, addrlen));
return r;
}
@@ -347,7 +207,7 @@ win32_getsockopt(SOCKET s, int level, int optname, char *optval, int *optlen)
{
int r;
- SOCKET_TEST_ERROR(r = pgetsockopt(TO_SOCKET(s), level, optname, optval, optlen));
+ SOCKET_TEST_ERROR(r = getsockopt(TO_SOCKET(s), level, optname, optval, optlen));
return r;
}
@@ -356,7 +216,7 @@ win32_ioctlsocket(SOCKET s, long cmd, u_long *argp)
{
int r;
- SOCKET_TEST_ERROR(r = pioctlsocket(TO_SOCKET(s), cmd, argp));
+ SOCKET_TEST_ERROR(r = ioctlsocket(TO_SOCKET(s), cmd, argp));
return r;
}
@@ -365,7 +225,7 @@ win32_listen(SOCKET s, int backlog)
{
int r;
- SOCKET_TEST_ERROR(r = plisten(TO_SOCKET(s), backlog));
+ SOCKET_TEST_ERROR(r = listen(TO_SOCKET(s), backlog));
return r;
}
@@ -374,7 +234,7 @@ win32_recv(SOCKET s, char *buf, int len, int flags)
{
int r;
- SOCKET_TEST_ERROR(r = precv(TO_SOCKET(s), buf, len, flags));
+ SOCKET_TEST_ERROR(r = recv(TO_SOCKET(s), buf, len, flags));
return r;
}
@@ -383,19 +243,21 @@ win32_recvfrom(SOCKET s, char *buf, int len, int flags, struct sockaddr *from, i
{
int r;
- SOCKET_TEST_ERROR(r = precvfrom(TO_SOCKET(s), buf, len, flags, from, fromlen));
+ SOCKET_TEST_ERROR(r = recvfrom(TO_SOCKET(s), buf, len, flags, from, fromlen));
return r;
}
/* select contributed by Vincent R. Slyngstad (vrs@ibeam.intel.com) */
int
-win32_select(int nfds, int* rd, int* wr, int* ex, const struct timeval* timeout)
+win32_select(int nfds, Perl_fd_set* rd, Perl_fd_set* wr, Perl_fd_set* ex, const struct timeval* timeout)
{
- long r;
- int dummy = 0;
+ int r;
+#ifdef USE_SOCKETS_AS_HANDLES
+ Perl_fd_set dummy;
int i, fd, bit, offset;
- FD_SET nrd, nwr, nex,*prd,*pwr,*pex;
+ FD_SET nrd, nwr, nex, *prd, *pwr, *pex;
+ PERL_FD_ZERO(&dummy);
if (!rd)
rd = &dummy, prd = NULL;
else
@@ -414,35 +276,28 @@ win32_select(int nfds, int* rd, int* wr, int* ex, const struct timeval* timeout)
FD_ZERO(&nex);
for (i = 0; i < nfds; i++) {
fd = TO_SOCKET(i);
- bit = 1L<<(i % (sizeof(int)*8));
- offset = i / (sizeof(int)*8);
- if (rd[offset] & bit)
+ if (PERL_FD_ISSET(i,rd))
FD_SET(fd, &nrd);
- if (wr[offset] & bit)
+ if (PERL_FD_ISSET(i,wr))
FD_SET(fd, &nwr);
- if (ex[offset] & bit)
+ if (PERL_FD_ISSET(i,ex))
FD_SET(fd, &nex);
}
- SOCKET_TEST_ERROR(r = pselect(nfds, prd, pwr, pex, timeout));
+ SOCKET_TEST_ERROR(r = select(nfds, prd, pwr, pex, timeout));
for (i = 0; i < nfds; i++) {
fd = TO_SOCKET(i);
- bit = 1L<<(i % (sizeof(int)*8));
- offset = i / (sizeof(int)*8);
- if (rd[offset] & bit) {
- if (!pWSAFDIsSet(fd, &nrd))
- rd[offset] &= ~bit;
- }
- if (wr[offset] & bit) {
- if (!pWSAFDIsSet(fd, &nwr))
- wr[offset] &= ~bit;
- }
- if (ex[offset] & bit) {
- if (!pWSAFDIsSet(fd, &nex))
- ex[offset] &= ~bit;
- }
+ if (PERL_FD_ISSET(i,rd) && !FD_ISSET(fd, &nrd))
+ PERL_FD_CLR(i,rd);
+ if (PERL_FD_ISSET(i,wr) && !FD_ISSET(fd, &nwr))
+ PERL_FD_CLR(i,wr);
+ if (PERL_FD_ISSET(i,ex) && !FD_ISSET(fd, &nex))
+ PERL_FD_CLR(i,ex);
}
+#else
+ SOCKET_TEST_ERROR(r = select(nfds, rd, wr, ex, timeout));
+#endif
return r;
}
@@ -451,7 +306,7 @@ win32_send(SOCKET s, const char *buf, int len, int flags)
{
int r;
- SOCKET_TEST_ERROR(r = psend(TO_SOCKET(s), buf, len, flags));
+ SOCKET_TEST_ERROR(r = send(TO_SOCKET(s), buf, len, flags));
return r;
}
@@ -461,7 +316,7 @@ win32_sendto(SOCKET s, const char *buf, int len, int flags,
{
int r;
- SOCKET_TEST_ERROR(r = psendto(TO_SOCKET(s), buf, len, flags, to, tolen));
+ SOCKET_TEST_ERROR(r = sendto(TO_SOCKET(s), buf, len, flags, to, tolen));
return r;
}
@@ -470,7 +325,7 @@ win32_setsockopt(SOCKET s, int level, int optname, const char *optval, int optle
{
int r;
- SOCKET_TEST_ERROR(r = psetsockopt(TO_SOCKET(s), level, optname, optval, optlen));
+ SOCKET_TEST_ERROR(r = setsockopt(TO_SOCKET(s), level, optname, optval, optlen));
return r;
}
@@ -479,7 +334,16 @@ win32_shutdown(SOCKET s, int how)
{
int r;
- SOCKET_TEST_ERROR(r = pshutdown(TO_SOCKET(s), how));
+ SOCKET_TEST_ERROR(r = shutdown(TO_SOCKET(s), how));
+ return r;
+}
+
+int
+win32_closesocket(SOCKET s)
+{
+ int r;
+
+ SOCKET_TEST_ERROR(r = closesocket(TO_SOCKET(s)));
return r;
}
@@ -489,13 +353,11 @@ win32_socket(int af, int type, int protocol)
SOCKET s;
#ifndef USE_SOCKETS_AS_HANDLES
- SOCKET_TEST(s = psocket(af, type, protocol), INVALID_SOCKET);
+ SOCKET_TEST(s = socket(af, type, protocol), INVALID_SOCKET);
#else
- if(hWinSockDll == 0)
- StartSockets();
-
- if((s = psocket(af, type, protocol)) == INVALID_SOCKET)
- errno = pWSAGetLastError();
+ StartSockets();
+ if((s = socket(af, type, protocol)) == INVALID_SOCKET)
+ errno = WSAGetLastError();
else
s = OPEN_SOCKET(s);
#endif /* USE_SOCKETS_AS_HANDLES */
@@ -507,16 +369,18 @@ win32_socket(int af, int type, int protocol)
int
my_fclose (FILE *pf)
{
- int osf, retval;
- if (hWinSockDll == 0) /* No WinSockDLL? */
- return(fclose(pf)); /* Then not a socket. */
- osf = TO_SOCKET(fileno(pf)); /* Get it now before it's gone! */
- retval = fclose(pf); /* Must fclose() before closesocket() */
- if (osf != -1
- && pclosesocket(osf) == SOCKET_ERROR
- && WSAGetLastError() != WSAENOTSOCK)
- retval = EOF;
- return retval;
+ int osf, retval;
+ if (!wsock_started) /* No WinSock? */
+ return(fclose(pf)); /* Then not a socket. */
+ osf = TO_SOCKET(fileno(pf));/* Get it now before it's gone! */
+ retval = fclose(pf); /* Must fclose() before closesocket() */
+ if (osf != -1
+ && closesocket(osf) == SOCKET_ERROR
+ && WSAGetLastError() != WSAENOTSOCK)
+ {
+ return EOF;
+ }
+ return retval;
}
struct hostent *
@@ -524,7 +388,7 @@ win32_gethostbyaddr(const char *addr, int len, int type)
{
struct hostent *r;
- SOCKET_TEST(r = pgethostbyaddr(addr, len, type), NULL);
+ SOCKET_TEST(r = gethostbyaddr(addr, len, type), NULL);
return r;
}
@@ -533,7 +397,7 @@ win32_gethostbyname(const char *name)
{
struct hostent *r;
- SOCKET_TEST(r = pgethostbyname(name), NULL);
+ SOCKET_TEST(r = gethostbyname(name), NULL);
return r;
}
@@ -542,7 +406,7 @@ win32_gethostname(char *name, int len)
{
int r;
- SOCKET_TEST_ERROR(r = pgethostname(name, len));
+ SOCKET_TEST_ERROR(r = gethostname(name, len));
return r;
}
@@ -551,7 +415,7 @@ win32_getprotobyname(const char *name)
{
struct protoent *r;
- SOCKET_TEST(r = pgetprotobyname(name), NULL);
+ SOCKET_TEST(r = getprotobyname(name), NULL);
return r;
}
@@ -560,7 +424,7 @@ win32_getprotobynumber(int num)
{
struct protoent *r;
- SOCKET_TEST(r = pgetprotobynumber(num), NULL);
+ SOCKET_TEST(r = getprotobynumber(num), NULL);
return r;
}
@@ -569,7 +433,7 @@ win32_getservbyname(const char *name, const char *proto)
{
struct servent *r;
- SOCKET_TEST(r = pgetservbyname(name, proto), NULL);
+ SOCKET_TEST(r = getservbyname(name, proto), NULL);
if (r) {
r = win32_savecopyservent(&myservent, r, proto);
}
@@ -581,7 +445,7 @@ win32_getservbyport(int port, const char *proto)
{
struct servent *r;
- SOCKET_TEST(r = pgetservbyport(port, proto), NULL);
+ SOCKET_TEST(r = getservbyport(port, proto), NULL);
if (r) {
r = win32_savecopyservent(&myservent, r, proto);
}
@@ -591,126 +455,108 @@ win32_getservbyport(int port, const char *proto)
char FAR *
win32_inet_ntoa(struct in_addr in)
{
- if(hWinSockDll == 0)
- StartSockets();
-
- return pinet_ntoa(in);
+ StartSockets();
+ return inet_ntoa(in);
}
unsigned long
win32_inet_addr(const char FAR *cp)
{
- if(hWinSockDll == 0)
- StartSockets();
-
- return pinet_addr(cp);
-
+ StartSockets();
+ return inet_addr(cp);
}
/*
* Networking stubs
*/
-#undef CROAK
-#define CROAK croak
void
win32_endhostent()
{
- CROAK("endhostent not implemented!\n");
+ croak("endhostent not implemented!\n");
}
void
win32_endnetent()
{
- CROAK("endnetent not implemented!\n");
+ croak("endnetent not implemented!\n");
}
void
win32_endprotoent()
{
- CROAK("endprotoent not implemented!\n");
+ croak("endprotoent not implemented!\n");
}
void
win32_endservent()
{
- CROAK("endservent not implemented!\n");
+ croak("endservent not implemented!\n");
}
struct netent *
win32_getnetent(void)
{
- CROAK("getnetent not implemented!\n");
+ croak("getnetent not implemented!\n");
return (struct netent *) NULL;
}
struct netent *
win32_getnetbyname(char *name)
{
- CROAK("getnetbyname not implemented!\n");
+ croak("getnetbyname not implemented!\n");
return (struct netent *)NULL;
}
struct netent *
win32_getnetbyaddr(long net, int type)
{
- CROAK("getnetbyaddr not implemented!\n");
+ croak("getnetbyaddr not implemented!\n");
return (struct netent *)NULL;
}
struct protoent *
win32_getprotoent(void)
{
- CROAK("getprotoent not implemented!\n");
+ croak("getprotoent not implemented!\n");
return (struct protoent *) NULL;
}
struct servent *
win32_getservent(void)
{
- CROAK("getservent not implemented!\n");
+ croak("getservent not implemented!\n");
return (struct servent *) NULL;
}
void
win32_sethostent(int stayopen)
{
- CROAK("sethostent not implemented!\n");
+ croak("sethostent not implemented!\n");
}
void
win32_setnetent(int stayopen)
{
- CROAK("setnetent not implemented!\n");
+ croak("setnetent not implemented!\n");
}
void
win32_setprotoent(int stayopen)
{
- CROAK("setprotoent not implemented!\n");
+ croak("setprotoent not implemented!\n");
}
void
win32_setservent(int stayopen)
{
- CROAK("setservent not implemented!\n");
+ croak("setservent not implemented!\n");
}
-#define WIN32IO_IS_STDIO
-#include <io.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include "win32iop.h"
-#ifdef __cplusplus
-}
-#endif
-
static struct servent*
win32_savecopyservent(struct servent*d, struct servent*s, const char *proto)
{
diff --git a/win32/win32thread.c b/win32/win32thread.c
index dfa9a0c733..4dbc750b05 100644
--- a/win32/win32thread.c
+++ b/win32/win32thread.c
@@ -15,11 +15,11 @@ Perl_alloc_thread_key(void)
}
void
-init_thread_intern(struct thread *thr)
+Perl_set_thread_self(struct thread *thr)
{
#ifdef USE_THREADS
- /* GetCurrentThread() retrurns a pseudo handle, need
- this to convert it into a handle another thread can use
+ /* Set thr->self. GetCurrentThread() retrurns a pseudo handle, need
+ this to convert it into a handle another thread can use.
*/
DuplicateHandle(GetCurrentProcess(),
GetCurrentThread(),
diff --git a/win32/win32thread.h b/win32/win32thread.h
index 75aa25b632..0c6bb55b69 100644
--- a/win32/win32thread.h
+++ b/win32/win32thread.h
@@ -4,20 +4,21 @@ typedef struct win32_cond { LONG waiters; HANDLE sem; } perl_cond;
typedef DWORD perl_key;
typedef HANDLE perl_thread;
-/* XXX Critical Sections used instead of mutexes: lightweight,
+#ifndef DONT_USE_CRITICAL_SECTION
+
+/* Critical Sections used instead of mutexes: lightweight,
* but can't be communicated to child processes, and can't get
- * HANDLE to it for use elsewhere
+ * HANDLE to it for use elsewhere.
*/
-
-#ifndef DONT_USE_CRITICAL_SECTION
typedef CRITICAL_SECTION perl_mutex;
#define MUTEX_INIT(m) InitializeCriticalSection(m)
#define MUTEX_LOCK(m) EnterCriticalSection(m)
#define MUTEX_UNLOCK(m) LeaveCriticalSection(m)
#define MUTEX_DESTROY(m) DeleteCriticalSection(m)
+
#else
-typedef HANDLE perl_mutex;
+typedef HANDLE perl_mutex;
#define MUTEX_INIT(m) \
STMT_START { \
if ((*(m) = CreateMutex(NULL,FALSE,NULL)) == NULL) \
@@ -46,44 +47,46 @@ typedef HANDLE perl_mutex;
* so there's no separate mutex protecting access to (c)->waiters
*/
#define COND_INIT(c) \
- STMT_START { \
- (c)->waiters = 0; \
- (c)->sem = CreateSemaphore(NULL,0,LONG_MAX,NULL); \
- if ((c)->sem == NULL) \
- croak("panic: COND_INIT (%ld)",GetLastError()); \
+ STMT_START { \
+ (c)->waiters = 0; \
+ (c)->sem = CreateSemaphore(NULL,0,LONG_MAX,NULL); \
+ if ((c)->sem == NULL) \
+ croak("panic: COND_INIT (%ld)",GetLastError()); \
} STMT_END
#define COND_SIGNAL(c) \
- STMT_START { \
- if (ReleaseSemaphore((c)->sem,1,NULL) == 0) \
- croak("panic: COND_SIGNAL (%ld)",GetLastError()); \
+ STMT_START { \
+ if ((c)->waiters > 0 && \
+ ReleaseSemaphore((c)->sem,1,NULL) == 0) \
+ croak("panic: COND_SIGNAL (%ld)",GetLastError()); \
} STMT_END
#define COND_BROADCAST(c) \
- STMT_START { \
- if ((c)->waiters > 0 && \
- ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0) \
- croak("panic: COND_BROADCAST (%ld)",GetLastError());\
+ STMT_START { \
+ if ((c)->waiters > 0 && \
+ ReleaseSemaphore((c)->sem,(c)->waiters,NULL) == 0) \
+ croak("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)\
- croak("panic: COND_WAIT (%ld)",GetLastError()); \
- MUTEX_LOCK(m); \
- (c)->waiters--; \
+ 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)\
+ croak("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) \
- croak("panic: COND_DESTROY (%ld)",GetLastError()); \
+ STMT_START { \
+ (c)->waiters = 0; \
+ if (CloseHandle((c)->sem) == 0) \
+ croak("panic: COND_DESTROY (%ld)",GetLastError()); \
} STMT_END
#define DETACH(t) \
@@ -105,17 +108,17 @@ typedef THREAD_RET_TYPE thread_func_t(void *);
START_EXTERN_C
void Perl_alloc_thread_key _((void));
int Perl_thread_create _((struct thread *thr, thread_func_t *fn));
-void Perl_init_thread_intern _((struct thread *thr));
+void Perl_set_thread_self _((struct thread *thr));
END_EXTERN_C
#define INIT_THREADS NOOP
#define ALLOC_THREAD_KEY Perl_alloc_thread_key()
-#define INIT_THREAD_INTERN(thr) Perl_init_thread_intern(thr)
+#define SET_THREAD_SELF(thr) Perl_set_thread_self(thr)
#define JOIN(t, avp) \
STMT_START { \
if ((WaitForSingleObject((t)->self,INFINITE) == WAIT_FAILED) \
- || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0)) \
+ || (GetExitCodeThread((t)->self,(LPDWORD)(avp)) == 0)) \
croak("panic: JOIN"); \
} STMT_END