35 int _mktemp_s(
char* templ) {
36 char* ofs = strchr(templ,
'X');
37 sprintf(ofs,
"%d", rand() % 1000000);
43 char* mkdtemp(
char* name_template) {
44 int err = _mktemp_s(name_template);
50 err = _mkdir(name_template);
60 string GetSystemTempDir() {
63 if (!GetTempPath(
sizeof(buf), buf))
67 const char* tempdir = getenv(
"TMPDIR");
83 " command = cat $in > $out\n");
93 ASSERT_TRUE(parser.
ParseTest(input, &err)) << err;
102 const string& contents) {
104 files_[path].contents = contents;
109 FileMap::iterator i =
files_.find(path);
111 return i->second.mtime;
127 FileMap::iterator i =
files_.find(path);
129 return i->second.contents;
137 FileMap::iterator i =
files_.find(path);
151 Fatal(
"couldn't get system temp dir");
153 Fatal(
"chdir: %s", strerror(errno));
156 char name_template[1024];
157 strcpy(name_template, name.c_str());
158 strcat(name_template,
"-XXXXXX");
159 char* tempname = mkdtemp(name_template);
161 Fatal(
"mkdtemp: %s", strerror(errno));
166 Fatal(
"chdir: %s", strerror(errno));
175 Fatal(
"chdir: %s", strerror(errno));
182 if (system(command.c_str()) < 0)
183 Fatal(
"system: %s", strerror(errno));