RE: [Dev-C++] How to get application directory?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-03-09 16:57:05
|
To read contents of a link on Linux, just call readlink() To reatrieve information about a link - instead of the file it points to, use lstat() instead of stat(). /Per W On Tue, 9 Mar 2004, P.D. van Zelst wrote: > For the original poster: Don't know if it will help you, but in Win32 I get > the path to the running application like this: > > char szBuf[512]; > GetModuleFileName(NULL, szBuf, 512); > > (if the call succeeded, szBuf now contains the full path to the current > module (executable)) > > To Per: > Thanks :D I forgot that lots of things are file (or pseudo-file) based in > Linux. But it appears that /proc/self/exe is a symlink to the current > binary... which brings me to a second problem: How do I get the target of a > symlink as a string or something :) Whenever I'm programming for Linux I > constantly run into problems, cause I have no clue where to get MSDN-like > information for Linux or POSIX. > > Regards, > > > Paul > > -----Original Message----- > From: dev...@li... > [mailto:dev...@li...] On Behalf Of Per > Westermark > Sent: Tuesday, March 09, 2004 1:14 PM > To: sub...@ar... > Cc: dev...@li... > Subject: Re: [Dev-C++] How to get application directory? > > If the application was started with a path, you might retrieve it as > the arg[0] parameter of main(). > > If not, you have to search the path for an application with the correct > name. I don't think there is a standard function to perform this. If I'm > wrong, I very much want to know the name of the function, since it would > be useful :) > > On Linux, it is possible to heck in the /proc filesystem. There exists a > symbolic link: > /proc/<process_id>/exe -> /my/running/binary > That will specify which binary that is running. > > It may also be accessed as: > /proc/self/exe -> /my/running/binary > to avoid the extra trouble of retrieving process id and dynamically create > the path to the symbolic link. > > /Per W > > On Tue, 9 Mar 2004 sub...@ar... wrote: > > > What I actually wanted is the directory where the binary application is > stored... > > Anybody knows how to get it? > > > > Thanks again, > > Josep > > > > ----- Original Nachricht ---- > > Von: Per Westermark <pw...@ia...> > > An: Kevin Wood <ke...@me...> > > Datum: 09.03.2004 10:28 > > Betreff: Re: [Dev-C++] How to get application directory? > > > > > The question was which directory the application is running in - not > where > > > the application binary is stored. > > > > > > /Per W > > > > > > On Tue, 9 Mar 2004, Kevin Wood wrote: > > > > > > > getcwd() returns the current working directory, which is not > necessarily > > > > the same as the directory in which the application resides. > > > > > > > > At 08:10 09/03/04, Per Westermark wrote: > > > > >getcwd() or _getcwd(). > > > > > > > > > >/Per W > > > > > > > > > >On Tue, 9 Mar 2004, Josep Subirana wrote: > > > > > > > > > > > Hi, > > > > > > > > > > > > Do you know how to get the directory where your c++ application is > > > running > > > > > > in? > > > > > > This should be a simple question for most experienced c++ > > > programmers! > > > > > > > > > > > > Thanks, > > > > > > > > > > > > Josep > > > > > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > > This SF.Net email is sponsored by: IBM Linux Tutorials > > > > Free Linux tutorial presented by Daniel Robbins, President and CEO of > > > > GenToo technologies. Learn everything from fundamentals to system > > > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > > > > _______________________________________________ > > > > Dev-cpp-users mailing list > > > > Dev...@li... > > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.Net email is sponsored by: IBM Linux Tutorials > > > Free Linux tutorial presented by Daniel Robbins, President and CEO of > > > GenToo technologies. Learn everything from fundamentals to system > > > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > > > _______________________________________________ > > > Dev-cpp-users mailing list > > > Dev...@li... > > > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > > > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |