//
-// $Id: fcgio.cpp,v 1.12 2001/12/04 00:22:06 robs Exp $
+// $Id: fcgio.cpp,v 1.14 2003/06/22 00:51:27 robs Exp $
//
// Allows you communicate with FastCGI streams using C++ iostreams
//
#define DLLAPI __declspec(dllexport)
#endif
+#include <limits.h>
#include "fcgio.h"
+using std::streambuf;
+using std::istream;
+using std::ostream;
+using std::streamsize;
+
fcgi_streambuf::fcgi_streambuf(FCGX_Stream * fs, char * b, int bs)
{
init(fs, b, bs);
}
-fcgi_streambuf::fcgi_streambuf(char * b, int bs)
+fcgi_streambuf::fcgi_streambuf(char_type * b, streamsize bs)
{
init(0, b, bs);
}
// FCGX_Finish()/FCGX_Accept() will flush and close
}
-void fcgi_streambuf::init(FCGX_Stream * fs, char * b, int bs)
+void fcgi_streambuf::init(FCGX_Stream * fs, char_type * b, streamsize bs)
{
this->fcgx = fs;
this->buf = 0;
// uflow() removes the char, underflow() doesn't
int fcgi_streambuf::uflow()
{
- int rv = underflow();
- if (this->bufsize) gbump(1);
- return rv;
+ if (this->bufsize)
+ {
+ int c = underflow();
+ gbump(1);
+ return c;
+ }
+ else
+ {
+ return FCGX_GetChar(this->fcgx);
+ }
}
-// Note that the expected behaviour when there is no buffer varies
int fcgi_streambuf::underflow()
{
if (this->bufsize)
}
else
{
- return FCGX_GetChar(this->fcgx);
+ return FCGX_UnGetChar(FCGX_GetChar(this->fcgx), this->fcgx);
}
}
setp(this->buf, this->buf + this->bufsize);
}
-streambuf * fcgi_streambuf::setbuf(char * b, int bs)
+std::streambuf * fcgi_streambuf::setbuf(char_type * b, streamsize bs)
{
// XXX support moving data from an old buffer
if (this->bufsize) return 0;
return 0;
}
-int fcgi_streambuf::xsgetn(char * s, int n)
+streamsize fcgi_streambuf::xsgetn(char_type * s, streamsize n)
{
+ if (n > INT_MAX) return 0;
return (this->bufsize)
? streambuf::xsgetn(s, n)
- : FCGX_GetStr(s, n, this->fcgx);
+ : (streamsize) FCGX_GetStr((char *) s, (int) n, this->fcgx);
}
-int fcgi_streambuf::xsputn(const char * s, int n)
+streamsize fcgi_streambuf::xsputn(const char_type * s, streamsize n)
{
+ if (n > INT_MAX) return 0;
return (this->bufsize)
? streambuf::xsputn(s, n)
- : FCGX_PutStr(s, n, this->fcgx);
+ : (streamsize) FCGX_PutStr((char *) s, (int) n, this->fcgx);
}
// deprecated