Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve handling of temp directory in GAP for Windows #3939

Merged
merged 2 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/system.g
Original file line number Diff line number Diff line change
Expand Up @@ -517,13 +517,20 @@ end );
## <Func Name="ARCH_IS_WINDOWS" Arg=''/>
##
## <Description>
## tests whether &GAP; is running on a Windows system in Cygwin.
## tests whether &GAP; is running on a Windows system without
## standard POSIX tools available (such as a shell).
## </Description>
## </ManSection>
## <#/GAPDoc>
##
BIND_GLOBAL("ARCH_IS_WINDOWS",function()
return POSITION_SUBSTRING (GAPInfo.Architecture, "cygwin", 0) <> fail;
# Exit early is we are not in Cygwin
if POSITION_SUBSTRING (GAPInfo.Architecture, "cygwin", 0) = fail then
return false;
fi;
# Check if programs we need exist in their standard Cygwin locations
return not IsExistingFile("/usr/bin/sh") or
not IsExistingFile("/usr/bin/xdg-open");
end);

#############################################################################
Expand Down
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