public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: where my executable is
@ 2001-09-24  2:32 Michael Veksler
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Veksler @ 2001-09-24  2:32 UTC (permalink / raw)
  To: gcc-help

> Is there a function that would give the absolute path to the directory
> where my executable was executed from?

If your main looks like: int main(int argc, char *argv[])
Then you normally can use argv[0] (no guarantee).

Here is pseudocode (I do something similar in ksh):

// Finds the full path version of "dir"
char* resolve_dir(char *dir)
{
   if (dir starts with '/'):
      return dir
   else:
     return getcwd()+'/'+dir
}

if (argv[0] contains '/'):
   return resolve_dir(the directory part of argv[0]);


// Search through $PATH;
name=argv[0]; // note that name contains no '/'
foreach element in $PATH:
   if exists executable file element+'/'+name:
      return resolve_dir(element+'/'+name);

// Nothing found
error "can't find the directory, the caller did not pass relevant info"



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: where my executable is
  2001-09-24  0:35 Anni Hienola
@ 2001-09-28 17:21 ` Alexandre Oliva
  0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Oliva @ 2001-09-28 17:21 UTC (permalink / raw)
  To: Anni Hienola; +Cc: gcc-help

On Sep 24, 2001, Anni Hienola <Anni.Hienola@helsinki.fi> wrote:

> Is there a function that would give the absolute path to the directory
> where my executable was executed from?

Not in GCC, since it is just a compiler.  It doesn't include a C
library, it just uses the one that comes with whatever OS you're
running.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 3+ messages in thread

* where my executable is
@ 2001-09-24  0:35 Anni Hienola
  2001-09-28 17:21 ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Anni Hienola @ 2001-09-24  0:35 UTC (permalink / raw)
  To: gcc-help

Is there a function that would give the absolute path to the directory
where my executable was executed from?

I've been searching the documentations and tutorials throughout the web
for this, without any success. It sounds so trivial that I wonder, why
it so hard to get.


Anni Hienola

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2001-09-28 17:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-24  2:32 where my executable is Michael Veksler
  -- strict thread matches above, loose matches on Subject: below --
2001-09-24  0:35 Anni Hienola
2001-09-28 17:21 ` Alexandre Oliva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).