Implement an alternative setenv/unsetenv, as it is not available on windows.

Switch uses of setenv/unsetenv to the new one.

PiperOrigin-RevId: 288738669
Change-Id: I689d0222c1dfcceeb5eef38c57bfb8524fd1c9b1
This commit is contained in:
Gunhan Gulsoy 2020-01-08 11:24:54 -08:00 committed by TensorFlower Gardener
parent 43e41f42dd
commit 2a66ce6f09
6 changed files with 33 additions and 0 deletions

View File

@ -16,7 +16,9 @@ limitations under the License.
#include "tensorflow/core/framework/run_handler_util.h"
#include <vector>
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/test.h"
namespace tensorflow {

View File

@ -39,6 +39,7 @@ limitations under the License.
#include "tensorflow/core/lib/core/notification.h"
#include "tensorflow/core/lib/core/status_test_util.h"
#include "tensorflow/core/lib/strings/strcat.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/public/session_options.h"
#include "tensorflow/core/public/version.h"

View File

@ -26,6 +26,7 @@ limitations under the License.
#include "tensorflow/core/graph/node_builder.h"
#include "tensorflow/core/kernels/ops_testutil.h"
#include "tensorflow/core/kernels/ops_util.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/platform/test.h"
#include "tensorflow/core/platform/test_benchmark.h"
#include "tensorflow/core/protobuf/rewriter_config.pb.h"

View File

@ -18,6 +18,7 @@ limitations under the License.
#include <fcntl.h>
#include <fnmatch.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/time.h>
@ -258,4 +259,10 @@ void PosixEnv::GetLocalTempDirectories(std::vector<string>* list) {
}
}
int setenv(const char* name, const char* value, int overwrite) {
return ::setenv(name, value, overwrite);
}
int unsetenv(const char* name) { return ::unsetenv(name); }
} // namespace tensorflow

View File

@ -431,6 +431,15 @@ class Thread {
TF_DISALLOW_COPY_AND_ASSIGN(Thread);
};
/// \brief Cross-platform setenv.
///
/// Since setenv() is not available on windows, we provide an
/// alternative with platform specific implementations here.
int setenv(const char* name, const char* value, int overwrite);
/// Cross-platform unsetenv.
int unsetenv(const char* name);
/// \brief Options to configure a Thread.
///
/// Note that the options are all hints, and the

View File

@ -20,6 +20,7 @@ limitations under the License.
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#undef LoadLibrary
#undef ERROR
@ -214,4 +215,16 @@ void WindowsEnv::GetLocalTempDirectories(std::vector<string>* list) {
list->push_back("C:\\temp\\");
}
int setenv(const char* name, const char* value, int overwrite) {
if (!overwrite) {
char* env_val = getenv(name);
if (env_val) {
return 0;
}
}
return _putenv_s(name, value);
}
int unsetenv(const char* name) { return _putenv_s(name, ""); }
} // namespace tensorflow