use 64bit file offsets and _ftelli64/_fseeki64 on Windows + specialize some FileStream methods
This commit is contained in:
parent
1de58ac2b6
commit
c86d31e5c2
21
octa/io.hh
21
octa/io.hh
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "octa/platform.hh"
|
||||||
#include "octa/string.hh"
|
#include "octa/string.hh"
|
||||||
#include "octa/stream.hh"
|
#include "octa/stream.hh"
|
||||||
#include "octa/format.hh"
|
#include "octa/format.hh"
|
||||||
|
@ -86,11 +87,19 @@ struct FileStream: Stream {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool seek(StreamOffset pos, StreamSeek whence = StreamSeek::set) {
|
bool seek(StreamOffset pos, StreamSeek whence = StreamSeek::set) {
|
||||||
|
#ifndef OCTA_PLATFORM_WIN32
|
||||||
return fseeko(p_f, pos, int(whence)) >= 0;
|
return fseeko(p_f, pos, int(whence)) >= 0;
|
||||||
|
#else
|
||||||
|
return _fseeki64(p_f, pos, int(whence)) >= 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamOffset tell() const {
|
StreamOffset tell() const {
|
||||||
|
#ifndef OCTA_PLATFORM_WIN32
|
||||||
return ftello(p_f);
|
return ftello(p_f);
|
||||||
|
#else
|
||||||
|
return _ftelli64(p_f);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flush() { return !fflush(p_f); }
|
bool flush() { return !fflush(p_f); }
|
||||||
|
@ -103,6 +112,18 @@ struct FileStream: Stream {
|
||||||
return fwrite(buf, 1, count, p_f);
|
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) {
|
void swap(FileStream &s) {
|
||||||
octa::swap(p_f, s.p_f);
|
octa::swap(p_f, s.p_f);
|
||||||
octa::swap(p_owned, s.p_owned);
|
octa::swap(p_owned, s.p_owned);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include "octa/platform.hh"
|
||||||
#include "octa/types.hh"
|
#include "octa/types.hh"
|
||||||
#include "octa/range.hh"
|
#include "octa/range.hh"
|
||||||
#include "octa/type_traits.hh"
|
#include "octa/type_traits.hh"
|
||||||
|
@ -17,8 +18,11 @@
|
||||||
|
|
||||||
namespace octa {
|
namespace octa {
|
||||||
|
|
||||||
/* off_t is POSIX - will also work on windows with mingw/clang, but FIXME */
|
#ifndef OCTA_PLATFORM_WIN32
|
||||||
using StreamOffset = off_t;
|
using StreamOffset = off_t;
|
||||||
|
#else
|
||||||
|
using StreamOffset = __int64;
|
||||||
|
#endif
|
||||||
|
|
||||||
enum class StreamSeek {
|
enum class StreamSeek {
|
||||||
cur = SEEK_CUR,
|
cur = SEEK_CUR,
|
||||||
|
|
Loading…
Reference in a new issue