This commit is contained in:
Cary Sandvig 2000-12-13 18:48:24 +00:00
parent aabd66821f
commit 0bfd97d7c4
2 changed files with 18 additions and 4 deletions

View File

@ -6,7 +6,7 @@
#ifndef __PFSTREAM_H__
#define __PFSTREAM_H__
#include "pfstreambuf.h"
#include "pfstreamBuf.h"
class EXPCL_DTOOL ipfstream : public istream {
PUBLISHED:

View File

@ -83,21 +83,35 @@ int PipeStreamBuf::sync(void) {
int PipeStreamBuf::underflow(void) {
assert(_pipe != (FILE*)0L);
assert(_dir == Input);
if ((eback() == (char*)0L) || (gptr() == (char*)0L) ||
(egptr() == (char*)0L)) {
// must be in win32
char* buf = new char[4096];
char* ebuf = &(buf[4096]);
setg(buf, ebuf, ebuf);
}
if (gptr() < egptr()) {
char c = *(gptr());
return c;
}
if (feof(_pipe) != 0)
return EOF;
// size_t len = ebuf() - base();
size_t len = 1024;
#ifdef WIN32_VC
size_t len = 4096;
#else /* WIN32_VC */
size_t len = ebuf() - base();
#endif /* WIN32_VC */
char* buf = new char[len];
size_t n = fread(buf, 1, len, _pipe);
int ret = buf[0];
if (n == 0)
ret = EOF;
else {
// memcpy(base()+(len - n), buf, n);
#ifdef WIN32_VC
memcpy(eback()+(len-n), buf, n);
#else /* WIN32_VC */
memcpy(base()+(len-n), buf, n);
#endif /* WIN32_VC */
gbump(-n);
}
delete buf;