Skip to content

Commit

Permalink
Switched some library methods over to windows only methods (C4996 war…
Browse files Browse the repository at this point in the history
…nings)

Signed-off-by: Nick Avramoussis <[email protected]>
  • Loading branch information
Idclip committed Feb 24, 2020
1 parent f8ab492 commit 40adbdb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
8 changes: 8 additions & 0 deletions openvdb/io/Archive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,15 @@ Archive::connectInstance(const GridDescriptor& gd, const NamedGridMap& grids) co
bool
Archive::isDelayedLoadingEnabled()
{
#if defined(_MSC_VER)
char* value;
_dupenv_s(&value, nullptr, "OPENVDB_DISABLE_DELAYED_LOAD");
if (!value) return true;
free(value);
return false;
#else
return (nullptr == std::getenv("OPENVDB_DISABLE_DELAYED_LOAD"));
#endif
}


Expand Down
10 changes: 10 additions & 0 deletions openvdb/io/File.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,20 @@ struct File::Impl
static Index64 getDefaultCopyMaxBytes()
{
Index64 result = DEFAULT_COPY_MAX_BYTES;
#if defined(_MSC_VER)
char* s;
_dupenv_s(&s, nullptr, "OPENVDB_DISABLE_DELAYED_LOAD");
if (s) {
char* endptr = nullptr;
result = std::strtoul(s, &endptr, /*base=*/10);
free(s);
}
#else
if (const char* s = std::getenv("OPENVDB_DELAYED_LOAD_COPY_MAX_BYTES")) {
char* endptr = nullptr;
result = std::strtoul(s, &endptr, /*base=*/10);
}
#endif
return result;
}

Expand Down
13 changes: 7 additions & 6 deletions openvdb/io/TempFile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <unistd.h> // for access()
#else
#include <fstream> // for std::filebuf
#include <cstdio> // for std::tmpnam_s(), L_tmpnam_s
#endif
#include <cstdio> // for std::tmpnam(), L_tmpnam, P_tmpdir
#include <iostream>
#include <sstream>
#include <string>
Expand Down Expand Up @@ -90,21 +90,22 @@ struct TempFile::TempFileImpl
BufferType mBuffer;
int mFileDescr;
#else // _MSC_VER
// Use only standard library routines; no POSIX.
// Use Windows only methods (tmpnam_s); no POSIX.

TempFileImpl(std::ostream& os) { this->init(os); }

void init(std::ostream& os)
{
char fnbuf[L_tmpnam];
const char* filename = std::tmpnam(fnbuf);
if (!filename) {
char fnbuf[L_tmpnam_s];
errno_t err = tmpnam_s(fnbuf, L_tmpnam_s);
if (err) {
OPENVDB_THROW(IoError, "failed to generate name for temporary file");
}

/// @todo This is not safe, since another process could open a file
/// with this name before we do. Unfortunately, there is no safe,
/// portable way to create a temporary file.
mPath = filename;
mPath = fnbuf;

const std::ios_base::openmode mode = (std::ios_base::out | std::ios_base::binary);
os.rdbuf(mBuffer.open(mPath.c_str(), mode));
Expand Down

0 comments on commit 40adbdb

Please sign in to comment.