1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 02:33:17 +02:00

adopt shane's popen patch

This commit is contained in:
Daniel Beulshausen
2001-07-09 16:44:40 +00:00
parent 61822fcd47
commit 112b9062ff
2 changed files with 14 additions and 11 deletions
+13 -10
View File
@@ -74,9 +74,7 @@ static ProcessPair* process_get(FILE *stream)
TWLS_FETCH();
for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
if (stream != NULL && ptr->stream == stream) {
break;
} else if (stream == NULL && !ptr->inuse) {
if (ptr->stream == stream) {
break;
}
}
@@ -96,6 +94,14 @@ static ProcessPair* process_get(FILE *stream)
return ptr;
}
static HANDLE dupHandle(HANDLE fh, BOOL inherit) {
HANDLE copy, self = GetCurrentProcess();
if (!DuplicateHandle(self, fh, self, &copy, 0, inherit, DUPLICATE_SAME_ACCESS|DUPLICATE_CLOSE_SOURCE)) {
return NULL;
}
return copy;
}
TSRM_API FILE* popen(const char *command, const char *type)
{
FILE *stream = NULL;
@@ -146,9 +152,11 @@ TSRM_API FILE* popen(const char *command, const char *type)
proc = process_get(NULL);
if (read) {
in = dupHandle(in, FALSE);
fno = _open_osfhandle((long)in, _O_RDONLY | mode);
CloseHandle(out);
} else {
out = dupHandle(out, FALSE);
fno = _open_osfhandle((long)out, _O_WRONLY | mode);
CloseHandle(in);
}
@@ -156,7 +164,6 @@ TSRM_API FILE* popen(const char *command, const char *type)
stream = _fdopen(fno, type);
proc->prochnd = process.hProcess;
proc->stream = stream;
proc->inuse = 1;
return stream;
}
@@ -172,16 +179,12 @@ TSRM_API int pclose(FILE* stream)
fflush(process->stream);
fclose(process->stream);
WaitForSingleObject(process->prochnd, INFINITE);
GetExitCodeProcess(process->prochnd, &termstat);
if (termstat == STILL_ACTIVE) {
TerminateProcess(process->prochnd, termstat);
}
process->stream = NULL;
process->inuse = 0;
CloseHandle(process->prochnd);
return termstat;
}
#endif
#endif
+1 -1
View File
@@ -25,10 +25,10 @@
#ifdef TSRM_WIN32
#include <windows.h>
typedef struct {
FILE *stream;
HANDLE prochnd;
int inuse;
} ProcessPair;
typedef struct {