From 77e9a8bb42285c118a8a0d51fa166d838cc9f473 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Fri, 20 Dec 2013 20:23:03 -0800 Subject: Switching off_t to off64_t. --- includes/BStream.h | 2 +- includes/Buffer.h | 4 ++-- includes/Handle.h | 52 ++++++++++++++++++++++++++++------------------------ includes/Input.h | 4 ++-- includes/Output.h | 4 ++-- src/BStream.cc | 2 +- src/Buffer.cc | 14 +++++++------- src/Handle.cc | 22 +++++++++++----------- src/HttpServer.cc | 3 ++- src/Input.cc | 8 ++++---- src/Output.cc | 6 +++--- 11 files changed, 63 insertions(+), 58 deletions(-) diff --git a/includes/BStream.h b/includes/BStream.h index 2fa842e..fd00b83 100644 --- a/includes/BStream.h +++ b/includes/BStream.h @@ -13,7 +13,7 @@ class BStream : public Handle { virtual bool canRead(); virtual const char * getName(); virtual ssize_t read(void * buf, size_t count) throw (GeneralException); - virtual off_t getSize(); + virtual off64_t getSize(); int peekNextByte(); String readString(bool putNL = false); bool isEmpty() { return m_availBytes == 0; } diff --git a/includes/Buffer.h b/includes/Buffer.h index a903ec9..c0d269a 100644 --- a/includes/Buffer.h +++ b/includes/Buffer.h @@ -17,14 +17,14 @@ class Buffer : public SeekableHandle { virtual bool canRead(); virtual bool canWrite(); virtual const char * getName(); - virtual off_t getSize(); + virtual off64_t getSize(); const uint8_t * getBuffer() { return m_buffer + rtell(); } void reset(); void rewind() { rseek(0); wseek(0); } private: uint8_t * m_buffer = NULL; bool m_fromConst = false; - off_t m_bufSize = 0, m_numBlocks = 0; + off64_t m_bufSize = 0, m_numBlocks = 0; }; }; diff --git a/includes/Handle.h b/includes/Handle.h index 29cdb08..176f4bb 100644 --- a/includes/Handle.h +++ b/includes/Handle.h @@ -6,6 +6,10 @@ #include #include +#ifdef _MSC_VER +typedef __int64 off64_t; +#endif + namespace Balau { class FileSystem { @@ -52,17 +56,17 @@ class Handle { virtual bool canWrite(); virtual ssize_t read(void * buf, size_t count) throw (GeneralException) WARN_UNUSED_RESULT; virtual ssize_t write(const void * buf, size_t count) throw (GeneralException) WARN_UNUSED_RESULT; - virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException); - virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException); - virtual off_t rtell() throw (GeneralException); - virtual off_t wtell() throw (GeneralException); - virtual off_t getSize(); + virtual void rseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException); + virtual void wseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException); + virtual off64_t rtell() throw (GeneralException); + virtual off64_t wtell() throw (GeneralException); + virtual off64_t getSize(); virtual time_t getMTime(); virtual bool isPendingComplete() { return true; } // helpers - off_t tell() { return rtell(); } - void seek(off_t offset, int whence = SEEK_SET) { rseek(offset, whence); } + off64_t tell() { return rtell(); } + void seek(off64_t offset, int whence = SEEK_SET) { rseek(offset, whence); } Future readU8(); Future readU16(); @@ -175,16 +179,16 @@ class SeekableHandle : public Handle { public: SeekableHandle() : m_wOffset(0), m_rOffset(0) { } virtual bool canSeek(); - virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException); - virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException); - virtual off_t rtell() throw (GeneralException); - virtual off_t wtell() throw (GeneralException); + virtual void rseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException); + virtual void wseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException); + virtual off64_t rtell() throw (GeneralException); + virtual off64_t wtell() throw (GeneralException); virtual bool isEOF(); protected: - off_t getWOffset() { return m_wOffset; } - off_t getROffset() { return m_rOffset; } + off64_t getWOffset() { return m_wOffset; } + off64_t getROffset() { return m_rOffset; } private: - off_t m_wOffset, m_rOffset; + off64_t m_wOffset, m_rOffset; }; class ReadOnly : public Handle { @@ -199,11 +203,11 @@ class ReadOnly : public Handle { virtual const char * getName() { return m_io->getName(); } virtual ssize_t read(void * buf, size_t count) throw (GeneralException) { return m_io->read(buf, count); } virtual ssize_t write(const void * buf, size_t count) throw (GeneralException) { throw GeneralException("Can't write"); } - virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { m_io->rseek(offset, whence); } - virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { throw GeneralException("Can't write"); } - virtual off_t rtell() throw (GeneralException) { return m_io->rtell(); } - virtual off_t wtell() throw (GeneralException) { throw GeneralException("Can't write"); } - virtual off_t getSize() { return m_io->getSize(); } + virtual void rseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException) { m_io->rseek(offset, whence); } + virtual void wseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException) { throw GeneralException("Can't write"); } + virtual off64_t rtell() throw (GeneralException) { return m_io->rtell(); } + virtual off64_t wtell() throw (GeneralException) { throw GeneralException("Can't write"); } + virtual off64_t getSize() { return m_io->getSize(); } virtual time_t getMTime() { return m_io->getMTime(); } private: IO m_io; @@ -221,11 +225,11 @@ class WriteOnly : public Handle { virtual const char * getName() { return m_io->getName(); } virtual ssize_t read(void * buf, size_t count) throw (GeneralException) { throw GeneralException("Can't read"); } virtual ssize_t write(const void * buf, size_t count) throw (GeneralException) { return m_io->write(buf, count); } - virtual void rseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { throw GeneralException("Can't read"); } - virtual void wseek(off_t offset, int whence = SEEK_SET) throw (GeneralException) { return m_io->wseek(offset, whence); } - virtual off_t rtell() throw (GeneralException) { throw GeneralException("Can't read"); } - virtual off_t wtell() throw (GeneralException) { return m_io->wtell(); } - virtual off_t getSize() { return m_io->getSize(); } + virtual void rseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException) { throw GeneralException("Can't read"); } + virtual void wseek(off64_t offset, int whence = SEEK_SET) throw (GeneralException) { return m_io->wseek(offset, whence); } + virtual off64_t rtell() throw (GeneralException) { throw GeneralException("Can't read"); } + virtual off64_t wtell() throw (GeneralException) { return m_io->wtell(); } + virtual off64_t getSize() { return m_io->getSize(); } virtual time_t getMTime() { return m_io->getMTime(); } private: IO m_io; diff --git a/includes/Input.h b/includes/Input.h index be9e4cf..a9bfa8c 100644 --- a/includes/Input.h +++ b/includes/Input.h @@ -14,7 +14,7 @@ class Input : public SeekableHandle { virtual bool isClosed(); virtual bool canRead(); virtual const char * getName(); - virtual off_t getSize(); + virtual off64_t getSize(); virtual time_t getMTime(); virtual bool isPendingComplete(); const char * getFName() { return m_fname.to_charp(); } @@ -22,7 +22,7 @@ class Input : public SeekableHandle { int m_fd = -1; String m_name; String m_fname; - off_t m_size = -1; + off64_t m_size = -1; time_t m_mtime = -1; void * m_pendingOp = NULL; }; diff --git a/includes/Output.h b/includes/Output.h index c80cf40..59a157e 100644 --- a/includes/Output.h +++ b/includes/Output.h @@ -13,7 +13,7 @@ class Output : public SeekableHandle { virtual bool isClosed(); virtual bool canWrite(); virtual const char * getName(); - virtual off_t getSize(); + virtual off64_t getSize(); virtual time_t getMTime(); virtual bool isPendingComplete(); const char * getFName() { return m_fname.to_charp(); } @@ -21,7 +21,7 @@ class Output : public SeekableHandle { int m_fd = -1; String m_name; String m_fname; - off_t m_size = -1; + off64_t m_size = -1; time_t m_mtime = -1; void * m_pendingOp = NULL; }; diff --git a/src/BStream.cc b/src/BStream.cc index 2fe75c7..3a3f972 100644 --- a/src/BStream.cc +++ b/src/BStream.cc @@ -22,7 +22,7 @@ bool Balau::BStream::isClosed() { return m_closed || m_h->isClosed(); } bool Balau::BStream::isEOF() { return (m_availBytes == 0) && m_h->isEOF(); } bool Balau::BStream::canRead() { return true; } const char * Balau::BStream::getName() { return m_name.to_charp(); } -off_t Balau::BStream::getSize() { return m_h->getSize(); } +off64_t Balau::BStream::getSize() { return m_h->getSize(); } ssize_t Balau::BStream::read(void * _buf, size_t count) throw (Balau::GeneralException) { if (m_passThru) diff --git a/src/Buffer.cc b/src/Buffer.cc index 25639b7..42dbd52 100644 --- a/src/Buffer.cc +++ b/src/Buffer.cc @@ -19,10 +19,10 @@ void Balau::Buffer::close() throw (GeneralException) { } ssize_t Balau::Buffer::read(void * buf, size_t count) throw (GeneralException) { - off_t cursor = rtell(); + off64_t cursor = rtell(); if (cursor >= m_bufSize) return 0; - off_t avail = m_bufSize - cursor; + off64_t avail = m_bufSize - cursor; if (count > avail) count = avail; @@ -38,10 +38,10 @@ ssize_t Balau::Buffer::write(const void * buf, size_t count) throw (GeneralExcep if (m_fromConst) throw GeneralException("Buffer is read only and can't be written to."); - off_t cursor = wtell(); - off_t end = cursor + count; - off_t endBlock = (end / s_blockSize) + ((end % s_blockSize) ? 1 : 0); - off_t oldEndBlock = m_numBlocks; + off64_t cursor = wtell(); + off64_t end = cursor + count; + off64_t endBlock = (end / s_blockSize) + ((end % s_blockSize) ? 1 : 0); + off64_t oldEndBlock = m_numBlocks; if (endBlock > oldEndBlock) { m_buffer = (uint8_t *) realloc(m_buffer, endBlock * s_blockSize); @@ -71,6 +71,6 @@ void Balau::Buffer::reset() { bool Balau::Buffer::isClosed() { return false; } bool Balau::Buffer::isEOF() { return rtell() == m_bufSize; } const char * Balau::Buffer::getName() { return "Buffer"; } -off_t Balau::Buffer::getSize() { return m_bufSize; } +off64_t Balau::Buffer::getSize() { return m_bufSize; } bool Balau::Buffer::canRead() { return true; } bool Balau::Buffer::canWrite() { return !m_fromConst; } diff --git a/src/Handle.cc b/src/Handle.cc index c1542ac..79b81c8 100644 --- a/src/Handle.cc +++ b/src/Handle.cc @@ -27,7 +27,7 @@ static const char * strerror_r(int errorno, char * buf, size_t bufsize) { bool Balau::Handle::canSeek() { return false; } bool Balau::Handle::canRead() { return false; } bool Balau::Handle::canWrite() { return false; } -off_t Balau::Handle::getSize() { return -1; } +off64_t Balau::Handle::getSize() { return -1; } time_t Balau::Handle::getMTime() { return -1; } ssize_t Balau::Handle::read(void * buf, size_t count) throw (GeneralException) { @@ -168,33 +168,33 @@ Balau::Future Balau::Handle::writeI16(int16_t v) { return genericWrite Balau::Handle::writeI32(int32_t v) { return genericWrite(this, v); } Balau::Future Balau::Handle::writeI64(int64_t v) { return genericWrite(this, v); } -void Balau::Handle::rseek(off_t offset, int whence) throw (GeneralException) { +void Balau::Handle::rseek(off64_t offset, int whence) throw (GeneralException) { if (canSeek()) throw GeneralException(String("Handle ") + getName() + " can seek, but rseek() not implemented (missing in class " + ClassName(this).c_str() + ")"); else throw GeneralException("Handle can't seek"); } -void Balau::Handle::wseek(off_t offset, int whence) throw (GeneralException) { +void Balau::Handle::wseek(off64_t offset, int whence) throw (GeneralException) { rseek(offset, whence); } -off_t Balau::Handle::rtell() throw (GeneralException) { +off64_t Balau::Handle::rtell() throw (GeneralException) { if (canSeek()) throw GeneralException(String("Handle ") + getName() + " can seek, but rtell() not implemented (missing in class " + ClassName(this).c_str() + ")"); else throw GeneralException("Handle can't seek"); } -off_t Balau::Handle::wtell() throw (GeneralException) { +off64_t Balau::Handle::wtell() throw (GeneralException) { return rtell(); } bool Balau::SeekableHandle::canSeek() { return true; } -void Balau::SeekableHandle::rseek(off_t offset, int whence) throw (GeneralException) { +void Balau::SeekableHandle::rseek(off64_t offset, int whence) throw (GeneralException) { AAssert(canRead() || canWrite(), "Can't use a SeekableHandle with a Handle that can neither read or write..."); - off_t size; + off64_t size; if (!canRead()) wseek(offset, whence); switch (whence) { @@ -215,9 +215,9 @@ void Balau::SeekableHandle::rseek(off_t offset, int whence) throw (GeneralExcept m_rOffset = 0; } -void Balau::SeekableHandle::wseek(off_t offset, int whence) throw (GeneralException) { +void Balau::SeekableHandle::wseek(off64_t offset, int whence) throw (GeneralException) { AAssert(canRead() || canWrite(), "Can't use a SeekableHandle with a Handle that can neither read or write..."); - off_t size; + off64_t size; if (!canWrite()) rseek(offset, whence); switch (whence) { @@ -238,14 +238,14 @@ void Balau::SeekableHandle::wseek(off_t offset, int whence) throw (GeneralExcept m_wOffset = 0; } -off_t Balau::SeekableHandle::rtell() throw (GeneralException) { +off64_t Balau::SeekableHandle::rtell() throw (GeneralException) { AAssert(canRead() || canWrite(), "Can't use a SeekableHandle with a Handle that can neither read or write..."); if (!canRead()) return wtell(); return m_rOffset; } -off_t Balau::SeekableHandle::wtell() throw (GeneralException) { +off64_t Balau::SeekableHandle::wtell() throw (GeneralException) { AAssert(canRead() || canWrite(), "Can't use a SeekableHandle with a Handle that can neither read or write..."); if (!canWrite()) return rtell(); diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 3abf776..4a3e086 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -225,7 +225,7 @@ void Balau::HttpWorker::sendError(int error, const char * msg, const char * deta } else { IO errorText(new Buffer); tpl->render(errorText, &ctx); - off_t length = errorText->getSize(); + off64_t length = errorText->getSize(); String headers; headers.set( "HTTP/1.1 %i %s\r\n" @@ -272,6 +272,7 @@ bool Balau::HttpWorker::handleClient() { yield(); continue; } + Printer::log(M_DEBUG, "HTTPIN: %s", line.to_charp()); // until we get a blank line if (line == "") break; diff --git a/src/Input.cc b/src/Input.cc index 64a05ec..87d9be3 100644 --- a/src/Input.cc +++ b/src/Input.cc @@ -217,10 +217,10 @@ namespace { class AsyncOpRead : public Balau::AsyncOperation { public: - AsyncOpRead(int fd, void * buf, size_t count, off_t offset, cbResults_t * results) : m_fd(fd), m_buf(buf), m_count(count), m_offset(offset), m_results(results) { } + AsyncOpRead(int fd, void * buf, size_t count, off64_t offset, cbResults_t * results) : m_fd(fd), m_buf(buf), m_count(count), m_offset(offset), m_results(results) { } virtual void run() { #ifdef _MSC_VER - off_t offset = lseek(m_fd, m_offset, SEEK_SET); + off64_t offset = lseek(m_fd, m_offset, SEEK_SET); if (offset < 0) { m_results->errorno = errno; return; @@ -239,7 +239,7 @@ class AsyncOpRead : public Balau::AsyncOperation { int m_fd; void * m_buf; size_t m_count; - off_t m_offset; + off64_t m_offset; cbResults_t * m_results; }; @@ -304,7 +304,7 @@ const char * Balau::Input::getName() { return m_name.to_charp(); } -off_t Balau::Input::getSize() { +off64_t Balau::Input::getSize() { return m_size; } diff --git a/src/Output.cc b/src/Output.cc index 0d5972d..0ace38e 100644 --- a/src/Output.cc +++ b/src/Output.cc @@ -217,7 +217,7 @@ namespace { class AsyncOpWrite : public Balau::AsyncOperation { public: - AsyncOpWrite(int fd, const void * buf, size_t count, off_t offset, cbResults_t * results) : m_fd(fd), m_buf(buf), m_count(count), m_offset(offset), m_results(results) { } + AsyncOpWrite(int fd, const void * buf, size_t count, off64_t offset, cbResults_t * results) : m_fd(fd), m_buf(buf), m_count(count), m_offset(offset), m_results(results) { } virtual void run() { #ifdef _MSC_VER IAssert(0, "Not yet implemented"); @@ -235,7 +235,7 @@ class AsyncOpWrite : public Balau::AsyncOperation { int m_fd; const void * m_buf; size_t m_count; - off_t m_offset; + off64_t m_offset; cbResults_t * m_results; }; @@ -300,7 +300,7 @@ const char * Balau::Output::getName() { return m_name.to_charp(); } -off_t Balau::Output::getSize() { +off64_t Balau::Output::getSize() { return m_size; } -- cgit v1.2.3