diff --git a/rtc_base/stream.cc b/rtc_base/stream.cc index 4ad005eee8..98fd175a0a 100644 --- a/rtc_base/stream.cc +++ b/rtc_base/stream.cc @@ -18,13 +18,6 @@ #include "rtc_base/stream.h" #include "rtc_base/thread.h" -#if defined(WEBRTC_WIN) -#include - -#define fileno _fileno -#include "rtc_base/string_utils.h" -#endif - namespace rtc { /////////////////////////////////////////////////////////////////////////////// @@ -137,134 +130,5 @@ void StreamAdapterInterface::OnEvent(StreamInterface* stream, SignalEvent(this, events, err); } -/////////////////////////////////////////////////////////////////////////////// -// FileStream -/////////////////////////////////////////////////////////////////////////////// - -FileStream::FileStream() : file_(nullptr) {} - -FileStream::~FileStream() { - FileStream::Close(); -} - -bool FileStream::Open(const std::string& filename, - const char* mode, - int* error) { - Close(); -#if defined(WEBRTC_WIN) - std::wstring wfilename; - if (Utf8ToWindowsFilename(filename, &wfilename)) { - file_ = _wfopen(wfilename.c_str(), ToUtf16(mode).c_str()); - } else { - if (error) { - *error = -1; - return false; - } - } -#else - file_ = fopen(filename.c_str(), mode); -#endif - if (!file_ && error) { - *error = errno; - } - return (file_ != nullptr); -} - -bool FileStream::OpenShare(const std::string& filename, - const char* mode, - int shflag, - int* error) { - Close(); -#if defined(WEBRTC_WIN) - std::wstring wfilename; - if (Utf8ToWindowsFilename(filename, &wfilename)) { - file_ = _wfsopen(wfilename.c_str(), ToUtf16(mode).c_str(), shflag); - if (!file_ && error) { - *error = errno; - return false; - } - return file_ != nullptr; - } else { - if (error) { - *error = -1; - } - return false; - } -#else - return Open(filename, mode, error); -#endif -} - -bool FileStream::DisableBuffering() { - if (!file_) - return false; - return (setvbuf(file_, nullptr, _IONBF, 0) == 0); -} - -StreamState FileStream::GetState() const { - return (file_ == nullptr) ? SS_CLOSED : SS_OPEN; -} - -StreamResult FileStream::Read(void* buffer, - size_t buffer_len, - size_t* read, - int* error) { - if (!file_) - return SR_EOS; - size_t result = fread(buffer, 1, buffer_len, file_); - if ((result == 0) && (buffer_len > 0)) { - if (feof(file_)) - return SR_EOS; - if (error) - *error = errno; - return SR_ERROR; - } - if (read) - *read = result; - return SR_SUCCESS; -} - -StreamResult FileStream::Write(const void* data, - size_t data_len, - size_t* written, - int* error) { - if (!file_) - return SR_EOS; - size_t result = fwrite(data, 1, data_len, file_); - if ((result == 0) && (data_len > 0)) { - if (error) - *error = errno; - return SR_ERROR; - } - if (written) - *written = result; - return SR_SUCCESS; -} - -void FileStream::Close() { - if (file_) { - DoClose(); - file_ = nullptr; - } -} - -bool FileStream::SetPosition(size_t position) { - if (!file_) - return false; - return (fseek(file_, static_cast(position), SEEK_SET) == 0); -} - -bool FileStream::Flush() { - if (file_) { - return (0 == fflush(file_)); - } - // try to flush empty file? - RTC_NOTREACHED(); - return false; -} - -void FileStream::DoClose() { - fclose(file_); -} } // namespace rtc diff --git a/rtc_base/stream.h b/rtc_base/stream.h index b535f16882..505ec8e1f9 100644 --- a/rtc_base/stream.h +++ b/rtc_base/stream.h @@ -11,8 +11,6 @@ #ifndef RTC_BASE_STREAM_H_ #define RTC_BASE_STREAM_H_ -#include - #include #include "rtc_base/buffer.h" @@ -180,51 +178,6 @@ class StreamAdapterInterface : public StreamInterface, RTC_DISALLOW_COPY_AND_ASSIGN(StreamAdapterInterface); }; -/////////////////////////////////////////////////////////////////////////////// -// FileStream is a simple implementation of a StreamInterface, which does not -// support asynchronous notification. -/////////////////////////////////////////////////////////////////////////////// - -// TODO(bugs.webrtc.org/6463): Delete this class. -class FileStream : public StreamInterface { - public: - FileStream(); - ~FileStream() override; - - // The semantics of filename and mode are the same as stdio's fopen - virtual bool Open(const std::string& filename, const char* mode, int* error); - virtual bool OpenShare(const std::string& filename, - const char* mode, - int shflag, - int* error); - - // By default, reads and writes are buffered for efficiency. Disabling - // buffering causes writes to block until the bytes on disk are updated. - virtual bool DisableBuffering(); - - StreamState GetState() const override; - StreamResult Read(void* buffer, - size_t buffer_len, - size_t* read, - int* error) override; - StreamResult Write(const void* data, - size_t data_len, - size_t* written, - int* error) override; - void Close() override; - virtual bool SetPosition(size_t position); - - bool Flush() override; - - protected: - virtual void DoClose(); - - FILE* file_; - - private: - RTC_DISALLOW_COPY_AND_ASSIGN(FileStream); -}; - } // namespace rtc #endif // RTC_BASE_STREAM_H_