Skip to content

Commit

Permalink
Merge pull request #509 from NoirMorilec/fix-no-fs
Browse files Browse the repository at this point in the history
Added NO_FS definition for std::ofstream usage
  • Loading branch information
syoyo authored Dec 30, 2024
2 parents fbff1f4 + 5e008af commit 1831424
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tiny_gltf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7207,6 +7207,7 @@ static void SerializeGltfBufferData(const std::vector<unsigned char> &data,

static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
const std::string &binFilename) {
#ifndef TINYGLTF_NO_FS
#ifdef _WIN32
#if defined(__GLIBCXX__) // mingw
int file_descriptor = _wopen(UTF8ToWchar(binFilename).c_str(),
Expand Down Expand Up @@ -7235,6 +7236,9 @@ static bool SerializeGltfBufferData(const std::vector<unsigned char> &data,
// write empty file.
}
return true;
#else
return false;
#endif
}

#if 0 // FIXME(syoyo): not used. will be removed in the future release.
Expand Down Expand Up @@ -8456,6 +8460,7 @@ static bool WriteGltfStream(std::ostream &stream, const std::string &content) {

static bool WriteGltfFile(const std::string &output,
const std::string &content) {
#ifndef TINYGLTF_NO_FS
#ifdef _WIN32
#if defined(_MSC_VER)
std::ofstream gltfFile(UTF8ToWchar(output).c_str());
Expand All @@ -8475,6 +8480,9 @@ static bool WriteGltfFile(const std::string &output,
if (!gltfFile.is_open()) return false;
#endif
return WriteGltfStream(gltfFile, content);
#else
return false;
#endif
}

static bool WriteBinaryGltfStream(std::ostream &stream,
Expand Down Expand Up @@ -8541,6 +8549,7 @@ static bool WriteBinaryGltfStream(std::ostream &stream,
static bool WriteBinaryGltfFile(const std::string &output,
const std::string &content,
const std::vector<unsigned char> &binBuffer) {
#ifndef TINYGLTF_NO_FS
#ifdef _WIN32
#if defined(_MSC_VER)
std::ofstream gltfFile(UTF8ToWchar(output).c_str(), std::ios::binary);
Expand All @@ -8557,6 +8566,9 @@ static bool WriteBinaryGltfFile(const std::string &output,
std::ofstream gltfFile(output.c_str(), std::ios::binary);
#endif
return WriteBinaryGltfStream(gltfFile, content, binBuffer);
#else
return false;
#endif
}

bool TinyGLTF::WriteGltfSceneToStream(const Model *model, std::ostream &stream,
Expand Down

0 comments on commit 1831424

Please sign in to comment.