Home » U++ Library support » U++ Core » GetExeFilePath() in Linux
Re: GetExeFilePath() in Linux [message #6431 is a reply to message #6411] |
Sun, 12 November 2006 18:11   |
masu
Messages: 378 Registered: February 2006
|
Senior Member |
|
|
I tried the latest version and got the right path with mounted proc and also without.
I had to make a tiny change (marked red, therefore the ugly formatting ).
luzr wrote on Sat, 11 November 2006 12:48 | OK, this is my final version:
const char *procexepath_() {
static char h[_MAX_PATH + 1];
ONCELOCK {
char link[100];
sprintf(link, "/proc/%d/exe", getpid());
int ret = readlink(link, h, _MAX_PATH);
if(ret > 0 && ret < _MAX_PATH)
h[ret] = '\0';
else
*h = '\0';
}
return h;
}
String GetExeFilePath()
{
static String exepath;
ONCELOCK {
const char *exe = procexepath_();
if(*exe)
exepath = exe;
else {
String x = Argv0__;
if(IsFullPath(x) && FileExists(x))
exepath = x;
else {
exepath = GetHomeDirFile("upp");
Vector<String> p = Split(FromSystemCharset(Environment().Get("PATH")), ':');
if(x.Find('/') >= 0)
p.Add(GetCurrentDirectory());
for(int i = 0; i < p.GetCount(); i++) {
String ep = NormalizePath(AppendFileName(p[i], x));
if(FileExists(ep))
exepath = ep;
}
}
}
}
return exepath;
}
Please check.
Mirek
P.S.: I need the name of executable in log files, without using the heap and before entering the main - that is why I have separated "procexepath_"...
|
Also, I think we should delete the green line since the result defaults to $HOME/app_name even if it does not exist. The application has to be in the PATH or in the current dir if it was not specified with the complete path on the command line. So this assignment is useless in my opinion since we check all possibilities.
Function SetExeTitle does not exist anymore, commented out in idewin.cpp:
#ifdef _DEBUG
SetExeTitle("debugide");
#else
SetExeTitle("theide");
#endif
Matthias
931b81e7ea53320dccc37375b34b38c3
[Updated on: Sun, 12 November 2006 18:27] Report message to a moderator
|
|
|
 |
|
GetExeFilePath() in Linux
By: zsolt on Tue, 07 November 2006 00:47
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Tue, 07 November 2006 00:53
|
 |
|
Re: GetExeFilePath() in Linux
By: guido on Tue, 07 November 2006 01:53
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Tue, 07 November 2006 09:35
|
 |
|
Re: GetExeFilePath() in Linux
By: zsolt on Tue, 07 November 2006 10:09
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Thu, 09 November 2006 20:27
|
 |
|
Re: GetExeFilePath() in Linux
By: masu on Thu, 09 November 2006 23:08
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Fri, 10 November 2006 00:13
|
 |
|
Re: GetExeFilePath() in Linux
By: zsolt on Fri, 10 November 2006 01:01
|
 |
|
Re: GetExeFilePath() in Linux
By: masu on Fri, 10 November 2006 09:22
|
 |
|
Re: GetExeFilePath() in Linux
By: zsolt on Fri, 10 November 2006 10:22
|
 |
|
Re: GetExeFilePath() in Linux
By: masu on Fri, 10 November 2006 10:48
|
 |
|
Re: GetExeFilePath() in Linux
By: zsolt on Fri, 10 November 2006 12:17
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Fri, 10 November 2006 12:23
|
 |
|
Re: GetExeFilePath() in Linux
By: zsolt on Fri, 10 November 2006 12:35
|
 |
|
Re: GetExeFilePath() in Linux
By: masu on Fri, 10 November 2006 16:28
|
 |
|
Re: GetExeFilePath() in Linux
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Sat, 11 November 2006 12:48
|
 |
|
Re: GetExeFilePath() in Linux
By: zsolt on Sat, 11 November 2006 13:00
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Sat, 11 November 2006 13:37
|
 |
|
Re: GetExeFilePath() in Linux
By: masu on Sun, 12 November 2006 18:11
|
 |
|
Re: GetExeFilePath() in Linux
By: guido on Mon, 20 November 2006 07:55
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Wed, 22 November 2006 16:30
|
 |
|
Re: GetExeFilePath() in Linux
By: guido on Wed, 22 November 2006 19:04
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Wed, 22 November 2006 19:10
|
 |
|
Re: GetExeFilePath() in Linux
By: guido on Wed, 22 November 2006 22:53
|
 |
|
Re: GetExeFilePath() in Linux
By: guido on Wed, 22 November 2006 23:07
|
 |
|
Re: GetExeFilePath() in Linux
|
 |
|
Re: GetExeFilePath() in Linux
By: mirek on Fri, 10 November 2006 10:34
|
Goto Forum:
Current Time: Sun Aug 17 02:24:39 CEST 2025
Total time taken to generate the page: 0.00572 seconds
|