This corrupt LD_LIBRARY_PATH was a huge mess when running apps with MemoryGuard, it even hard-locked my machine!
char oldDirectory[MAX_LOCATION];
char tempPath[MAX_LOCATION];
char command[MAX_LOCATION];
- char oldPath[MAX_LOCATION * 65];
Project project = ide.project;
DirExpression targetDirExp = project.targetDir;
-
- GetEnvironment("PATH", oldPath, sizeof(oldPath));
+ PathBackup pathBackup { };
prjConfig = project.config;
}
ChangeWorkingDir(oldDirectory);
- SetEnvironment("PATH", oldPath);
+
+ delete pathBackup;
if(!result)
GdbExit();
define pathListSep = ":";
#endif
+define maxPathLen = 65 * MAX_LOCATION;
+
+class PathBackup : struct
+{
+ String oldLDPath;
+ String oldPath;
+
+ PathBackup()
+ {
+ oldPath = new char[maxPathLen];
+ oldLDPath = new char[maxPathLen];
+
+ GetEnvironment("PATH", oldPath, maxPathLen);
+#if defined(__APPLE__)
+ GetEnvironment("DYLD_LIBRARY_PATH", oldLDPath, maxPathLen);
+#else
+ GetEnvironment("LD_LIBRARY_PATH", oldLDPath, maxPathLen);
+#endif
+ }
+
+ ~PathBackup()
+ {
+ SetEnvironment("PATH", oldPath);
+#if defined(__APPLE__)
+ SetEnvironment("DYLD_LIBRARY_PATH", oldLDPath);
+#else
+ SetEnvironment("LD_LIBRARY_PATH", oldLDPath);
+#endif
+ delete oldPath;
+ delete oldLDPath;
+ }
+};
+
enum OpenCreateIfFails { no, yes, something, whatever };
enum OpenMethod { normal, add };
int c, len, count;
char * newList;
char * oldPaths[128];
- char oldList[MAX_LOCATION * 128];
+ String oldList = new char[maxPathLen];
Array<String> newExePaths { };
//Map<String, bool> exePathExists { };
bool found = false;
newExePaths.Add(CopySystemPath(item));
}
- GetEnvironment("PATH", oldList, sizeof(oldList));
+ GetEnvironment("PATH", oldList, maxPathLen);
/*#ifdef _DEBUG
printf("Old value of PATH: %s\n", oldList);
#endif*/
}
#if defined(__APPLE__)
- GetEnvironment("DYLD_LIBRARY_PATH", oldList, sizeof(oldList));
+ GetEnvironment("DYLD_LIBRARY_PATH", oldList, maxPathLen);
#else
- GetEnvironment("LD_LIBRARY_PATH", oldList, sizeof(oldList));
+ GetEnvironment("LD_LIBRARY_PATH", oldList, maxPathLen);
#endif
/*#ifdef _DEBUG
printf("Old value of [DY]LD_LIBRARY_PATH: %s\n", oldList);
SetEnvironment("DISTCC_HOSTS", compiler.distccHosts);
delete compiler;
+ delete oldList;
}
void DestroyTemporaryProjectDir()
char makeTarget[MAX_LOCATION] = "";
char makeFile[MAX_LOCATION];
char makeFilePath[MAX_LOCATION];
- char oldPath[MAX_LOCATION * 65];
char configName[MAX_LOCATION];
CompilerConfig compiler = GetCompilerConfig();
DirExpression objDirExp = objDir;
+ PathBackup pathBackup { };
int numJobs = compiler.numJobs;
char command[MAX_LOCATION];
- GetEnvironment("PATH", oldPath, sizeof(oldPath));
-
strcpy(configName, this.configName);
SetPath(false); //true
ide.outputView.buildBox.Logf("Error executing make (%s) command\n", compiler.makeCommand);
}
- SetEnvironment("PATH", oldPath);
+ delete pathBackup;
delete objDirExp;
delete compiler;
void Clean()
{
- char oldPath[MAX_LOCATION * 65];
char makeFile[MAX_LOCATION];
char makeFilePath[MAX_LOCATION];
char command[MAX_LOCATION];
DualPipe f;
CompilerConfig compiler = GetCompilerConfig();
-
- GetEnvironment("PATH", oldPath, sizeof(oldPath));
+ PathBackup pathBackup { };
SetPath(false);
}
}
- SetEnvironment("PATH", oldPath);
+ delete pathBackup;
delete compiler;
}
void Run(char * args)
{
- char target[MAX_LOCATION * 65], oldDirectory[MAX_LOCATION];
- char oldPath[MAX_LOCATION * 65];
+ String target = new char[maxPathLen];
+ char oldDirectory[MAX_LOCATION];
DirExpression targetDirExp = targetDir;
CompilerConfig compiler = GetCompilerConfig();
-
- GetEnvironment("PATH", oldPath, sizeof(oldPath));
+ PathBackup pathBackup { };
// Build(project, ideMain, true, null);
Execute(target);
ChangeWorkingDir(oldDirectory);
- SetEnvironment("PATH", oldPath);
+ delete pathBackup;
delete targetDirExp;
delete compiler;
+ delete target;
}
void Compile(ProjectNode node)
char filePath[MAX_LOCATION];
char makeFile[MAX_LOCATION];
CompilerConfig compiler = GetCompilerConfig();
- /*char oldPath[MAX_LOCATION * 65];
- char oldDirectory[MAX_LOCATION];*/
+ // PathBackup pathBackup { };
+ // char oldDirectory[MAX_LOCATION];
File f = null;
if(!altMakefilePath)
#endif
f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
- /*GetEnvironment("PATH", oldPath, sizeof(oldPath));
- SetPath(false);
+ /*SetPath(false);
GetWorkingDir(oldDirectory, MAX_LOCATION);
ChangeWorkingDir(topNode.path);*/
result = true;
}
- /*ChangeWorkingDir(oldDirectory);
- SetEnvironment("PATH", oldPath);*/
+ // ChangeWorkingDir(oldDirectory);
+ // delete pathBackup;
if(config)
config.makingModified = false;
bool Run(MenuItem selection, Modifiers mods)
{
- char args[MAX_LOCATION * 64];
+ String args = new char[maxPathLen];
args[0] = '\0';
if(ide.workspace.commandLineArgs)
//ide.debugger.GetCommandLineArgs(args);
MessageBox { master = ide, type = ok, text = "Run", contents = "Shared and static libraries cannot be run like executables." }.Modal();*/
else if(BuildInterrim(project, run))
project.Run(args);
+ delete args;
return true;
}
{
//bool result = false;
char oldwd[MAX_LOCATION];
- char oldPath[MAX_LOCATION * 65];
+ PathBackup pathBackup { };
char command[MAX_LOCATION];
- GetEnvironment("PATH", oldPath, sizeof(oldPath));
ide.SetPath(false); //true
GetWorkingDir(oldwd, sizeof(oldwd));
//ide.outputView.buildBox.Logf("command: %s\n", command);
Execute(command);
ChangeWorkingDir(oldwd);
- SetEnvironment("PATH", oldPath);
+
+ delete pathBackup;
}
else
{
{
int c = 0;
char s[2] = "";
- char files[MAX_LOCATION * 16] = "\n";
+ String files = new char[MAX_LOCATION * 16];
char title[512];
- char msg[MAX_LOCATION * 16 + 2048];
-
+ String msg = new char[MAX_LOCATION * 16 + 2048];
NamedItem item;
+ strcpy(files,"\n");
item = openedFilesNotFound.first;
if(item.next)
sprintf(msg, "The following file%s could not be re-opened.%s", s, files);
MessageBox { type = ok, master = ide, contents = msg, text = title }.Modal();
+
+ delete files;
+ delete msg;
}
openedFilesNotFound.Free(OldLink::Free);
}