From c86d31e5c26bae40757126bb27e70b32c143178d Mon Sep 17 00:00:00 2001 From: q66 Date: Wed, 1 Jul 2015 20:59:05 +0100 Subject: [PATCH] use 64bit file offsets and _ftelli64/_fseeki64 on Windows + specialize some FileStream methods --- octa/io.hh | 21 +++++++++++++++++++++ octa/stream.hh | 6 +++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/octa/io.hh b/octa/io.hh index 7c7cc0d..6fc45c2 100644 --- a/octa/io.hh +++ b/octa/io.hh @@ -8,6 +8,7 @@ #include +#include "octa/platform.hh" #include "octa/string.hh" #include "octa/stream.hh" #include "octa/format.hh" @@ -86,11 +87,19 @@ struct FileStream: Stream { } bool seek(StreamOffset pos, StreamSeek whence = StreamSeek::set) { +#ifndef OCTA_PLATFORM_WIN32 return fseeko(p_f, pos, int(whence)) >= 0; +#else + return _fseeki64(p_f, pos, int(whence)) >= 0; +#endif } StreamOffset tell() const { +#ifndef OCTA_PLATFORM_WIN32 return ftello(p_f); +#else + return _ftelli64(p_f); +#endif } bool flush() { return !fflush(p_f); } @@ -103,6 +112,18 @@ struct FileStream: Stream { return fwrite(buf, 1, count, p_f); } + int getchar() { + return fgetc(p_f); + } + + bool putchar(int c) { + return fputc(c, p_f) != EOF; + } + + bool write(const char *s) { + return fputs(s, p_f) != EOF; + } + void swap(FileStream &s) { octa::swap(p_f, s.p_f); octa::swap(p_owned, s.p_owned); diff --git a/octa/stream.hh b/octa/stream.hh index 9bb286b..f60a082 100644 --- a/octa/stream.hh +++ b/octa/stream.hh @@ -8,6 +8,7 @@ #include +#include "octa/platform.hh" #include "octa/types.hh" #include "octa/range.hh" #include "octa/type_traits.hh" @@ -17,8 +18,11 @@ namespace octa { -/* off_t is POSIX - will also work on windows with mingw/clang, but FIXME */ +#ifndef OCTA_PLATFORM_WIN32 using StreamOffset = off_t; +#else +using StreamOffset = __int64; +#endif enum class StreamSeek { cur = SEEK_CUR,