Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ShirasawaSama committed Oct 17, 2023
1 parent b2ad233 commit b472f7c
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace eim {
public:
output_stream() {
setvbuf(oldStdout, nullptr, _IOFBF, 4096);
freopen(nullptr, "wb", oldStdout);
juce::ignoreUnused(freopen(nullptr, "wb", oldStdout));
#ifdef _WIN32
_setmode(_fileno(oldStdout), _O_BINARY);
#endif
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace eim {

void flush() { std::fflush(oldStdout); }

static void preventStdout() { freopen("/dev/null", "w", stdout); }
static void preventStdout() { juce::ignoreUnused(freopen("/dev/null", "w", stdout)); }

private:
FILE *oldStdout = fdopen(dup(1), "wb");
Expand All @@ -91,19 +91,21 @@ namespace eim {
public:
input_stream() {
setvbuf(stdin, nullptr, _IOFBF, 4096);
freopen(nullptr, "rb", stdin);
juce::ignoreUnused(freopen(nullptr, "rb", stdin));
#ifdef _WIN32
_setmode(_fileno(stdin), _O_BINARY);
#endif
}

static bool readBool() {
char var;
std::fread(&var, 1, 1, stdin);
return var != 0;
auto ret = std::fread(&var, 1, 1, stdin);
return ret && var != 0;
}
template <typename T> size_t read(T& var) { return std::fread(&var, sizeof(T), 1, stdin); }
template <typename T> void readArray(T* var, int len) { std::fread(var, sizeof(T), (size_t) len, stdin); }
template <typename T> void readArray(T* var, int len) {
juce::ignoreUnused(std::fread(var, sizeof(T), (size_t) len, stdin));
}
template <typename T> input_stream& operator>>(T& var) { read(var); return *this; }
input_stream& operator>>(bool& var) { var = readBool(); return *this; }
input_stream& operator>>(std::string& var) { var = readString(); return *this; }
Expand Down Expand Up @@ -131,7 +133,8 @@ namespace eim {
readVarInt(len);
if (len == 0) return "";
char* str = new char[static_cast<unsigned long>(len + 1)];
std::fread(str, sizeof(char), (size_t) len, stdin);
auto ret = std::fread(str, sizeof(char), (size_t) len, stdin);
if ((int)ret < len) len = (int)ret;
str[len] = '\0';
return str;
}
Expand Down

0 comments on commit b472f7c

Please sign in to comment.