Skip to content

Commit

Permalink
Only use windows temp directory if /tmp is missing, even in Cygwin
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson committed Apr 2, 2021
1 parent b1896e8 commit 81010b7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,17 @@ static Obj FuncREAD_GAP_ROOT(Obj self, Obj filename)
*/
static Obj FuncTmpName(Obj self)
{
char name[100] = "/tmp/gaptempfile.XXXXXX";
#ifdef SYS_IS_CYGWIN32
char name[] = "C:/WINDOWS/Temp/gaptempfile.XXXXXX";
#else
char name[] = "/tmp/gaptempfile.XXXXXX";
// If /tmp is missing, write into Window's temp directory
DIR* dir = opendir("/tmp");
if(dir) {
closedir(dir);
}
else {
strcpy(name, "C:/WINDOWS/Temp/gaptempfile.XXXXXX");
}
#endif

int fd = mkstemp(name);
if (fd < 0)
return Fail;
Expand All @@ -996,14 +1001,22 @@ static Obj FuncTmpName(Obj self)
*/
static Obj FuncTmpDirectory(Obj self)
{
Obj name;
Obj name = 0;
char * env_tmpdir = getenv("TMPDIR");
if (env_tmpdir != NULL) {
name = MakeString(env_tmpdir);
}
else {
#ifdef SYS_IS_CYGWIN32
name = MakeString("C:/WINDOWS/Temp/");
// If /tmp is missing, write into Window's temp directory
DIR* dir = opendir("/tmp");
if(dir) {
closedir(dir);
name = MakeString("/tmp");
}
else {
name = MakeString("C:/WINDOWS/Temp/");
}
#else
name = MakeString("/tmp");
#endif
Expand Down

0 comments on commit 81010b7

Please sign in to comment.