precomp-cpp/contrib/preflate/support/filestream.cpp
Alex Xu (Hello71) 3a84725d31 use __linux/__unix instead of CMAKE_C(XX)_FLAGS
this allows the user-specified CFLAGS/CXXFLAGS to take effect.

assume that all platforms supporting C++ in 2021 also support stdbool.h.
2021-11-20 10:30:19 -05:00

48 lines
1.3 KiB
C++

/* Copyright 2018 Dirk Steinke
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include "filestream.h"
FileStream::FileStream(FILE* f) : _f(f) {}
bool FileStream::eof() const {
return feof(_f);
}
size_t FileStream::read(unsigned char* buffer, const size_t size) {
return fread(buffer, 1, size, _f);
}
size_t FileStream::write(const unsigned char* buffer, const size_t size) {
return fwrite(buffer, 1, size, _f);
}
uint64_t FileStream::tell() const {
#ifndef __unix
return _ftelli64(_f);
#else
return ftello(_f);
#endif
}
uint64_t FileStream::seek(const uint64_t newPos) {
uint64_t oldPos = tell();
#ifndef __unix
_fseeki64(_f, newPos, SEEK_SET);
#else
fseeko(_f, newPos, SEEK_SET);
#endif
return oldPos;
}