Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef SRC_UTIL_ENV_H_ | ||
#define SRC_UTIL_ENV_H_ | ||
|
||
#include <string> | ||
#include <unistd.h> | ||
|
||
#include "error.h" | ||
|
||
namespace taco { | ||
namespace util { | ||
std::string getFromEnv(std::string flag, std::string dflt); | ||
std::string getTmpdir(); | ||
|
||
std::string getFromEnv(std::string flag, std::string dflt) { | ||
char const *ret = getenv(flag.c_str()); | ||
if (!ret) { | ||
return dflt; | ||
} else { | ||
return std::string(ret); | ||
} | ||
} | ||
|
||
std::string getTmpdir() { | ||
// use POSIX logic for finding a temp dir | ||
auto tmpdir = getFromEnv("TMPDIR", "/tmp/"); | ||
|
||
uassert(access(tmpdir.c_str(), W_OK) == 0) << | ||
"Unable to write to temporary directory for code generation. " | ||
"Please set the environment variable TMPDIR to somewhere writable"; | ||
|
||
return tmpdir; | ||
} | ||
|
||
}} | ||
|
||
#endif /* SRC_UTIL_ENV_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters