--- parser3/src/main/pa_exec.C 2007/04/23 10:30:31 1.69 +++ parser3/src/main/pa_exec.C 2007/11/15 19:44:39 1.71 @@ -7,7 +7,7 @@ @todo setrlimit */ -static const char * const IDENT_EXEC_C="$Date: 2007/04/23 10:30:31 $"; +static const char * const IDENT_EXEC_C="$Date: 2007/11/15 19:44:39 $"; #include "pa_config_includes.h" @@ -122,6 +122,37 @@ static void read_pipe(String& result, HA } } +static void read_pipe(File_read_result& result, HANDLE hOutRead){ + + char *buf=new(PointerFreeGC) char[MAX_STRING]; + + unsigned long size = 0; + unsigned long bufsize = 0; + unsigned long newsize = 0; + + result.headers = 0; + result.length = 0; + result.str = 0; + result.success = false; + + while(true) { + if(!ReadFile(hOutRead, buf, MAX_STRING-1, &size, NULL) || !size) + break; + newsize = (size + result.length); + if(newsize > bufsize){ + bufsize = (size==MAX_STRING-1)?newsize*2:newsize; + char *tmp = new(PointerFreeGC) char[bufsize]; + if(result.str) + memcpy(tmp, result.str, result.length); + memcpy(tmp+result.length, buf, size); + result.str = tmp; + }else{ + memcpy(result.str+result.length, buf, size); + } + result.length = newsize; + } +} + static const char* buildCommand(const char* file_spec_cstr, const ArrayString& argv) { const char* result=file_spec_cstr; if(FILE *f=fopen(file_spec_cstr, "r")) { @@ -290,6 +321,36 @@ static void read_pipe(String& result, in } } +static void read_pipe(File_read_result& result, int file){ + char *buf=new(PointerFreeGC) char[MAX_STRING]; + + unsigned long bufsize = 0; + unsigned long newsize = 0; + + result.headers = 0; + result.length = 0; + result.str = 0; + result.success = false; + + while(true) { + ssize_t size=read(file, buf, MAX_STRING-1); + if(size <= 0) + break; + newsize = (size + result.length); + if(newsize > bufsize){ + bufsize = (size==MAX_STRING-1)?newsize*2:newsize; + char *tmp = new(PointerFreeGC) char[bufsize]; + if(result.str) + memcpy(tmp, result.str, result.length); + memcpy(tmp+result.length, buf, size); + result.str = tmp; + }else{ + memcpy(result.str+result.length, buf, size); + } + result.length = newsize; + } +} + #endif #ifndef DOXYGEN @@ -374,7 +435,7 @@ PA_exec_result pa_exec( // without this char WriteFile(hInWrite, "\x1A", 1, &written_size, NULL); CloseHandle(hInWrite); - read_pipe(result.out, hOutRead, String::L_AS_IS); + read_pipe(result.out, hOutRead); CloseHandle(hOutRead); read_pipe(result.err, hErrRead, String::L_TAINTED); CloseHandle(hErrRead); @@ -439,7 +500,7 @@ from http://www.apache.org/websrc/cvsweb write(pipe_write, in_cstr, in.length()); } close(pipe_write); - read_pipe(result.out, pipe_read, String::L_AS_IS); + read_pipe(result.out, pipe_read); close(pipe_read); read_pipe(result.err, pipe_err, String::L_TAINTED); close(pipe_err);