X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=libfcgi%2Ffcgio.cpp;h=5a54c1153c9dce8ad07412e23dc8c6729ecc44ca;hb=ac8d264a0023d0023d794f9644370a0f182c6037;hp=0eb6e87446f75e76556f98f2315186a5fadb7b71;hpb=25413d1c93641e07088aabb0ea4481f5770cace7;p=catagits%2Ffcgi2.git diff --git a/libfcgi/fcgio.cpp b/libfcgi/fcgio.cpp index 0eb6e87..5a54c11 100644 --- a/libfcgi/fcgio.cpp +++ b/libfcgi/fcgio.cpp @@ -1,5 +1,5 @@ // -// $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 // @@ -22,14 +22,20 @@ #define DLLAPI __declspec(dllexport) #endif +#include #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); } @@ -45,7 +51,7 @@ fcgi_streambuf::~fcgi_streambuf(void) // 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; @@ -85,12 +91,18 @@ int fcgi_streambuf::sync() // 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) @@ -107,7 +119,7 @@ int fcgi_streambuf::underflow() } else { - return FCGX_GetChar(this->fcgx); + return FCGX_UnGetChar(FCGX_GetChar(this->fcgx), this->fcgx); } } @@ -118,7 +130,7 @@ void fcgi_streambuf::reset(void) 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; @@ -146,18 +158,20 @@ int fcgi_streambuf::attach(FCGX_Stream * fs) 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