diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 1998-05-18 09:40:58 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 1998-05-18 09:40:58 +0000 |
commit | 3666098248b43282bda1153dae2f4c1e4af38d09 (patch) | |
tree | 9c69a323f89cdd81b231dc630b0eaf134225da7a /win32/win32.c | |
parent | 9e6b2b00f0190751b970ece3db7033405cb08ca5 (diff) | |
parent | d2719217c9b7910115cef7ea0c16d68e6b286cf7 (diff) | |
download | perl-3666098248b43282bda1153dae2f4c1e4af38d09.tar.gz |
[asperl] integrate mainline changes (untested)
p4raw-id: //depot/asperl@1010
Diffstat (limited to 'win32/win32.c')
-rw-r--r-- | win32/win32.c | 89 |
1 files changed, 51 insertions, 38 deletions
diff --git a/win32/win32.c b/win32/win32.c index 674b047446..d4be76a7bd 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -112,48 +112,29 @@ static long filetime_to_clock(PFILETIME ft); static BOOL filetime_from_time(PFILETIME ft, time_t t); -char * w32_perlshell_tokens = Nullch; -char ** w32_perlshell_vec; -long w32_perlshell_items = -1; -DWORD w32_platform = (DWORD)-1; -char w32_perllib_root[MAX_PATH+1]; HANDLE w32_perldll_handle = INVALID_HANDLE_VALUE; -#ifndef __BORLANDC__ -long w32_num_children = 0; -HANDLE w32_child_pids[MAXIMUM_WAIT_OBJECTS]; -#endif - -#ifndef FOPEN_MAX -# if defined(_NSTREAM_) -# define FOPEN_MAX _NSTREAM_ -# elsif defined(_NFILE_) -# define FOPEN_MAX _NFILE_ -# elsif defined(_NFILE) -# define FOPEN_MAX _NFILE -# endif -#endif - -#ifndef USE_CRT_POPEN -int w32_popen_pids[FOPEN_MAX]; -#endif +static DWORD w32_platform = (DWORD)-1; #ifdef USE_THREADS # ifdef USE_DECLSPEC_THREAD __declspec(thread) char strerror_buffer[512]; __declspec(thread) char getlogin_buffer[128]; +__declspec(thread) char w32_perllib_root[MAX_PATH+1]; # ifdef HAVE_DES_FCRYPT __declspec(thread) char crypt_buffer[30]; # endif # else # define strerror_buffer (thr->i.Wstrerror_buffer) # define getlogin_buffer (thr->i.Wgetlogin_buffer) +# define w32_perllib_root (thr->i.Ww32_perllib_root) # define crypt_buffer (thr->i.Wcrypt_buffer) # endif #else -char strerror_buffer[512]; -char getlogin_buffer[128]; +static char strerror_buffer[512]; +static char getlogin_buffer[128]; +static char w32_perllib_root[MAX_PATH+1]; # ifdef HAVE_DES_FCRYPT -char crypt_buffer[30]; +static char crypt_buffer[30]; # endif #endif @@ -1113,7 +1094,7 @@ win32_utime(const char *filename, struct utimbuf *times) DllExport int win32_wait(int *status) { -#ifdef __BORLANDC__ +#ifdef USE_RTL_WAIT return wait(status); #else /* XXX this wait emulation only knows about processes @@ -1638,7 +1619,7 @@ win32_pipe(int *pfd, unsigned int size, int mode) DllExport FILE* win32_popen(const char *command, const char *mode) { -#ifdef USE_CRT_POPEN +#ifdef USE_RTL_POPEN return _popen(command, mode); #else int p[2]; @@ -1698,7 +1679,7 @@ win32_popen(const char *command, const char *mode) /* close saved handle */ win32_close(oldfd); - w32_popen_pids[p[parent]] = childpid; + sv_setiv(*av_fetch(w32_fdpid, p[parent], TRUE), childpid); /* we have an fd, return a file stream */ return (win32_fdopen(p[parent], (char *)mode)); @@ -1713,7 +1694,7 @@ cleanup: } return (NULL); -#endif /* USE_CRT_POPEN */ +#endif /* USE_RTL_POPEN */ } /* @@ -1723,13 +1704,22 @@ cleanup: DllExport int win32_pclose(FILE *pf) { -#ifdef USE_CRT_POPEN +#ifdef USE_RTL_POPEN return _pclose(pf); #else - int fd, childpid, status; - fd = win32_fileno(pf); - childpid = w32_popen_pids[fd]; +#ifndef USE_RTL_WAIT + int child; +#endif + + int childpid, status; + SV *sv; + + sv = *av_fetch(w32_fdpid, win32_fileno(pf), TRUE); + if (SvIOK(sv)) + childpid = SvIVX(sv); + else + childpid = 0; if (!childpid) { errno = EBADF; @@ -1737,7 +1727,18 @@ win32_pclose(FILE *pf) } win32_fclose(pf); - w32_popen_pids[fd] = 0; + SvIVX(sv) = 0; + +#ifndef USE_RTL_WAIT + for (child = 0 ; child < w32_num_children ; ++child) { + if (w32_child_pids[child] == (HANDLE)childpid) { + Copy(&w32_child_pids[child+1], &w32_child_pids[child], + (w32_num_children-child-1), HANDLE); + w32_num_children--; + break; + } + } +#endif /* wait for the child */ if (cwait(&status, childpid, WAIT_CHILD) == -1) @@ -1749,7 +1750,7 @@ win32_pclose(FILE *pf) return (status); #endif -#endif /* USE_CRT_OPEN */ +#endif /* USE_RTL_POPEN */ } DllExport int @@ -1844,8 +1845,13 @@ win32_spawnvp(int mode, const char *cmdname, const char *const *argv) { int status; +#ifndef USE_RTL_WAIT + if (mode == P_NOWAIT && w32_num_children >= MAXIMUM_WAIT_OBJECTS) + return -1; +#endif + status = spawnvp(mode, cmdname, (char * const *) argv); -#ifndef __BORLANDC__ +#ifndef USE_RTL_WAIT /* XXX For the P_NOWAIT case, Borland RTL returns pinfo.dwProcessId * while VC RTL returns pinfo.hProcess. For purposes of the custom * implementation of win32_wait(), we assume the latter. @@ -3050,6 +3056,13 @@ Perl_init_os_extras() char *file = __FILE__; dXSUB_SYS; + w32_perlshell_tokens = Nullch; + w32_perlshell_items = -1; + w32_fdpid = newAV(); /* XXX needs to be in Perl_win32_init()? */ +#ifndef USE_RTL_WAIT + w32_num_children = 0; +#endif + /* these names are Activeware compatible */ newXS("Win32::GetCwd", w32_GetCwd, file); newXS("Win32::SetCwd", w32_SetCwd, file); @@ -3126,7 +3139,7 @@ Perl_win32_init(int *argcp, char ***argvp) #if !defined(_ALPHA_) && !defined(__GNUC__) _control87(MCW_EM, MCW_EM); #endif - MALLOC_INIT; + MALLOC_INIT; } #ifdef USE_BINMODE_SCRIPTS |