Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ceco!garry From: garry@ceco.ceco.com (Garry Garrett) Newsgroups: comp.lang.c Subject: Re: Strings as function names (again) Summary: C, Portablitiy, Finding out the where the current executible file is. Message-ID: <410@ceco.ceco.com> Date: 23 Feb 91 15:59:00 GMT References: <388@bria> <14972@smoke.brl.mil> <8431@exodus.Eng.Sun.COM> Organization: Commonwealth Edison Co., Chicago, IL Lines: 33 In article <8431@exodus.Eng.Sun.COM>, limes@ouroborous.Eng.Sun.COM (Greg Limes) writes: > In article , wolfram@akela.informatik.rwth-aachen.de (Wolfram Roesler) writes: > |> >>One is that you have to tell it a path to the executable file, and > |> >>that is not in general available for the currently-executing process. > |> > |> >Sure? How about argv[0] ? > [...] > * > * PORTABILITY > * This was developed on a Sun3 running SunOS 4.0, but I think I > * at least made the algorithm portable. You may need to mess > * with include files and such. Symbolic link searching is turned > * on if your errno.h supplies ELOOP, and off otherwise; I assume > * that all systems with symlinks have a readlink() call. > * [...] Your solution is interesting, but I think that here is where you miss the point. C runs on many many many operating systems and platforms. I have no doubt that your code will run on a sun, or most unix systems. On the other hand, I doubt that it will run on a PC (MS-Dos), or a Mac or an Amiaga, or a prime, or a machine running the OS-9 operating system... The answer is, NO - there is no STANDARD way of knowing the name of the currently exicuting file. On many systems, argv[0] does contain the name of the currently exicuting file, often times with the full pathname. If your C compiler doesn't, send the author hate mail until the next version does, then maybe it will become a de-facto standard. In some cases, this is not possible because of the way that the operating system works. In otherwords, this information is not available from the operating system, so your compiler could not possible give you this information. If that's the case then you are stuck. :-(